com.googlecode.mobilityrpc.session.impl
Class MobilitySessionImpl

java.lang.Object
  extended by com.googlecode.mobilityrpc.session.impl.MobilitySessionImpl
All Implemented Interfaces:
MobilitySessionInternal, MobilitySession

public class MobilitySessionImpl
extends Object
implements MobilitySessionInternal

Author:
Niall Gallagher

Constructor Summary
MobilitySessionImpl(UUID sessionId, MobilityControllerInternal mobilityController)
           
 
Method Summary
<T> T
execute(ConnectionId connectionId, Callable<T> callable)
          Transfers the given Callable object, and any objects it references, to the given remote machine, and executes it (calls the Callable.call() method) on the remote machine.
<T> T
execute(ConnectionId connectionId, ExecutionMode executionMode, Callable<T> callable)
          Transfers the given Callable object, and any objects it references, to the given remote machine, and executes it (calls the Callable.call() method) on the remote machine.
 void execute(ConnectionId connectionId, ExecutionMode executionMode, Runnable runnable)
          Transfers the given Runnable object, and any objects it references, to the given remote machine, and executes it (calls the Runnable.run() method) on the remote machine.
 void execute(ConnectionId connectionId, Runnable runnable)
          Transfers the given Runnable object, and any objects it references, to the given remote machine, and executes it (calls the Runnable.run() method) on the remote machine.
<T> T
execute(String address, Callable<T> callable)
          Transfers the given Callable object, and any objects it references, to the given remote machine, and executes it (calls the Callable.call() method) on the remote machine.
 void execute(String address, Runnable runnable)
          Transfers the given Runnable object, and any objects it references, to the given remote machine, and executes it (calls the Runnable.run() method) on the remote machine.
 MobilityController getMobilityController()
          Returns the mobility controller which manages this session.
 SessionClassLoader getSessionClassLoader()
          Returns the class loader associated with this session.
 UUID getSessionId()
          Returns the UUID of this session.
 void receiveExecutionResponse(ExecutionResponse executionResponse)
          Called when we receive an incoming ExecutionResponse object from a remote machine addressed to this session.
 void receiveIncomingExecutionRequest(ConnectionId connectionId, ExecutionRequest executionRequest)
          Called when we receive an incoming ExecutionRequest object from a remote machine addressed to this session.
 void release()
          Removes this session from the mobility controller.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MobilitySessionImpl

public MobilitySessionImpl(UUID sessionId,
                           MobilityControllerInternal mobilityController)
Method Detail

getSessionId

public UUID getSessionId()
Description copied from interface: MobilitySession
Returns the UUID of this session.

Specified by:
getSessionId in interface MobilitySession
Returns:
the UUID of this session

execute

public void execute(String address,
                    Runnable runnable)
Description copied from interface: MobilitySession
Transfers the given Runnable object, and any objects it references, to the given remote machine, and executes it (calls the Runnable.run() method) on the remote machine.

This is a convenience method for calling MobilitySession.execute(ConnectionId, ExecutionMode, Runnable) with ExecutionMode.RETURN_RESPONSE and default port 5739 in the connection id.

Specified by:
execute in interface MobilitySession
Parameters:
address - The address (ip or name) of the remote machine
runnable - The object to send and execute on the remote machine

execute

public void execute(ConnectionId connectionId,
                    Runnable runnable)
Description copied from interface: MobilitySession
Transfers the given Runnable object, and any objects it references, to the given remote machine, and executes it (calls the Runnable.run() method) on the remote machine.

This is a convenience method for calling MobilitySession.execute(ConnectionId, ExecutionMode, Runnable) with ExecutionMode.RETURN_RESPONSE.

Specified by:
execute in interface MobilitySession
Parameters:
connectionId - The address/port of the remote machine
runnable - The object to send and execute on the remote machine

execute

public void execute(ConnectionId connectionId,
                    ExecutionMode executionMode,
                    Runnable runnable)
Description copied from interface: MobilitySession
Transfers the given Runnable object, and any objects it references, to the given remote machine, and executes it (calls the Runnable.run() method) on the remote machine.

Specified by:
execute in interface MobilitySession
Parameters:
connectionId - The address/port of the remote machine
executionMode - Either of the following, see: ExecutionMode.RETURN_RESPONSE or ExecutionMode.FIRE_AND_FORGET
runnable - The object to send to the remote machine

execute

public <T> T execute(String address,
                     Callable<T> callable)
