All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----JavaGroups.MethodInvoker
MethodInvoker
can be used to register an object so that its methods
can be invoked from a client using a
RemoteMethodCall object and is typically used in the server role. Sample code is
shown below:
import java.util.*; import JavaGroups.channel.*;
public class MethodInvokerTest { private Channel channel; private MethodInvoker inv;
public void Start() throws Exception { channel=new EnsChannel("MethodInvokerTest", null); channel.Connect(1000); inv=new MethodInvoker(channel, this); }
public Date GetCurrentDate() {return new Date();}
public float Divide(Integer x, Integer y) { return (float)x.intValue()/y.intValue(); }
public void ThrowMe() throws Exception { System.out.println("ThrowMe(): throwing exception"); throw new Exception("hello, this is a dummy exception from ThrowMe"); }
public long GetCurrentTimeMillis() {return System.currentTimeMillis();}
public static void main(String args[]) { MethodInvokerTest t=new MethodInvokerTest(); try { t.Start(); } catch(Exception e) { System.err.println(e); } }
}
The code first creates a channel object and connects to it. This allows clients which connect
to a channel with the same name to multicast method calls to all channels with the same name.
Then a MethodInvoker
object is created. The first argument is a transport used
to receive messages and send responses. The second is the object on which the method calls
will be invoked.
Methods to be invoked by MethodInvoker
have to have Objects because
primitive parameters (e.g. 'int') are currently not supported as Class objects for primitive
types cannot be serialized. As consequence, methods to be invoked remotely (via
MethodInvoker
) have to have Objects as parameters, rather than
primitive types. Return values, however, can be primitive types.
Note that a server role can at any time assume a client role by creating and sending remote method calls.
public MethodInvoker(Transport t, boolean create_pull_push_adapter)
public MethodInvoker(Transport t, Object target, boolean create_pull_push_adapter)
public void SetMethodLookup(MethodLookup lookup)
public synchronized void HoldRequests()
ReleaseRequests
will invoke all
queued requests on the target object(s) and reset the queuing flag.
public synchronized void ReleaseRequests()
HoldRequests
is made.
public void AddFunclet(Object target, String funclet_name, Object funclet)
funclet_name
field will be handled by
funclet
instead of target
. Both funclets and their methods
need to be public, otherwise an IllegalAccessException
will be thrown at
runtime.
public void AddTargetObject(Object target)RemoveTargetObject
public void RemoveTargetObject(Object target)RemoveAllTargetObjects
public void RemoveAllTargetObjects()Receive
public synchronized void Receive(Message msg)GetState
public Serializable GetState()SetState
public void SetState(Serializable state)main
public static void main(String args[])
All Packages Class Hierarchy This Package Previous Next Index