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 AFSockets.- Author:
- Christian Kohlschütter
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAFNaming(int registryPort, int servicePort) Creates a new naming instance with the given ports. -
Method Summary
Modifier and TypeMethodDescriptionvoidConvenience method forgetRegistry().bind.Creates a new RMIRegistry.voidexportAndBind(String name, Remote obj) Exports and binds the given Remote object to the given name, using the givenAFNamingsetup.voidexportAndRebind(String name, Remote obj) Exports and re-binds the given Remote object to the given name, using the givenAFNamingsetup.static RemoteexportObject(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 intReturns the registry port.Returns theAFRMISocketFactoryassociated with this instance.protected abstract voidCalled bycreateRegistry()right before creating/setting the registry.protected abstract AFRMISocketFactoryCreates or returns theAFRMISocketFactoryto be used with this instance.booleanChecks if thisAFNaminginstance can be shut down remotely.String[]list()Convenience method forgetRegistry().list.Convenience method forgetRegistry().lookup.Convenience method forgetRegistry().lookup.protected abstract AFRegistrynewAFRegistry(Registry impl) Creates a newAFRegistrygiven aRegistryimplementation.protected abstract AFRegistryopenRegistry(long timeout, TimeUnit unit) Tries to access the registry, waiting some time if necessary.voidConvenience method forgetRegistry().rebind.voidsetRemoteShutdownAllowed(boolean remoteShutdownAllowed) Controls whether thisAFNaminginstance can be shut down remotely.voidShuts this RMI Registry down.protected abstract voidCalled byshutdownRegistry()as the final step.voidConvenience method forgetRegistry().unbind.voidunexportAndUnbind(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 voidunexportObject(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 newAFRegistrygiven aRegistryimplementation.- Parameters:
impl- The implementation.- Returns:
- The new
AFRegistryinstance. - Throws:
RemoteException- on error.
-
initSocketFactory
Creates or returns theAFRMISocketFactoryto be used with this instance.- Returns:
- The socket factory.
- Throws:
IOException- on error.
-
getSocketFactory
Returns theAFRMISocketFactoryassociated 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, andcreateis set totrue, a new one is created; whencreateis set tofalse,nullis returned.- Parameters:
create-trueif 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 thisAFNaminginstance can be shut down remotely.- Returns:
trueif remote shutdown is allowed.
-
setRemoteShutdownAllowed
public void setRemoteShutdownAllowed(boolean remoteShutdownAllowed) Controls whether thisAFNaminginstance can be shut down remotely.- Parameters:
remoteShutdownAllowed-trueif remote shutdown is allowed.
-
exportAndBind
Exports and binds the given Remote object to the given name, using the givenAFNamingsetup.- 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 givenAFNamingsetup.- 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
-