java.lang.Object
org.newsclub.net.unix.rmi.AFNaming
- Direct Known Subclasses:
AFUNIXNaming
The
AFSocket
-compatible equivalent of Naming
. Use this class for accessing RMI
registries that are reachable by AFSocket
s.- Author:
- Christian Kohlschütter
-
Constructor Summary
ModifierConstructorDescriptionprotected
AFNaming
(int registryPort, int servicePort) Creates a new naming instance with the given ports. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Convenience method forgetRegistry().bind
.Creates a new RMIRegistry
.void
exportAndBind
(String name, Remote obj) Exports and binds the given Remote object to the given name, using the givenAFNaming
setup.void
exportAndRebind
(String name, Remote obj) Exports and re-binds the given Remote object to the given name, using the givenAFNaming
setup.static Remote
exportObject
(Remote obj, RMISocketFactory socketFactory) Exports the given Remote object, using the given socket factory and a randomly assigned port.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.final int
Returns the registry port.Returns theAFRMISocketFactory
associated with this instance.protected abstract void
Called bycreateRegistry()
right before creating/setting the registry.protected abstract AFRMISocketFactory
Creates or returns theAFRMISocketFactory
to be used with this instance.boolean
Checks if thisAFNaming
instance can be shut down remotely.String[]
list()
Convenience method forgetRegistry().list
.Convenience method forgetRegistry().lookup
.Convenience method forgetRegistry().lookup
.protected abstract AFRegistry
newAFRegistry
(Registry impl) Creates a newAFRegistry
given aRegistry
implementation.protected abstract AFRegistry
openRegistry
(long timeout, TimeUnit unit) Tries to access the registry, waiting some time if necessary.void
Convenience method forgetRegistry().rebind
.void
setRemoteShutdownAllowed
(boolean remoteShutdownAllowed) Controls whether thisAFNaming
instance can be shut down remotely.void
Shuts this RMI Registry down.protected abstract void
Called byshutdownRegistry()
as the final step.void
Convenience method forgetRegistry().unbind
.void
unexportAndUnbind
(String name, Remote obj) Forcibly un-exports the given object, if it exists, and unbinds the object from the registry (otherwise returns without an error).static void
unexportObject
(Remote obj) Forcibly un-exports the given object, if it exists (otherwise returns without an error).
-
Constructor Details
-
AFNaming
protected AFNaming(int registryPort, int servicePort) Creates a new naming instance with the given ports.- Parameters:
registryPort
- The registry port.servicePort
- The port for AFRMIService.
-
-
Method Details
-
newAFRegistry
Creates a newAFRegistry
given aRegistry
implementation.- Parameters:
impl
- The implementation.- Returns:
- The new
AFRegistry
instance. - Throws:
RemoteException
- on error.
-
initSocketFactory
Creates or returns theAFRMISocketFactory
to be used with this instance.- Returns:
- The socket factory.
- Throws:
IOException
- on error.
-
getSocketFactory
Returns theAFRMISocketFactory
associated with this instance.- Returns:
- The
AFRMISocketFactory
.
-
getRegistryPort
public final int getRegistryPort()Returns the registry port.- Returns:
- The port.
-
getRegistry
Returns a reference to the existing RMI registry. If there's no registry running at this port, an exception is thrown.- Returns:
- The registry.
- Throws:
RemoteException
- If there was a problem.
-
getRegistry
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.- Parameters:
timeout
- The timeout value.unit
- The timeout unit.- Returns:
- The registry.
- Throws:
RemoteException
- If there was a problem.
-
openRegistry
Tries to access the registry, waiting some time if necessary.- Parameters:
timeout
- The timeout.unit
- The unit for the timeout.- Returns:
- The registry instance.
- Throws:
RemoteException
- on error.
-
getRegistry
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.- Parameters:
create
-true
if a new register may be created if necessary.- Returns:
- The registry, or
null
- Throws:
RemoteException
- If there was a problem.
-
shutdownRegistry
Shuts this RMI Registry down.- Throws:
RemoteException
- if the operation fails.
-
shutdownRegistryFinishingTouches
protected abstract void shutdownRegistryFinishingTouches()Called byshutdownRegistry()
as the final step. -
createRegistry
Creates a new RMIRegistry
. If there already was a registry created previously, it is shut down and replaced by the current one. UsegetRegistry()
to try to reuse an existing registry.- Returns:
- The registry
- Throws:
RemoteException
- if the operation fails.- See Also:
-
initRegistryPrerequisites
Called bycreateRegistry()
right before creating/setting the registry.- Throws:
ServerException
- on error.
-
isRemoteShutdownAllowed
public boolean isRemoteShutdownAllowed()Checks if thisAFNaming
instance can be shut down remotely.- Returns:
true
if remote shutdown is allowed.
-
setRemoteShutdownAllowed
public void setRemoteShutdownAllowed(boolean remoteShutdownAllowed) Controls whether thisAFNaming
instance can be shut down remotely.- Parameters:
remoteShutdownAllowed
-true
if remote shutdown is allowed.
-
exportAndBind
Exports and binds the given Remote object to the given name, using the givenAFNaming
setup.- Parameters:
name
- The name to use to bind the object in the registry.obj
- The object to export and bind.- Throws:
RemoteException
- if the operation fails.AlreadyBoundException
- if there already was something bound at that name
-
exportAndRebind
Exports and re-binds the given Remote object to the given name, using the givenAFNaming
setup.- Parameters:
name
- The name to use to bind the object in the registry.obj
- The object to export and bind.- Throws:
RemoteException
- if the operation fails.
-
unexportAndUnbind
Forcibly un-exports the given object, if it exists, and unbinds the object from the registry (otherwise returns without an error).- Parameters:
name
- The name used to bind the object.obj
- The object to un-export.- Throws:
RemoteException
- if the operation fails.
-
exportObject
public static Remote exportObject(Remote obj, RMISocketFactory socketFactory) throws RemoteException Exports the given Remote object, using the given socket factory and a randomly assigned port. NOTE: This helper function can also be used for regular RMI servers.- Parameters:
obj
- The object to export.socketFactory
- The socket factory to use.- Returns:
- The remote stub.
- Throws:
RemoteException
- if the operation fails.
-
unexportObject
-
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
-