All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class JavaGroups.MethodInvoker

java.lang.Object
   |
   +----JavaGroups.MethodInvoker

public class MethodInvoker
extends Object
implements MessageListener
A 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.

See Also:
RemoteMethodCall, Dispatcher

Constructor Index

 o MethodInvoker(Transport, boolean)
Creates a new MethodInvoker and (optionally) a PullPushAdapter and directs messages received by the PullPushAdapter to the MethodInvoker.
 o MethodInvoker(Transport, Object, boolean)
Creates a new MethodInvoker and (optionally) a PullPushAdapter and directs messages received by the PullPushAdapter to the MethodInvoker.

Method Index

 o AddFunclet(Object, String, Object)
A funclet handles requests on behalf of the target object.
 o AddTargetObject(Object)
 o GetState()
 o HoldRequests()
Every request received after this call will be stored in a queue instead of being invoked on the target object(s).
 o main(String[])
 o Receive(Message)
 o ReleaseRequests()
Removes all requests from the queue, invokes them on the target object(s) and resets the queueing flag.
 o RemoveAllTargetObjects()
 o RemoveTargetObject(Object)
 o SetMethodLookup(MethodLookup)
Allows to set a method resolution method which will be executed by the underlying MethodCall object to resolve the method.
 o SetState(Serializable)

Constructors

 o MethodInvoker
 public MethodInvoker(Transport t,
                      boolean create_pull_push_adapter)
Creates a new MethodInvoker and (optionally) a PullPushAdapter and directs messages received by the PullPushAdapter to the MethodInvoker.

Parameters:
t - Transport over which to send responses
create_pull_push_adapter - If true, a new instance of PullPushAdapter is created and messages received by it redirected to the MethodInvoker. Setting this parameter to false allows to create one's own PullPushAdapter (to invoke Receive).
 o MethodInvoker
 public MethodInvoker(Transport t,
                      Object target,
                      boolean create_pull_push_adapter)
Creates a new MethodInvoker and (optionally) a PullPushAdapter and directs messages received by the PullPushAdapter to the MethodInvoker.

Parameters:
t - Transport over which to send responses
target - Adds the object to the MethodInvoker's target set. Any time a message is received, it will be dispatched (in the form of a method invocation) to all objects in the target set.
create_pull_push_adapter - If true, a new instance of PullPushAdapter is created and messages received by it redirected to the MethodInvoker. Setting this parameter to false allows to create one's own PullPushAdapter (to invoke Receive).

Methods

 o SetMethodLookup
 public void SetMethodLookup(MethodLookup lookup)
Allows to set a method resolution method which will be executed by the underlying MethodCall object to resolve the method. If not set, MethodCall's internal lookup method will be used.

 o HoldRequests
 public synchronized void HoldRequests()
Every request received after this call will be stored in a queue instead of being invoked on the target object(s). Method ReleaseRequests will invoke all queued requests on the target object(s) and reset the queuing flag.

 o ReleaseRequests
 public synchronized void ReleaseRequests()
Removes all requests from the queue, invokes them on the target object(s) and resets the queueing flag. After this call, no requests will be queued any more until a call to HoldRequests is made.

 o AddFunclet
 public void AddFunclet(Object target,
                        String funclet_name,
                        Object funclet)
A funclet handles requests on behalf of the target object. All methods (MethodCalls) containing a non-empty 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.

 o AddTargetObject
 public void AddTargetObject(Object target)
 o RemoveTargetObject
 public void RemoveTargetObject(Object target)
 o RemoveAllTargetObjects
 public void RemoveAllTargetObjects()
 o Receive
 public synchronized void Receive(Message msg)
 o GetState
 public Serializable GetState()
 o SetState
 public void SetState(Serializable state)
 o main
 public static void main(String args[])

All Packages  Class Hierarchy  This Package  Previous  Next  Index