Description copied from interface: MobilitySession
Transfers the given Callable object, and any objects it references, to the given remote machine, and executes it (calls the Callable.call() method) on the remote machine. Transfers the object returned by the call method on the remote machine, and any objects it references, back to the local application.

This is a convenience method for calling MobilitySession.execute(ConnectionId, ExecutionMode, Runnable) with ExecutionMode.RETURN_RESPONSE and default port 5739 in the connection id.

Specified by:
execute in interface MobilitySession
Parameters:
address - The address (ip or name) of the remote machine
callable - The object to send to the remote machine
Returns:
The object returned by the Callable.call() method on the remote machine (transferred back to this machine)

execute

public <T> T execute(ConnectionId connectionId,
                     Callable<T> callable)
Description copied from interface: MobilitySession
Transfers the given Callable object, and any objects it references, to the given remote machine, and executes it (calls the Callable.call() method) on the remote machine. Transfers the object returned by the call method on the remote machine, and any objects it references, back to the local application.

This is a convenience method for calling MobilitySession.execute(ConnectionId, ExecutionMode, Runnable) with ExecutionMode.RETURN_RESPONSE.

Specified by:
execute in interface MobilitySession
Parameters:
connectionId - The address/port of the remote machine
callable - The object to send to the remote machine
Returns:
The object returned by the Callable.call() method on the remote machine (transferred back to this machine)

execute

public <T> T execute(ConnectionId connectionId,
                     ExecutionMode executionMode,
                     Callable<T> callable)
Description copied from interface: MobilitySession
Transfers the given Callable object, and any objects it references, to the given remote machine, and executes it (calls the Callable.call() method) on the remote machine. Transfers the object returned by the call method on the remote machine, and any objects it references, back to the local application.

Specified by:
execute in interface MobilitySession
Parameters:
connectionId - The address/port of the remote machine
executionMode - Either of the following, see: ExecutionMode.RETURN_RESPONSE or ExecutionMode.FIRE_AND_FORGET
callable - The object to send to the remote machine
Returns:
The object returned by the Callable.call() method on the remote machine (transferred back to this machine)

receiveIncomingExecutionRequest

public void receiveIncomingExecutionRequest(ConnectionId connectionId,
                                            ExecutionRequest executionRequest)
Description copied from interface: MobilitySessionInternal
Called when we receive an incoming ExecutionRequest object from a remote machine addressed to this session.

This method will submit this request to the session's thread pool for execution asynchronously. This method will return immediately.

Specified by:
receiveIncomingExecutionRequest in interface MobilitySessionInternal
Parameters:
connectionId - Indicates the connection from which we received the request
executionRequest - A request from a remote machine to execute a serialized object on this machine

receiveExecutionResponse

public void receiveExecutionResponse(ExecutionResponse executionResponse)
Description copied from interface: MobilitySessionInternal
Called when we receive an incoming ExecutionResponse object from a remote machine addressed to this session.

This method will look up and unblock the relevant thread which is waiting for the response to arrive.

Specified by:
receiveExecutionResponse in interface MobilitySessionInternal
Parameters:
executionResponse - A response from a remote machine for an execution request sent by a thread on this machine

getSessionClassLoader

public SessionClassLoader getSessionClassLoader()
Description copied from interface: MobilitySession
Returns the class loader associated with this session.

Specified by:
getSessionClassLoader in interface MobilitySession
Returns:
The class loader associated with this session

getMobilityController

public MobilityController getMobilityController()
Description copied from interface: MobilitySession
Returns the mobility controller which manages this session.

Specified by:
getMobilityController in interface MobilitySession
Returns:
The mobility controller which manages this session

release

public void release()
Description copied from interface: MobilitySession
Removes this session from the mobility controller.

All references to the session and its class loader will be released by the library. This means that, unless some application code has stored a reference to the session somewhere, the session and all of the classes it has loaded will be garbage collected. Also note that this means that any data stored in static fields in those classes will also be garbage collected.

Deferred Session Release
Note that if this is called on a remote machine by an object sent to that machine, the remote machine will defer releasing the session until all threads concurrently processing requests in that session have finished.

This mechanism allows mobile code to effectively schedule the session in which it is executing, on what it views as the local machine, to be released after it has finished executing on that machine.

If this method is called by a thread not managed by the library (e.g. from the host application), the method will check if remote threads are executing in the session, and either schedule the session to be released when those threads finish, or release it immediately if the session is actually not in use.

See also MobilityController.releaseSession(java.util.UUID), which bypasses this safeguard, and allows sessions to be released immediately.

Specified by:
release in interface MobilitySession

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.