org.sapia.ubik.rmi.server
Class Hub

java.lang.Object
  extended by org.sapia.ubik.rmi.server.Hub

public class Hub
extends java.lang.Object

This class is the single-entry point into Ubik RMI's API.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site

Field Summary
static ClientRuntime clientRuntime
          The object implementing client-side behavior
static ServerRuntime serverRuntime
          The object implementing server-side behavior
static StatsCollector statsCollector
          The stats collector
static TaskManager taskMan
          The hub's task manager
 
Constructor Summary
Hub()
           
 
Method Summary
static java.lang.Object asRemote(java.lang.Object o, VmId caller, java.lang.String transportType)
          Returns a stub for the given object.
static RemoteRef asRemoteRef(java.lang.Object o, VmId caller, java.lang.String transportType)
          Returns a remote reference for the given object.
static java.lang.Object connect(ServerAddress address)
          This method allows connecting to a RMI server listening on the given address.
static java.lang.Object connect(java.lang.String host, int port)
          This method allows connecting to a RMI server listening to the given host and port.
static java.lang.Object exportObject(java.lang.Object o)
          "Exports" the passed in object as a remote RMI server: this method internally starts an RMI server that listens on a random port and implements the interfaces of the passed in object.
static java.lang.Object exportObject(java.lang.Object o, int port)
          This method creates a server listening on the specified port.
static java.lang.Object exportObject(java.lang.Object o, java.util.Properties props)
          Exports the given object as a server (and creates a remote reference).
static java.lang.Object exportObject(java.lang.Object o, java.lang.String transportType)
          Exports the given object as a remote object that will receive request through a server that must already have been exported for the given transport type.
static ServerAddress getServerAddressFor(java.lang.String transportType)
          Returns the address of the server for the given transport type.
static java.lang.Object getStubFor(RemoteRef ref, java.lang.Object remote)
           
static boolean isShutdown()
          Returns true if the Hub is shut down.
static void shutdown(long timeout)
          Shuts down this instance; some part of the shutdown can be asynchronous.
