Class RmiRegistry

java.lang.Object
org.djutils.rmi.RmiRegistry

public final class RmiRegistry extends Object
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 Details

    • getRegistry

      public static Registry getRegistry(String host, int port) throws RemoteException
      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 registry
      NullPointerException - when host is null
      IllegalArgumentException - when port ≤ 0 or port > 65535
      AccessException - 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 key
      bindingKey - String; the key under which the object will be bound in the RMI registry
      object - Remote; the object that will be bound
      Throws:
      RemoteException - when there is a problem with the RMI registry
      AlreadyBoundException - when there is already another object bound to the bindingKey
      NullPointerException - when registry, bindingKey or object is null
      IllegalArgumentException - 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 key
      bindingKey - String; the key under which the object will be bound in the RMI registry
      Throws:
      RemoteException - when there is a problem with the RMI registry
      NotBoundException - when there is no object bound to the bindingKey
      NullPointerException - when registry or bindingKey is null
      IllegalArgumentException - 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 key
      bindingKey - String; the (existing) key under which the new object will be bound in the RMI registry
      newObject - Remote; the new object that will be bound
      Throws:
      RemoteException - when there is a problem with the RMI registry
      NullPointerException - when registry, bindingKey or newObject is null
      IllegalArgumentException - 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 key
      bindingKey - 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 registry
      NotBoundException - when there is no object bound to the bindingKey
      NullPointerException - when registry or bindingKey is null
      IllegalArgumentException - when bindingKey is the empty String
    • closeRegistry

      public static void closeRegistry(Registry registry) throws RemoteException
      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 registry
      NullPointerException - when registry is null