games.strategy.engine.message
Interface IRemoteMessenger

All Known Implementing Classes:
RemoteMessenger

public interface IRemoteMessenger

Very similar to RMI

Objects can be registered with a remote messenger under a public name and declared to implement a particular interface. Methods on this registered object can then be called on different vms.

To call a method on the registered object, you get a remote reference to it using the getRemote(...) method. This returns an object that can be used and called as if it were the original implementor.

The getRemote(...) method though may be called on a different vm than the registerRemote(...) method. In that case the calls on the return value of getRemote(...) will be routed to the implementor object passed to registerRemote(...) On VM A you have code like

 
 RemoteName FOO = new RemoteName("Foo", IFoo.class);
 
 IFoo aFoo = new Foo(); 
 aRemoteMessenger.registerRemote(IFoo.class, aFoo, FOO);
 
 
After this runs, on VM B you can do
   
 IFoo someFoo = anotherRemoteMessenger.getRemote(FOO);
 boolean rVal = someFoo.fee();
 if(rVal)
   ...
 
 
What will happen is that the fee() call in VM B will be invoked on aFoo in VM A.
This 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 be used as the channel name. For example names should be in the form


"foo.fee.Fi.SomeConstant"

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


Remotes and threading

Remotes are multithreaded. Method calls may arrive out of order that methods were called.

Author:
Sean Bridges
See Also:
IRemote, java.lang.reflect.Proxy

Method Summary
 IRemote getRemote(RemoteName name)
           
 boolean hasLocalImplementor(RemoteName name)
           
 boolean isServer()
           
 void registerRemote(java.lang.Object implementor, RemoteName name)
           
 void unregisterRemote(RemoteName name)
          Remove the remote registered under name.
 void unregisterRemote(java.lang.String name)
          Remove the remote registered under name.
 

Method Detail

getRemote

IRemote getRemote(RemoteName name)
Parameters:
name - the name the remote is registered under.
Returns:
a remote reference to the registered remote.

registerRemote

void registerRemote(java.lang.Object implementor,
                    RemoteName name)
Parameters:
remoteInterface - - the remote interface that implementor implements, must be a subclass of IRemote
implementor - - an object that implements remoteInterface
name - - the name that implementor will be registered under

unregisterRemote

void unregisterRemote(java.lang.String name)
Remove the remote registered under name.


unregisterRemote

void unregisterRemote(RemoteName name)
Remove the remote registered under name.


hasLocalImplementor

boolean hasLocalImplementor(RemoteName name)

isServer

boolean isServer()