wt.util
Class RMIServer

java.lang.Object
  extended byjava.rmi.server.RemoteObject
      extended byjava.rmi.server.RemoteServer
          extended bywt.util.RMIServer
All Implemented Interfaces:
Remote, Serializable
Direct Known Subclasses:
CacheManager, MethodServerImpl, ServerManagerImpl, StandardServerMonitor

public class RMIServer
extends RemoteServer

A version of UnicastRemoteObject that allows on-the-fly configuration of the port number on which objects are exported, the host name used by clients when connecting, and object identifier (oid). Port number is set statically for all instances of RMIServer subclasses in a single JVM. Hostname and oid can be set per instance.

Control of hostname and oid allows building RMI server objects that can work in load balanced server clusters.

See Also:
Serialized Form

Field Summary
private static RMIClientSocketFactory CLIENT_SOCKET_FACTORY
           
private static Method CREATE_PROXY_METHOD
           
 RMIClientSocketFactory csf
           
private  boolean exported
           
private  String hostname
           
private static InetAddress[] localAddrs
           
private static String localName
           
private  RemoteStub marshalStub
           
private  int oid
           
private static int port
           
private static Class REMOTE_PROXY_CLASS
           
private static String RESOURCE
           
private static InetAddress[] rmiAddrs
           
private static RMIServerSocketFactory SERVER_SOCKET_FACTORY
           
 RMIServerSocketFactory ssf
           
private  RemoteStub stub
           
private static Class SUN_RMI_UTIL_CLASS
           
 
Fields inherited from class java.rmi.server.RemoteServer
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
protected RMIServer()
           
protected RMIServer(int oid)
           
protected RMIServer(String hostname)
           
protected RMIServer(String hostname, int oid)
           
protected RMIServer(String hostname, int oid, boolean export)
           
