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.
Comments to this Manuals