APC AP9212 User's Guide Page 36

  • Download
  • Add to my manuals
  • Print
  • Page
    / 147
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 35
36
4.4.2 Messages
Masterswitch status information is broadcast to clients on the CHANNEL_MASTERSWITCH,
initialised at the APTServer start-up .
...
// APTServer.java
// Create the Masterswitch Channel
JASChannel masterswitchChannel =
client.makeChannel(Channels.CHANNEL_MASTERSWITCH);
masterswitchChannel.join();
// Initalise the Masterswitch
JASMasterswitch.getJASMasterswitch( masterswitchChannel );
...
Figure 4-6 Initialising the Masterswitch channel
The MasteswitchChannelWatcher, instantiated within the JASMasterswitch object, monitors
the JASChannel, using the method discussed in Appendix B.5, to send full status information to
new clients joining the Masterswitch channel.
// Monitor the Masterswitch Channel and send any new subscribers all status
// information
private class MasterswitchChannelWatcher extends ChannelAdaptor {
public void channelConsumerAdded(ChannelEvent event) {
try {
log.log( Level.INFO, "Detected new "+ Channels.CHANNEL_MASTERSWITCH +
" subscriber: "+event.getClientName() );
masterswitchChannel.sendToClient( prepareCompleteMsg(),
event.getClientName() );
} catch (JSDTException e) {
log.log( Level.INFO, "Couldn't send new subscriber information");
}
}
}
Figure 4-7 Masterswitch channel monitoring
To keep the status information up to date, the JASMasterswitch must broadcast JASMessages
notifying clients of any change in state. This is achieved by utilising the MasterswitchListener
interface.
Whenever a Masterswitch Event occurs, the JASMasterswitch prepares and sends a
JASStatusMessage with the updated state information. The key values used to identify
properties within the JASStatusMessage are statically defined in JASMasterswitch.java, as
shown below in Figure 4-8.
Page view 35
1 2 ... 31 32 33 34 35 36 37 38 39 40 41 ... 146 147

Comments to this Manuals

No comments