provided.rmiUtils
Class RMIUtils

java.lang.Object
  extended by provided.rmiUtils.RMIUtils
All Implemented Interfaces:
IRMIUtils

public class RMIUtils
extends java.lang.Object
implements IRMIUtils

Utilities to make it easier to get a hold of the Registry

Author:
swong

Field Summary
private  ClassFileServer classFileServer
          A class file server to enable remote dynamic class loading of the ICompute object.
private  IVoidLambda<java.lang.String> outputCmd
          Command used to output strings to one or more destinations.
 
Constructor Summary
RMIUtils(IVoidLambda<java.lang.String> outputCmd)
          Constructor for the class.
 
Method Summary
private  void configRMIProperties(int classServerPort)
          Sets the java.rmi.server.hostname and java.rmi.server.codebase system properties which control the automatic remote dynamic class loading.
private  void configSecurityManager()
          Sets the java.security.policy system property to point at the location of the security policy file, which is assumed to be at "provided\rmiUtils\server.policy" (file separators adjusted to match operating system).
 java.lang.String getLocalAddress()
          This method is designed to reliably return the actual local IP address across multiple platforms, particularly Linux.
 java.rmi.registry.Registry getLocalRegistry()
          Returns the Registry on the local machine on port IRMI_Defs.REGISTRY_PORT, as a server would require.
 java.rmi.registry.Registry getRemoteRegistry(java.lang.String host)
          Returns the Registry on the given machine on port IRMI_Defs.REGISTRY_PORT, as a client would require.
private  void startClassFileServer(int classServerPort)
          Start the class file server to support remote dynamic class loading.
 void startRMI(int classServerPort)
          Start up the RMI system.
private  void stopClassFileServer()
          Stop the class file server and reset the reference to it, "classFileServer", to null.
 void stopRMI()
          Performs all necessary work to shut the RMI system down, such as shut the class server down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outputCmd

private IVoidLambda<java.lang.String> outputCmd
Command used to output strings to one or more destinations. By default, output goes to standard error.


classFileServer

private ClassFileServer classFileServer
A class file server to enable remote dynamic class loading of the ICompute object.

Constructor Detail

RMIUtils

public RMIUtils(IVoidLambda<java.lang.String> outputCmd)
Constructor for the class. Combines the given output command with the default command to send status info to both the view connected to by the input outputCmd as well as standard error.

Parameters:
outputCmd - command used to output status and error information
Method Detail

getLocalRegistry

public java.rmi.registry.Registry getLocalRegistry()
Returns the Registry on the local machine on port IRMI_Defs.REGISTRY_PORT, as a server would require. Creates the Registry if it isn't already running. Returns null system if unable to create a Registry if needed.

Specified by:
getLocalRegistry in interface IRMIUtils
Returns:
the Registry or null if no Registry could be made or found.

getRemoteRegistry

public java.rmi.registry.Registry getRemoteRegistry(java.lang.String host)
Returns the Registry on the given machine on port IRMI_Defs.REGISTRY_PORT, as a client would require.

Specified by:
getRemoteRegistry in interface IRMIUtils
Parameters:
host - the IP address or host name of the remote machine.
Returns:
The remote Registry or null if it could not be located.

getLocalAddress

public java.lang.String getLocalAddress()
                                 throws java.net.SocketException,
                                        java.net.UnknownHostException
This method is designed to reliably return the actual local IP address across multiple platforms, particularly Linux. This method is a replacement for "java.net.InetAddress.getLocalHost().getHostAddress()" which will return the loopback address in Linux, not the actual IP address. This method only returns IPv4 addresses, not IPv6 addresses. It returns the first valid address found.

Specified by:
getLocalAddress in interface IRMIUtils
Returns:
The first IPv4 address found for the system that is not a loopback address.
Throws:
java.net.SocketException - thrown when there is a problem retrieving the network interfaces.
java.net.UnknownHostException - thrown when the local host address cannot be found.

startRMI

public void startRMI(int classServerPort)
Start up the RMI system. This method should be called before any other activity with that involves RMI. This method configures the system properties RMI needs, starts the security manager and starts the class server.
Typical classServerPort values are:
IRMI_Defs.CLASS_SERVER_PORT_SERVER and
IRMI_Defs.CLASS_SERVER_PORT_CLIENT

Specified by:
startRMI in interface IRMIUtils
Parameters:
classServerPort - the port that the class server will use

configRMIProperties

private void configRMIProperties(int classServerPort)
Sets the java.rmi.server.hostname and java.rmi.server.codebase system properties which control the automatic remote dynamic class loading. This must be called before starting the class server.

Parameters:
classServerPort - The port the class server will use.

configSecurityManager

private void configSecurityManager()
Sets the java.security.policy system property to point at the location of the security policy file, which is assumed to be at "provided\rmiUtils\server.policy" (file separators adjusted to match operating system). the security manager is then started. This method must be called before starting the class server.


startClassFileServer

private void startClassFileServer(int classServerPort)
Start the class file server to support remote dynamic class loading. This method must be called after configSecurityManager() and configRMIProperties(). If the reference to the class file server, "classFileServer" is null, it is assumed that the class file server is not runnng.

Parameters:
classServerPort - the port the class file server will use.

stopClassFileServer

private void stopClassFileServer()
Stop the class file server and reset the reference to it, "classFileServer", to null.


stopRMI

public void stopRMI()
Performs all necessary work to shut the RMI system down, such as shut the class server down. This method MUST be called before exiting the system or phantom processes may persist.

Specified by:
stopRMI in interface IRMIUtils