Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop Asynchronous beans > Develop work objects, event listeners, and asynchronous scopes > Develop asynchronous scopes
Asynchronous scopes: Dynamic message bean scenario
Java EE now supports message-driven beans, but the beans are static. This scenario provides information about how to set up the environment to enable the dynamic message bean.
All of the message sources must be known in advance and bound at deployment time. This action is not always viable, especially in fluid messaging environments such as those found in brokerages. Some environments have publish-subscribe topic spaces that are continually changing and clients need servers that can subscribe on demand to an arbitrary topic.
An asynchronous bean application can create a work object that performs a blocking receive on a JMS topic and then publishes the message as an event on an application-defined event source. Clients requiring a subscription to that message can add an event listener to the event source. The event source can inform the work object when there are no listeners. Then, the event source can shut down and make the JMS and thread resources available. The work object registers a listener with its own event source. When the count is one again, the work object knows that it is the only listener and it is time to shut down the work object. The WebSphere Trader Sample uses this pattern to dynamically subscribe to JMS topics at run time to gather stock prices. See the overview of the samples.
How does the server catch clients that disconnect or crash? It creates a subsystem monitor to watch the client and adds an event listener to catch dead events. When a dead event occurs, the server application can clean up the client server state. For example, the server application can remove the client event listener from the dynamic message bean, thereby allowing the server to subscribe to a dynamic topic only when it is needed.
Work objects
Develop asynchronous scopes
Samples documentation