java.lang.Object
org.newsclub.net.unix.rmi.AFNaming
org.newsclub.net.unix.rmi.AFUNIXNaming
The
AFUNIXSocket
-compatible equivalent of Naming
. Use this class for accessing
RMI registries that are reachable by AFUNIXSocket
s.- Author:
- Christian Kohlschütter
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Convenience method forgetRegistry().bind
.Creates a new RMIRegistry
.static File
Returns the directory where RMI sockets are stored by default.static AFUNIXNaming
Returns the default instance ofAFUNIXNaming
.static AFUNIXNaming
getInstance
(File socketDir) Returns aAFUNIXNaming
instance which support several socket files that can be stored under the same, given directory.static AFUNIXNaming
getInstance
(File socketDir, int registryPort) Returns aAFUNIXNaming
instance which support several socket files that can be stored under the same, given directory.static AFUNIXNaming
getInstance
(File socketDir, int registryPort, String socketPrefix, String socketSuffix) Returns aAFUNIXNaming
instance which support several socket files that can be stored under the same, given directory.Returns a reference to the existing RMI registry.getRegistry
(boolean create) Returns a reference to the RMI registry, ornull
.getRegistry
(long timeout, TimeUnit unit) Returns a reference to the existing RMI registry.Returns the directory in which sockets used by this registry are located.Returns the socket file which is used to control the RMI registry.static AFNaming
getSingleFileInstance
(File socketFile) Returns anAFUNIXNaming
instance which only supports one file.Returns theAFRMISocketFactory
associated with this instance.protected void
Called byAFNaming.createRegistry()
right before creating/setting the registry.protected AFUNIXRMISocketFactory
Creates or returns theAFRMISocketFactory
to be used with this instance.String[]
list()
Convenience method forgetRegistry().list
.Convenience method forgetRegistry().lookup
.Convenience method forgetRegistry().lookup
.protected AFUNIXRegistry
newAFRegistry
(Registry impl) Creates a newAFRegistry
given aRegistry
implementation.static AFUNIXNaming
Returns a new private instance that resides in a custom location, to avoid any collisions with existing instances.protected AFRegistry
openRegistry
(long timeout, TimeUnit unit) Tries to access the registry, waiting some time if necessary.void
Convenience method forgetRegistry().rebind
.protected void
Called byAFNaming.shutdownRegistry()
as the final step.void
Convenience method forgetRegistry().unbind
.Methods inherited from class org.newsclub.net.unix.rmi.AFNaming
exportAndBind, exportAndRebind, exportObject, getRegistryPort, isRemoteShutdownAllowed, setRemoteShutdownAllowed, shutdownRegistry, unexportAndUnbind, unexportObject
-
Method Details
-
getDefaultSocketDirectory
Returns the directory where RMI sockets are stored by default. You can configure this location by setting the System propertyorg.newsclub.net.unix.rmi.socketdir
upon start.- Returns:
- The directory.
-
newPrivateInstance
Returns a new private instance that resides in a custom location, to avoid any collisions with existing instances.- Returns:
- The private
AFNaming
instance. - Throws:
IOException
- if the operation fails.
-
getInstance
Returns the default instance ofAFUNIXNaming
. Sockets are stored injava.io.tmpdir
.- Returns:
- The default instance.
- Throws:
IOException
- if the operation fails.
-
getInstance
Returns aAFUNIXNaming
instance which support several socket files that can be stored under the same, given directory.- Parameters:
socketDir
- The directory to store sockets in.- Returns:
- The instance.
- Throws:
RemoteException
- if the operation fails.
-
getInstance
Returns aAFUNIXNaming
instance which support several socket files that can be stored under the same, given directory. A custom "registry port" can be specified. Typically, AF-UNIX specific ports should be above100000
.- Parameters:
socketDir
- The directory to store sockets in.registryPort
- The registry port. Should be above100000
.- Returns:
- The instance.
- Throws:
RemoteException
- if the operation fails.
-
getInstance
public static AFUNIXNaming getInstance(File socketDir, int registryPort, String socketPrefix, String socketSuffix) throws RemoteException Returns aAFUNIXNaming
instance which support several socket files that can be stored under the same, given directory. A custom "registry port" can be specified. Typically, AF-UNIX specific ports should be above100000
.- Parameters:
socketDir
- The directory to store sockets in.registryPort
- The registry port. Should be above100000
.socketPrefix
- A string to be inserted at the beginning of each socket filename, ornull
.socketSuffix
- A string to be added at the end of each socket filename, ornull
.- Returns:
- The instance.
- Throws:
RemoteException
- if the operation fails.
-
getSingleFileInstance
Returns anAFUNIXNaming
instance which only supports one file. (Probably only useful when you want/can access the exportedUnicastRemoteObject
directly)- Parameters:
socketFile
- The socket file.- Returns:
- The instance.
- Throws:
IOException
- if the operation fails.
-
getSocketFactory
Description copied from class:AFNaming
Returns theAFRMISocketFactory
associated with this instance.- Overrides:
getSocketFactory
in classAFNaming
- Returns:
- The
AFRMISocketFactory
.
-
getRegistry
Returns a reference to the existing RMI registry. If there's no registry running at this port, an exception is thrown.- Overrides:
getRegistry
in classAFNaming
- Returns:
- The registry.
- Throws:
RemoteException
- If there was a problem.
-
getRegistry
Description copied from class:AFNaming
Returns a reference to the existing RMI registry. If there's no registry running at this port after waiting for up to the given time, an exception is thrown.- Overrides:
getRegistry
in classAFNaming
- Parameters:
timeout
- The timeout value.unit
- The timeout unit.- Returns:
- The registry.
- Throws:
RemoteException
- If there was a problem.
-
getRegistry
Description copied from class:AFNaming
Returns a reference to the RMI registry, ornull
. If there's no registry running at this port, andcreate
is set totrue
, a new one is created; whencreate
is set tofalse
,null
is returned.- Overrides:
getRegistry
in classAFNaming
- Parameters:
create
-true
if a new register may be created if necessary.- Returns:
- The registry, or
null
- Throws:
RemoteException
- If there was a problem.
-
createRegistry
Description copied from class:AFNaming
Creates a new RMIRegistry
. If there already was a registry created previously, it is shut down and replaced by the current one. UseAFNaming.getRegistry()
to try to reuse an existing registry.- Overrides:
createRegistry
in classAFNaming
- Returns:
- The registry
- Throws:
RemoteException
- if the operation fails.- See Also:
-
getRegistrySocketFile
Returns the socket file which is used to control the RMI registry. The file is usually in the directory returned bygetRegistrySocketDir()
.- Returns:
- The directory.
-
initSocketFactory
Description copied from class:AFNaming
Creates or returns theAFRMISocketFactory
to be used with this instance.- Specified by:
initSocketFactory
in classAFNaming
- Returns:
- The socket factory.
- Throws:
IOException
- on error.
-
newAFRegistry
Description copied from class:AFNaming
Creates a newAFRegistry
given aRegistry
implementation.- Specified by:
newAFRegistry
in classAFNaming
- Parameters:
impl
- The implementation.- Returns:
- The new
AFRegistry
instance. - Throws:
RemoteException
- on error.
-
openRegistry
Description copied from class:AFNaming
Tries to access the registry, waiting some time if necessary.- Specified by:
openRegistry
in classAFNaming
- Parameters:
timeout
- The timeout.unit
- The unit for the timeout.- Returns:
- The registry instance.
- Throws:
RemoteException
- on error.
-
shutdownRegistryFinishingTouches
protected void shutdownRegistryFinishingTouches()Description copied from class:AFNaming
Called byAFNaming.shutdownRegistry()
as the final step.- Specified by:
shutdownRegistryFinishingTouches
in classAFNaming
-
getRegistrySocketDir
Returns the directory in which sockets used by this registry are located.- Returns:
- The directory.
-
initRegistryPrerequisites
Description copied from class:AFNaming
Called byAFNaming.createRegistry()
right before creating/setting the registry.- Specified by:
initRegistryPrerequisites
in classAFNaming
- Throws:
ServerException
- on error.
-
lookup
Convenience method forgetRegistry().lookup
.- Parameters:
name
- the name for the remote reference to look up- Returns:
- The instance
- Throws:
NotBoundException
- upon errorMalformedURLException
- upon errorRemoteException
- upon error- See Also:
-
lookup
public Remote lookup(String name, long timeout, TimeUnit unit) throws NotBoundException, MalformedURLException, RemoteException Convenience method forgetRegistry().lookup
.- Parameters:
name
- the name for the remote reference to look uptimeout
- The timeout value.unit
- The timeout unit.- Returns:
- The instance
- Throws:
NotBoundException
- upon errorMalformedURLException
- upon errorRemoteException
- upon error- See Also:
-
unbind
Convenience method forgetRegistry().unbind
.- Parameters:
name
- the name for the remote reference to unbind- Throws:
RemoteException
- upon errorNotBoundException
- upon errorMalformedURLException
- upon error- See Also:
-
bind
public void bind(String name, Remote obj) throws AlreadyBoundException, MalformedURLException, RemoteException Convenience method forgetRegistry().bind
.- Parameters:
name
- the name for the remote reference to bindobj
- the remote reference to bind- Throws:
RemoteException
- upon errorAlreadyBoundException
- upon errorMalformedURLException
- upon error- See Also:
-
rebind
Convenience method forgetRegistry().rebind
.- Parameters:
name
- the name for the remote reference to rebindobj
- the remote reference to rebind- Throws:
RemoteException
- upon errorMalformedURLException
- upon error- See Also:
-
list
Convenience method forgetRegistry().list
. UnlikeAFRegistry.list()
, in case the registry has been shut down already, an empty array is returned.- Returns:
- an array of the names bound in this registry
- Throws:
RemoteException
- upon errorAccessException
- upon error
-