static java.lang.Object toReliableStub(java.lang.Object obj)
          Returns a "reliable" stub for the given passed in stub; the dynamically generated proxy (created with Java's reflection API) wraps an InvocationHandler of the StubHandlerReliable class.
static java.lang.Object toStatelessStub(javax.naming.Name name, java.lang.String domain, java.lang.Object obj)
          Returns a stateless stub for the given object.
static java.lang.Object toStub(java.lang.Object o)
          Generates the stub for the object passed in and returns it.
static void unexport(java.lang.ClassLoader loader)
          This method "unexports" all objects whose class was loaded by the given ClassLoader.
static void unexport(java.lang.Object o)
          This method "unexports" an object that was exported through one of this class' export() methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statsCollector

public static final StatsCollector statsCollector
The stats collector


taskMan

public static final TaskManager taskMan
The hub's task manager


clientRuntime

public static final ClientRuntime clientRuntime
The object implementing client-side behavior


serverRuntime

public static final ServerRuntime serverRuntime
The object implementing server-side behavior

Constructor Detail

Hub

public Hub()
Method Detail

toStub

public static java.lang.Object toStub(java.lang.Object o)
                               throws java.rmi.RemoteException
Generates the stub for the object passed in and returns it.

Returns:
an Object which is the stub of the instance passed in.
Throws:
java.rmi.RemoteException - if a problem occurs performing the connection.

toReliableStub

public static java.lang.Object toReliableStub(java.lang.Object obj)
Returns a "reliable" stub for the given passed in stub; the dynamically generated proxy (created with Java's reflection API) wraps an InvocationHandler of the StubHandlerReliable class.

The object passed as a parameter is expected to be a stub whose invocation handler is assumed to be of the StubHandlerBasic type. This method thus performs a stub substitution.

Returns:
a "reliable" stub for the given stub.
See Also:
RemoteRefReliable, RemoteRefEx

toStatelessStub

public static java.lang.Object toStatelessStub(javax.naming.Name name,
                                               java.lang.String domain,
                                               java.lang.Object obj)
Returns a stateless stub for the given object.

Parameters:
name - the name of the object for which a stateless stub should be returned.
domain - the name of the domain to which the object "belongs".
obj -
Returns:
a Stateless stub.
See Also:
Stateless

exportObject

public static java.lang.Object exportObject(java.lang.Object o)
                                     throws java.rmi.RemoteException
"Exports" the passed in object as a remote RMI server: this method internally starts an RMI server that listens on a random port and implements the interfaces of the passed in object. The stub is returned and can be bound to the JNDI.

Returns:
the stub corresponding to the exported object.
Throws:
java.rmi.RemoteException - if a problem occurs performing the connection.
See Also:
exportObject(Object, int), connect(String, int)

exportObject

public static java.lang.Object exportObject(java.lang.Object o,
                                            int port)
                                     throws java.rmi.RemoteException
This method creates a server listening on the specified port.

Returns:
the stub for the given exported object.
Throws:
java.rmi.RemoteException - if a problem occurs performing the connection.
See Also:
exportObject(Object)

exportObject

public static java.lang.Object exportObject(java.lang.Object o,
                                            java.util.Properties props)
                                     throws java.rmi.RemoteException
Exports the given object as a server (and creates a remote reference). The properties passed in must contain the property identifying the desired "transport type" (ubik.rmi.transport.type).

The method returns the stub for the given object.

Returns:
the stub of the exported server.
Throws:
java.rmi.RemoteException
See Also:
TransportManager, TransportManager.getProviderFor(String), TransportProvider

exportObject

public static java.lang.Object exportObject(java.lang.Object o,
                                            java.lang.String transportType)
                                     throws java.rmi.RemoteException
Exports the given object as a remote object that will receive request through a server that must already have been exported for the given transport type.

The method returns the stub for the given object.

Parameters:
o - an Object to export.
transportType - the identifier of the transport layer to which the given object will be exported.
Returns:
a stub.
Throws:
java.rmi.RemoteException - if the object could not be exported.

unexport

public static void unexport(java.lang.Object o)
This method "unexports" an object that was exported through one of this class' export() methods. The unexported object will not receive remote method calls anymore.

NOTE: this method does not stop the server through which the exported instance is receiving remote method calls. To stop the servers that have been started by the Hub, call the latter's shutdown() method.

Parameters:
o - the exported object that is to be unexported.
See Also:
shutdown(long)

unexport

public static void unexport(java.lang.ClassLoader loader)
This method "unexports" all objects whose class was loaded by the given ClassLoader.

This method can be useful in hot-deploy scenarios.

NOTE: this method does not stop the server through which the exported instances (that correspond to the given classloader) are receiving remote method calls. To stop the servers that have been started by the Hub, call the latter's shutdown() method.

Parameters:
loader -
See Also:
shutdown(long)

connect

public static java.lang.Object connect(java.lang.String host,
                                       int port)
                                throws java.rmi.RemoteException
This method allows connecting to a RMI server listening to the given host and port.

Throws:
java.rmi.RemoteException - if a problem occurs performing the connection.

connect

public static java.lang.Object connect(ServerAddress address)
                                throws java.rmi.RemoteException
This method allows connecting to a RMI server listening on the given address.

Parameters:
address - the ServerAddress corresponding to the target server's physical endpoint.
Throws:
java.rmi.RemoteException - if a problem occurs performing the connection.

getServerAddressFor

public static ServerAddress getServerAddressFor(java.lang.String transportType)
Returns the address of the server for the given transport type.

Parameters:
transportType - the logical identifier of a "transport type".
Returns:
a ServerAddress,

asRemote

public static java.lang.Object asRemote(java.lang.Object o,
                                        VmId caller,
                                        java.lang.String transportType)
                                 throws java.rmi.RemoteException
Returns a stub for the given object. This method is usually not called by client application. It is meant for use by the different transport layers.

Parameters:
o - an object.
caller - the VM identifier of the client that triggered the creation of the returned remote reference.
transportType - the "transport type" for which to return a remote reference.
Returns:
a stub.
Throws:
java.rmi.RemoteException
See Also:
asRemoteRef(Object, VmId, String)

asRemoteRef

public static RemoteRef asRemoteRef(java.lang.Object o,
                                    VmId caller,
                                    java.lang.String transportType)
                             throws java.rmi.RemoteException
Returns a remote reference for the given object. This method is usually not called by client application. It is meant for use by the different transport layers.

Parameters:
o - an object.
caller - the VM identifier of the client that triggered the creation of the returned remote reference.
transportType - the "transport type" for which to return a remote reference.
Returns:
a RemoteRef.
Throws:
java.rmi.RemoteException

isShutdown

public static boolean isShutdown()
Returns true if the Hub is shut down.

Returns:
true if the Hub is shut down.

shutdown

public static void shutdown(long timeout)
                     throws java.lang.InterruptedException
Shuts down this instance; some part of the shutdown can be asynchronous. A timeout must be given in order not to risk the shutdown to last for too long.

Parameters:
timeout - a shutdown "timeout", in millis.
Throws:
java.lang.InterruptedException

getStubFor

public static java.lang.Object getStubFor(RemoteRef ref,
                                          java.lang.Object remote)


Copyright © 2010 Sapia OSS. All Rights Reserved.