public class RMIUtils extends java.lang.Object implements IRMIUtils
Modifier and Type | Field and Description |
---|---|
private ClassFileServer |
classFileServer
A class file server to enable remote dynamic class loading of the
ICompute object.
|
private java.util.function.Consumer<java.lang.String> |
errMsgStrategy
Strategy to display an error message.
|
private java.util.function.Consumer<java.lang.String> |
infoMsgStrategy
Strategy to display an informational message.
|
private java.lang.String |
last_addr
The last address selected for use.
|
private boolean |
privateAddrOnly
If true, then only detects private IP addresses.
|
Constructor and Description |
---|
RMIUtils(java.util.function.Consumer<java.lang.String> outputCmd)
Constructor for the class.
|
RMIUtils(java.util.function.Consumer<java.lang.String> outputCmd,
boolean privateAddrOnly)
Auxiliary constructor used to set the getLocalAddress() method to return non-private addresses,
e.g.
|
Modifier and Type | Method and Description |
---|---|
private void |
addPrivateAddr(java.lang.String hostAddress,
java.util.ArrayList<java.lang.String> addr_choices)
Adds the given host address to the addr_choices ArrayList if the host address is a private address, i.e.
|
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.
|
protected void |
showErrorMsg(java.lang.String msg)
Encapsulated behavior to show an error message
|
protected void |
showInfoMsg(java.lang.String msg)
Encapsulated behavior to show an informational message
|
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.
|
private boolean privateAddrOnly
private java.lang.String last_addr
private java.util.function.Consumer<java.lang.String> infoMsgStrategy
private java.util.function.Consumer<java.lang.String> errMsgStrategy
private ClassFileServer classFileServer
public RMIUtils(java.util.function.Consumer<java.lang.String> outputCmd)
outputCmd
- command used to output status and error informationjava.lang.IllegalArgumentException
- If the given outputCmd is null.public RMIUtils(java.util.function.Consumer<java.lang.String> outputCmd, boolean privateAddrOnly)
outputCmd
- command used to output status and error informationprivateAddrOnly
- If false, will look for non-private IP addresses as well.public java.rmi.registry.Registry getLocalRegistry()
getLocalRegistry
in interface IRMIUtils
public java.rmi.registry.Registry getRemoteRegistry(java.lang.String host)
getRemoteRegistry
in interface IRMIUtils
host
- the IP address or host name of the remote machine.java.lang.IllegalArgumentException
- if host is null or an empty string.public java.lang.String getLocalAddress() throws java.net.SocketException, java.net.UnknownHostException
getLocalAddress
in interface IRMIUtils
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.private void addPrivateAddr(java.lang.String hostAddress, java.util.ArrayList<java.lang.String> addr_choices)
hostAddress
- The host address to check and possibly addaddr_choices
- The ArrayList to add the host address to if it is a private addresspublic void startRMI(int classServerPort)
private void configRMIProperties(int classServerPort)
classServerPort
- The port the class server will use.private void configSecurityManager()
private void startClassFileServer(int classServerPort)
classServerPort
- the port the class file server will use.private void stopClassFileServer()
public void stopRMI()
protected void showInfoMsg(java.lang.String msg)
msg
- Message to show.protected void showErrorMsg(java.lang.String msg)
msg
- Message to show.