Develop asynchronous scopes
Overview
Asynchronous scopes are units of scoping that comprise a set of alarms, subsystem monitors, and child asynchronous scopes. Using asynchronous scopes can involve some or all of the following steps:
Procedure
- Create asynchronous scopes. Create the parent asynchronous scope object by using a unique parameter name that calls the AsynchScopeManager.createAsynchScope() method. We can store properties in an asynchronous scope object. This storage provides Java 2 Enterprise Edition (J2EE) applications with a way to store a non-serializable state that otherwise cannot be stored in a session bean. You also can create child asynchronous scopes, which is useful for scoping data beneath the parent.
- Listen for alarm notifications
- Create a listener object by implementing the AlarmListener interface. For more information, see the AlarmListener interface in the Javadoc.
- Supply this object to the AlarmManager.create() method, as the target for the alarm. The create() method takes the following parameters:
After the specified interval, the alarm fires and the fired() method of the listener is called with the firing alarm as a parameter. The alarm object is returned. By calling methods on this object, one can cancel or reschedule the alarm.
- Target for the alarm
- The target on which the fired() method is called when the alarm is fired.
- Context
- The context object for the alarm. This object is useful for supplying alarm-specific data to the listener and supports a single listener for multiple alarms.
- Interval
- The number of milliseconds before the alarm fires.
- Monitor remote systems.
- Implement a mechanism for detecting messages sent from the remote system. For example, publish and subscribe messaging.
- Create a subsystem manager object by calling the SubsystemMonitorManager.create() method with the following parameters:
- Name
- Each subsystem monitor must have a unique name.
- Heartbeat interval
- The expected interval, in milliseconds, between heartbeats.
- Missed heart beats until stale or suspect
- The number of heartbeats that can be missed before the subsystem is marked as stale.
- Missed heart beats until dead
- The number of heartbeats that can be missed before the system is marked as dead.
- Create an object that implements the SubsystemMonitorEvents interface. For more information, see the SubsystemMonitorEvents in the Javadoc.
- Add an instance of this object to the subsystem monitor using the SubsystemMonitor.addListener() method.
- Whenever a heartbeat message arrives from the remote system, call the SubsystemMonitor ping() method.
The subsystem monitor configures alarms to track the heartbeat status of the remote system. When the ping() method is called, the alarms are reset. If an alarm fires, the ping() method is not called; that is, the application did not receive a heartbeat from the monitored subsystem.
Example
Asynchronous scopes are useful in stateful server applications. An application can have a startup bean that creates an asynchronous scope on a named work manager. The application also might create subsystem monitors to monitor the health of any remote systems on which the application is dependent.
When a client attaches to the server, the application creates a child asynchronous scope that is owned by the application asynchronous scope for the client and named using the client ID. A subsystem monitor for monitoring the client might be created on the client asynchronous scope. If the client times out, a callback can clean up the client state on the server. Callbacks can be attached to the application subsystem monitors, on behalf of the client. When a remote system becomes unavailable, the client code in the server is notified and an event is sent to the client to warn that a critical remote system has failed. For example, the failure might be a data feed in an electronic trading application.
See also
Asynchronous scopes
Alarms
Subsystem monitors
Asynchronous scopes: Dynamic message bean scenario