com.sentilla.net.rpc
Class RemoteInvoker

java.lang.Object
  extended by com.sentilla.net.rpc.RemoteInvoker
All Implemented Interfaces:
Action

public class RemoteInvoker
extends Object
implements Action

RemoteInvoker manages an RPC transaction between a caller and callee(s). Construct RemoteInvoker with a sender for the destination motes, and a result_factory for the response to be sent by the callee back to the caller. Then, send and invoke the procedure on the callees with one of the invoke routines. invoke(procedure, result_type) returns a single result. invokeMany(procedure, result_type, maxResults, timeoutMilli) returns multiple results through an iterable abstraction. If the remote procedure returns an exception instead of providing results, the exception is returned and thrown back at the caller.


Nested Class Summary
protected  class RemoteInvoker.ResultIter<T>
           
 
Field Summary
 
Fields inherited from interface com.sentilla.system.Action
DONE, ERROR, IDLE, PENDING
 
Constructor Summary
RemoteInvoker(Sender sender, SenderFactory result_factory)
          Create a new RemoteInvoker for a particular sender and result path.
 
Method Summary
 Action block()
          Block an indefinite amount of time until this Action is no longer pending.
 Action block(int timeoutMilli)
          Block a defined amount of time or until the Action is no longer pending.
 Action cancel()
          Cancel this Action if PENDING.
 byte getActionState()
          Get the current state of this Action: IDLE, PENDING, DONE, or ERROR.
 Procedure getProcedure()
           
 Receiver getReceiver()
           
 Object getResult()
           
<T> T
getResult(Class<T> result_type)
           
<T> Iterable<Result<T>>
getResultMany(Class<T> result_type, int maxResults, int timeoutMilli)
           
 Sender getSender()
           
<T> T
invoke(Procedure<T> procedure, Class<T> result_type)
          Remotely invoke a procedure and return a single result.
<T> T
invoke(Procedure<T> procedure, Class<T> result_type, int timeoutMilli)
          Remotely invoke a procedure and return a single result.
<T> Iterable<Result<T>>
invokeMany(Procedure<T> procedure, Class<T> result_type, int maxResults, int timeoutMilli)
          Remotely invoke a procedure and return an iterable over possibly many results.
 boolean isDone()
          Return true is this Action is DONE.
 RemoteInvoker setProcedure(Procedure procedure)
           
 RemoteInvoker setSender(Sender sender)
           
 Action submit()
          Submit this Action for processing by the action engine.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteInvoker

public RemoteInvoker(Sender sender,
                     SenderFactory result_factory)
Create a new RemoteInvoker for a particular sender and result path. Sender should send the RPC message to the callees, and result_factory should allow the callees to return results back to the sender.

Method Detail

invoke

public <T> T invoke(Procedure<T> procedure,
                    Class<T> result_type)
Remotely invoke a procedure and return a single result. Locally rethrow any RuntimeException that occurs in the remote run method of this procedure. This will block until a result is received.

Parameters:
procedure - instance of Procedure to execute
result_type - result type to expect
Returns:
return value from RPC

invoke

public <T> T invoke(Procedure<T> procedure,
                    Class<T> result_type,
                    int timeoutMilli)
Remotely invoke a procedure and return a single result. Locally rethrow any RuntimeException that occurs in the remote run method of this procedure.

Parameters:
procedure - instance of Procedure to execute
result_type - result type to expect
timeoutMilli - milliseconds to wait for return result
Returns:
return value from RPC or null if timed out

invokeMany

public <T> Iterable<Result<T>> invokeMany(Procedure<T> procedure,
                                          Class<T> result_type,
                                          int maxResults,
                                          int timeoutMilli)
Remotely invoke a procedure and return an iterable over possibly many results. A remote RuntimeException in the run procedure is rethrown by Result.getResult(), allowing for unintertuped iteration given some exceptions. The iteration is complete after either maxResults results are receiver or timeoutMilli milliseconds elapse from invocation.


setProcedure

public RemoteInvoker setProcedure(Procedure procedure)

setSender

public RemoteInvoker setSender(Sender sender)

getProcedure

public Procedure getProcedure()

getSender

public Sender getSender()

getReceiver

public Receiver getReceiver()

getResult

public Object getResult()

getResult

public <T> T getResult(Class<T> result_type)

getResultMany

public <T> Iterable<Result<T>> getResultMany(Class<T> result_type,
                                             int maxResults,
                                             int timeoutMilli)

submit

public Action submit()
Description copied from interface: Action
Submit this Action for processing by the action engine. Calling submit transitions this Action to PENDING from either IDLE, DONE, or ERROR. Nothing happens if this Action is already PENDING.

Specified by:
submit in interface Action
Returns:
A pointer to this Action.

block

public Action block()
             throws ActionException
Description copied from interface: Action
Block an indefinite amount of time until this Action is no longer pending. Return immediately if the Action is IDLE or DONE. Return when the Action leaves the PENDING state, either through completion or cancellation. Throw ActionException if the Action is in ERROR.

Specified by:
block in interface Action
Returns:
A pointer to this Action.
Throws:
ActionException

block

public Action block(int timeoutMilli)
             throws ActionException
Description copied from interface: Action
Block a defined amount of time or until the Action is no longer pending. Return immediately if the Action is IDLE or DONE. Return when the Action leaves the PENDING state, either through completion or cancellation, or until the timeout occurs, whichever comes first. Throw ActionException is the Action is in ERROR.

Specified by:
block in interface Action
Parameters:
timeoutMilli - the maximum number of milliseconds to block
Returns:
A pointer to this Action.
Throws:
ActionException

cancel

public Action cancel()
Description copied from interface: Action
Cancel this Action if PENDING. If cancel successfully completes, it transitions this Action to IDLE from any state. If this Action is PENDING, a best effort is made to remove it from the underlying Action engine, and failing that, exception XXX-TODO is thrown.

Specified by:
cancel in interface Action
Returns:
A pointer to this Action.

getActionState

public byte getActionState()
Description copied from interface: Action
Get the current state of this Action: IDLE, PENDING, DONE, or ERROR.

Specified by:
getActionState in interface Action

isDone

public boolean isDone()
               throws ActionException
Description copied from interface: Action
Return true is this Action is DONE. isDone can be used with block(timeoutMilli) to determine if the Action has completed. Calling isDone is equivalent to getActionState() == Action.DONE. Throw ActionException is getActionState() == Action.ERROR.

Specified by:
isDone in interface Action
Throws:
ActionException


Copyright © 2007 Sentilla Corporation. All Rights Reserved.