games.strategy.engine.message
Interface IChannelMessenger

All Known Implementing Classes:
ChannelMessenger

public interface IChannelMessenger

A simple way to multicast method calls over several machines and possibly several objects on each machine.
A channel can be created such that all channel subscribers must implement the same
interface. Channel subscribors can be on multiple machines. On VM A

 RemoteName FOO = new RemoteName("Foo", IFoo.class);
 
 IFoo aFoo = new Foo(); 
 someChannelMessenger.registerChannelSubscribor(aFoo, FOO);
 
 
On VM B
 
 IFoo anotherFoo = new Foo();
 anotherChannelMessenger.registerChannelSubscribor(anotherFoo, FOO);
 
 
 IFoo multicastFoo = (IFoo) anotherChannelMessenger.getChannelBroadcastor(FOO);
 multicastFoo.fee();

 
The multicast.fee() line results in two method calls, one on VM B to anotherFoo, and another call on VM A to aFoo.
The magic is done using reflection and dynamic proxies (java.lang.reflect.Proxy)
To avoid naming conflicts, it is advised to use the fully qualified java name and and a constant as channel names. For example channel names should be in the form

"foo.fee.Fi.SomeConstant"

where SomeConstant is defined in the class foo.fee.Fi

Channels and threading

There will only be one thread calling methods in a channel at one time. Methods will be called on subscribors in the order that they are called on broadcasters. This means that if you block the current thread during a client invocation, no further methods can be called on that channel.

Author:
Sean Bridges

Method Summary
 IChannelSubscribor getChannelBroadcastor(RemoteName channelName)
          Get a reference such that methods called on it will be multicast to all subscribors of the channel
 INode getLocalNode()
           
 boolean isServer()
          Is the underlying messenger a server?
 void registerChannelSubscriber(java.lang.Object implementor, RemoteName channelName)
          register a subscribor to a channel
 void unregisterChannelSubscriber(java.lang.Object implementor, RemoteName channelName)
          unregister a subscribor to a channel
 

Method Detail

getChannelBroadcastor

IChannelSubscribor getChannelBroadcastor(RemoteName channelName)
Get a reference such that methods called on it will be multicast to all subscribors of the channel


registerChannelSubscriber

void registerChannelSubscriber(java.lang.Object implementor,
                               RemoteName channelName)
register a subscribor to a channel


unregisterChannelSubscriber

void unregisterChannelSubscriber(java.lang.Object implementor,
                                 RemoteName channelName)
unregister a subscribor to a channel


getLocalNode

INode getLocalNode()

isServer

boolean isServer()
Is the underlying messenger a server?