protected RMIServer(String hostname, int oid, boolean export, RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
           
 
Method Summary
 Object clone()
          Returns a clone of the remote object that is distinct from the original.
private static RemoteStub createProxy(String remote_classname, Class stub_class, sun.rmi.transport.LiveRef live_ref)
           
static RemoteStub exportObject(Remote obj)
          Export the remote object to make it available to receive incoming calls.
static RemoteStub exportObject(Remote obj, String hostname, int oid)
          Export the remote object to make it available to receive incoming calls.
static RemoteStub exportObject(Remote obj, String hostname, int oid, RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
          Export the remote object to make it available to receive incoming calls.
private static Class getClassForName(String className, boolean failQuietly)
           
static RMIClientSocketFactory getClientSocketFactory()
           
private static Method getMethod(Class cls, String methodName, Class[] argTypes, boolean failQuietly)
           
static int getPort()
          Get port number on which RMIServer objects are exported.
static RMIServerSocketFactory getServerSocketFactory()
           
 RemoteStub getStub()
          Get remote stub from exporting of this server object.
static boolean isHostInList(String host, String list)
          Utility method to check if a given host is in a list of host names.
static boolean isLocalHost(String host)
          Utility method to check if a given host is the local host.
private  void readObject(ObjectInputStream in)
          Re-export the remote object when it is deserialized.
private  void reexport()
           
static void setPort(int port)
          Set port number on which RMIServer objects are exported.
 Object writeReplace()
           
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLIENT_SOCKET_FACTORY

private static RMIClientSocketFactory CLIENT_SOCKET_FACTORY

SERVER_SOCKET_FACTORY

private static RMIServerSocketFactory SERVER_SOCKET_FACTORY

port

private static int port

hostname

private String hostname

oid

private int oid

csf

public RMIClientSocketFactory csf

ssf

public RMIServerSocketFactory ssf

stub

private RemoteStub stub

marshalStub

private RemoteStub marshalStub

exported

private boolean exported

REMOTE_PROXY_CLASS

private static final Class REMOTE_PROXY_CLASS

SUN_RMI_UTIL_CLASS

private static final Class SUN_RMI_UTIL_CLASS

CREATE_PROXY_METHOD

private static final Method CREATE_PROXY_METHOD

localName

private static String localName

localAddrs

private static InetAddress[] localAddrs

rmiAddrs

private static InetAddress[] rmiAddrs
Constructor Detail

RMIServer

protected RMIServer()
             throws RemoteException

RMIServer

protected RMIServer(String hostname)
             throws RemoteException

RMIServer

protected RMIServer(int oid)
             throws RemoteException

RMIServer

protected RMIServer(String hostname,
                    int oid)
             throws RemoteException

RMIServer

protected RMIServer(String hostname,
                    int oid,
                    boolean export)
             throws RemoteException

RMIServer

protected RMIServer(String hostname,
                    int oid,
                    boolean export,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf)
             throws RemoteException
Method Detail

getClientSocketFactory

public static RMIClientSocketFactory getClientSocketFactory()

getServerSocketFactory

public static RMIServerSocketFactory getServerSocketFactory()

setPort

public static void setPort(int port)
Set port number on which RMIServer objects are exported.

Parameters:
port - the port number (0 = anonymous port)

getPort

public static int getPort()
Get port number on which RMIServer objects are exported.

Returns:
port the port number (0 = anonymous port)

getStub

public RemoteStub getStub()
Get remote stub from exporting of this server object.

Returns:
stub returned from exportObject during construction

readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
Re-export the remote object when it is deserialized.

Throws:
IOException
ClassNotFoundException

clone

public Object clone()
             throws CloneNotSupportedException
Returns a clone of the remote object that is distinct from the original.

Returns:
the new remote object
Throws:
CloneNotSupportedException - if clone failed due to a RemoteException.

reexport

private void reexport()
               throws RemoteException
Throws:
RemoteException

exportObject

public static RemoteStub exportObject(Remote obj)
                               throws RemoteException
Export the remote object to make it available to receive incoming calls.

Parameters:
obj - the remote object to be exported
Throws:
RemoteException - if export fails

exportObject

public static RemoteStub exportObject(Remote obj,
                                      String hostname,
                                      int oid)
                               throws RemoteException
Export the remote object to make it available to receive incoming calls.

Parameters:
obj - the remote object to be exported
hostname - the host name to include in remote stubs for this object (null = default)
Throws:
RemoteException - if export fails

exportObject

public static RemoteStub exportObject(Remote obj,
                                      String hostname,
                                      int oid,
                                      RMIClientSocketFactory csf,
                                      RMIServerSocketFactory ssf)
                               throws RemoteException
Export the remote object to make it available to receive incoming calls.

Parameters:
obj - the remote object to be exported
hostname - the host name to include in remote stubs for this object (null = default)
oid - the well known object identifier (0 = unique)
csf - the client-side socket factory for making calls to the remote object (null = default)
ssf - the server-side socket factory for receiving remote calls (null = default)
Throws:
RemoteException - if export fails
Since:
Windchill R6.0

getClassForName

private static Class getClassForName(String className,
                                     boolean failQuietly)

getMethod

private static Method getMethod(Class cls,
                                String methodName,
                                Class[] argTypes,
                                boolean failQuietly)

createProxy

private static RemoteStub createProxy(String remote_classname,
                                      Class stub_class,
                                      sun.rmi.transport.LiveRef live_ref)

writeReplace

public Object writeReplace()

isLocalHost

public static boolean isLocalHost(String host)
                           throws IOException
Utility method to check if a given host is the local host. The check includes resolved addresses as well as names. First the names and addresses of the default local host name are checked, then the names and addresses associated with the java.rmi.server.hostname property to allow servers to be configured using virtual IP addresses. Caller should cache result to avoid further name server lookups.

Parameters:
host - the host name to check
Returns:
true if the name corresponds to an address of the local host
Throws:
IOException

isHostInList

public static boolean isHostInList(String host,
                                   String list)
                            throws IOException
Utility method to check if a given host is in a list of host names. Check includes resolved addresses as well as names. Caller should cache result to avoid further name server lookups.

Parameters:
host - the host name to check
Returns:
true if the name corresponds to an address of one of the listed hosts
Throws:
IOException