Lightweight Bartering Grid

lbg.protocol.rpc
Class RemoteCall

java.lang.Object
  extended by lbg.protocol.rpc.RemoteCall
All Implemented Interfaces:
java.io.Serializable

public class RemoteCall
extends java.lang.Object
implements java.io.Serializable

A class implementing simple and protected calls to distant host. This class makes use of java.lang.reflect, and therefore allows polymorphism

Author:
Xavier Dalem, Cyril Briquet
See Also:
Serialized Form

Nested Class Summary
static class RemoteCall.CallType
          Who do we make the call to ?
 
Constructor Summary
RemoteCall(RemoteCall.CallType destination, java.lang.String methodName, java.lang.Class[] paramtypes, java.lang.Object[] params)
          Creates a remote call.
RemoteCall(RemoteCall.CallType destination, java.lang.String methodName, java.lang.Object... params)
          Creates a remote call.
Warning: you could experience problem with runtime types (e.g.
 
Method Summary
 java.lang.Object doCall(java.lang.Object obj)
          Makes the obj.methodName(params) call.
protected static LivePeerHandle getPeerHandle(java.lang.String host, int port)
          Gets a handle from a Peer just by knowing his host and port.
protected static LiveSearchEngineHandle getSearchEngineHandle(java.lang.String host, int port)
          Gets a handle from a search engine just by knowing his host and port.
 RemoteCall.CallType getType()
           
 java.lang.Object send(java.lang.String host, int port, boolean do_return)
          Opens a connection to host:port and send the call
 java.lang.Object send(java.lang.String host, int port, boolean do_return, boolean do_timeout)
          Opens a connection to host:port and send the call
 java.lang.Object send(java.lang.String host, int port, boolean do_return, boolean do_timeout, boolean do_failfast)
          Opens a connection to host:port and send the call
 java.lang.String toString()
          Sums up the call as a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RemoteCall

public RemoteCall(RemoteCall.CallType destination,
                  java.lang.String methodName,
                  java.lang.Object... params)
           throws GridException
Creates a remote call.
Warning: you could experience problem with runtime types (e.g. with interfaces)

Parameters:
destination - The node we are talking to
methodName - The name of the method
params - The paramaters for called function
Throws:
GridException
See Also:
RemoteCall(CallType type, String methodName, Class[] paramtypes, Object[] params)

RemoteCall

public RemoteCall(RemoteCall.CallType destination,
                  java.lang.String methodName,
                  java.lang.Class[] paramtypes,
                  java.lang.Object[] params)
           throws GridException
Creates a remote call. This constructor, unlike RemoteCall(Calltype, String, Object...), is type-safe.

Parameters:
destination - The node we are talking to
methodName - The name of the method
paramtypes - The classes of the parameters
params - The paramaters for called function
Throws:
GridException
See Also:
RemoteCall(CallType type, String methodName, Object... params)
Method Detail

getPeerHandle

protected static LivePeerHandle getPeerHandle(java.lang.String host,
                                              int port)
                                       throws GridException
Gets a handle from a Peer just by knowing his host and port.
This is simply a shorthand. You can get also handle without this.

Parameters:
host - Peer host
port - Peer port
Throws:
GridException - if getting the handle was not possible

getSearchEngineHandle

protected static LiveSearchEngineHandle getSearchEngineHandle(java.lang.String host,
                                                              int port)
                                                       throws GridException
Gets a handle from a search engine just by knowing his host and port.
This is simply a shorthand. You can get also handle without this.

Parameters:
host - Search host
port - Search port
Throws:
GridException - if getting the handle was not possible

doCall

public java.lang.Object doCall(java.lang.Object obj)
                        throws GridException,
                               java.lang.reflect.InvocationTargetException
Makes the obj.methodName(params) call.

Parameters:
obj - The object to make the call on (will be type-checked)
Returns:
The result of the invoked method
Throws:
GridException - if the call is not supported by that object.
java.lang.reflect.InvocationTargetException - if the underlying method throws an exception.

send

public java.lang.Object send(java.lang.String host,
                             int port,
                             boolean do_return)
                      throws GridException
Opens a connection to host:port and send the call

Parameters:
host - The host to send it to
port - The port on where to send it
do_return - True if we wait for a return value
Returns:
The remote call return value, or null if do_return is false
Throws:
GridException - if the parameters are invalid
GridNetworkException - if the remote host couldn't be reached or didn't format its messages as expected.

send

public java.lang.Object send(java.lang.String host,
                             int port,
                             boolean do_return,
                             boolean do_timeout)
                      throws GridException
Opens a connection to host:port and send the call

Parameters:
host - The host to send it to
port - The port on where to send it
do_return - true if we wait for a return value
do_timeout - false to deactivate the transmission timeout
Returns:
The remote call return value, or null if do_return is false
Throws:
GridException - if the parameters are invalid
GridNetworkException - if the remote host couldn't be reached or didn't format its messages as expected.

send

public java.lang.Object send(java.lang.String host,
                             int port,
                             boolean do_return,
                             boolean do_timeout,
                             boolean do_failfast)
                      throws GridException
Opens a connection to host:port and send the call

Parameters:
host - The host to send it to
port - The port on where to send it
do_return - true if we wait for a return value
do_timeout - false to deactivate the transmission timeout
do_failfast - true to retry only once, and immediately, in case of comm. failure
Returns:
The remote call return value, or null if do_return is false
Throws:
GridException - if the parameters are invalid
GridNetworkException - if the remote host couldn't be reached or didn't format its messages as expected.

getType

public RemoteCall.CallType getType()

toString

public java.lang.String toString()
Sums up the call as a string

Overrides:
toString in class java.lang.Object

Lightweight Bartering Grid

Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.