Package org.djutils.rmi
Class RmiRegistry
java.lang.Object
org.djutils.rmi.RmiRegistry
RMIUtils contains a number of utilities to help with the RMI registry.
Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Bind an object in the RMI registry.static void
closeRegistry
(Registry registry) Unbinds all the objects from the RMI registry and closes the registry.static Registry
getRegistry
(String host, int port) Lookup or create the RMI registry.static Remote
Lookup an object in the RMI registry.static void
Rebind an object to an existing string in the RMI registry.static void
Unbind an object from the RMI registry.
-
Method Details
-
getRegistry
Lookup or create the RMI registry. When the RMI registry does not exist yet, it will be created, but only on the local host. Remote creation of a registry on another computer is not possible. Any attempt to do so will cause an AccessException to be fired.- Parameters:
host
- String; the host where the RMI registry resides or will be created. Creation is only possible on localhost.port
- int; the port where the RMI registry can be found or will be created- Returns:
- Registry; the located or created RMI registry
- Throws:
RemoteException
- when there is a problem with locating or creating the RMI registryNullPointerException
- when host is nullIllegalArgumentException
- when port ≤ 0 or port > 65535AccessException
- when there is an attempt to create a registry on a remote host
-
bind
public static void bind(Registry registry, String bindingKey, Remote object) throws RemoteException, AlreadyBoundException Bind an object in the RMI registry.- Parameters:
registry
- Registry; the RMI registry where the object will be bound using the keybindingKey
- String; the key under which the object will be bound in the RMI registryobject
- Remote; the object that will be bound- Throws:
RemoteException
- when there is a problem with the RMI registryAlreadyBoundException
- when there is already another object bound to the bindingKeyNullPointerException
- when registry, bindingKey or object is nullIllegalArgumentException
- when bindingKey is the empty String
-
unbind
public static void unbind(Registry registry, String bindingKey) throws RemoteException, NotBoundException Unbind an object from the RMI registry.- Parameters:
registry
- Registry; the RMI registry where the object will be bound using the keybindingKey
- String; the key under which the object will be bound in the RMI registry- Throws:
RemoteException
- when there is a problem with the RMI registryNotBoundException
- when there is no object bound to the bindingKeyNullPointerException
- when registry or bindingKey is nullIllegalArgumentException
- when bindingKey is the empty String
-
rebind
public static void rebind(Registry registry, String bindingKey, Remote newObject) throws RemoteException Rebind an object to an existing string in the RMI registry.- Parameters:
registry
- Registry; the RMI registry where the object will be bound using the keybindingKey
- String; the (existing) key under which the new object will be bound in the RMI registrynewObject
- Remote; the new object that will be bound- Throws:
RemoteException
- when there is a problem with the RMI registryNullPointerException
- when registry, bindingKey or newObject is nullIllegalArgumentException
- when bindingKey is the empty String
-
lookup
public static Remote lookup(Registry registry, String bindingKey) throws RemoteException, NotBoundException Lookup an object in the RMI registry.- Parameters:
registry
- Registry; the RMI registry in which the object will be looked up using the keybindingKey
- String; the key under which the object should be registered in the RMI registry- Returns:
- Remote; the remote object that bound to the key in the RMI registry
- Throws:
RemoteException
- when there is a problem with the RMI registryNotBoundException
- when there is no object bound to the bindingKeyNullPointerException
- when registry or bindingKey is nullIllegalArgumentException
- when bindingKey is the empty String
-
closeRegistry
Unbinds all the objects from the RMI registry and closes the registry.- Parameters:
registry
- Registry; the RMI registry that will unbind all the objects and close.- Throws:
RemoteException
- when there is a problem with the RMI registryNullPointerException
- when registry is null
-