java.lang.Object
com.telenav.kivakit.configuration.lookup.Registry

public class Registry extends Object
The Registry class allows code to register and locate objects by class and instance (if there is more than one instance). The methods register(Object) and register(Object, Enum) are used to install an object in the lookup and lookup(Class) and lookup(Class, Enum) are used to find an object that has been registered.

Example

In this example, the initialize() method and the doit() method may be in different classes or packages. The doit() method can find the WEB instance of the Server class using lookup(Class, Enum)

 enum Servers { WEB, TRAFFIC, MAP }

 void initialize()
 {
     Registry.of(this).register(new Server(), WEB);
 }

     [...]

 void doit()
 {
     var server = Registry.of(this).lookup(Server.class, WEB);

         [...]
 }
 
  • Constructor Details

    • Registry

      public Registry()
  • Method Details

    • of

      public static Registry of(Object object)
      Returns:
      The lookup for the given object
    • lookup

      public <T> T lookup(Class<T> type)
      Returns:
      Any registered object of the given type
    • lookup

      public <T> T lookup(Class<T> type, String instance)
      Returns:
      Any registered object of the given type with the given instance identifier
    • lookup

      public <T> T lookup(Class<T> type, InstanceIdentifier instance)
      Returns:
      Any registered object of the given type with the given instance identifier
    • lookup

      public <T> T lookup(Class<T> type, Enum<?> instance)
      Returns:
      Any registered object of the given type with the given instance identifier
    • register

      public <T> T register(T object)
      Registers the given singleton object in the lookup
    • register

      public <T> T register(T object, String instance)
      Registers the specified instance of the given object's type in the lookup
    • register

      public <T> T register(T object, InstanceIdentifier instance)
      Registers the specified instance of the given object's type in the lookup
    • register

      public <T> T register(T object, Enum<?> instance)
      Registers the specified instance of the given object's type in the lookup