Class MoeraNaming

java.lang.Object
org.moera.lib.jsonrpc.JsonRpcClient
org.moera.lib.naming.MoeraNaming
All Implemented Interfaces:
NamingApi

public class MoeraNaming extends JsonRpcClient implements NamingApi
MoeraNaming is a client for interfacing with the Moera Naming Service. It extends JsonRpcClient to perform JSON-RPC based calls to the naming service, and implements NamingApi to provide specific operations related to name resolution and management.
  • Field Details

    • MAIN_NAMING_SERVER

      public static final String MAIN_NAMING_SERVER
      The default URL of the main Moera naming server used for resolving and interacting with names in the Moera Naming system. This constant represents the primary endpoint for the naming server, which is used when no alternative server URL is specified.
      See Also:
    • DEV_NAMING_SERVER

      public static final String DEV_NAMING_SERVER
      The URL of the development naming server. This server is used for testing and development purposes.
      See Also:
  • Constructor Details

    • MoeraNaming

      public MoeraNaming()
      Constructs a new instance of the MoeraNaming class using the default naming server (MAIN_NAMING_SERVER).
    • MoeraNaming

      public MoeraNaming(String server)
      Constructs a new instance of the MoeraNaming class and initializes it with the specified naming server.
      Parameters:
      server - the URL of the naming server to be used. It must be a valid HTTP or HTTPS URL.
    • MoeraNaming

      public MoeraNaming(Function<JsonRpcRequest,JsonRpcResponse> fetcher)
      Constructs a new instance of the MoeraNaming class using the provided fetcher function.
      Parameters:
      fetcher - a Function that takes a JsonRpcRequest as input and returns a corresponding JsonRpcResponse as output. This function is responsible for handling the communication with the naming server.
  • Method Details

    • resolve

      public static String resolve(String name)
      Resolves the specified name using the default naming server.
      Parameters:
      name - the name to be resolved. It should be a valid Moera node name.
      Returns:
      the resolved node URI if the specified name exists, or null if no record is found.
    • resolve

      public static String resolve(String name, String namingServer)
      Resolves the given name using the specified naming server.
      Parameters:
      name - the name to be resolved. It should be a valid Moera node name.
      namingServer - the URL of the naming server to be used for name resolution
      Returns:
      the node URI associated with the resolved name if it exists, or null if no record is found.
    • fetch

      protected <T> T fetch(Class<T> result, String method, Object... parameters)
      Description copied from class: JsonRpcClient
      Performs a JSON-RPC call to invoke a method on a remote server. Constructs a JSON-RPC request, sends it using the pre-configured fetcher, and processes the response. If the response contains an error, it throws a JsonRpcApiException. If the response is successful, the result is converted to the specified type and returned.
      Overrides:
      fetch in class JsonRpcClient
      Type Parameters:
      T - the type of the result object expected from the remote method
      Parameters:
      result - the class type of the result object. If the expected result is null or the remote method does not return a value, the method will return null.
      method - the name of the remote method to invoke
      parameters - the parameters to pass to the remote method
      Returns:
      the result of the remote method call, converted to the specified type, or null if the remote method does not return a value
    • put

      public UUID put(String name, int generation, byte[] updatingKey, String nodeUri, byte[] signingKey, Long validFrom, byte[] previousDigest, byte[] signature)
      Description copied from interface: NamingApi
      Registers or updates the given name in the Moera Naming Service. See Architecture Overview for the detailed description of the algorithm.
      Specified by:
      put in interface NamingApi
      Parameters:
      name - the name to be registered or updated. Required.
      generation - the generation of the name. Required.
      updatingKey - the public key for verifying signatures of further updates of the name. May be null – the current key is preserved in this case.
      nodeUri - URI of the REST API endpoint of the node to which the name is assigned. May be null – the current URI is preserved in this case.
      signingKey - the public signing key of the name owner. May be null – the current key is preserved in this case.
      validFrom - the moment in time (in epoch seconds) the owner's key is valid from. May be null, if signingKey is also null.
      previousDigest - the unique identifier as reported by a naming server of the current state of the name. Used to detect the situations when the name was changed by someone else between sending the request and processing it. May be null, if the name was never registered before.
      signature - the signature, if required, null otherwise.
      Returns:
      the unique operation ID, which can be used to track the status of the operation
    • getStatus

      public OperationStatusInfo getStatus(UUID operationId)
      Description copied from interface: NamingApi
      Retrieves the status of the operation based on the provided operation ID.
      Specified by:
      getStatus in interface NamingApi
      Parameters:
      operationId - the unique identifier of the operation
      Returns:
      an OperationStatusInfo object containing details about the operation's status, or null if the operation ID is unknown
    • getCurrent

      public RegisteredNameInfo getCurrent(String name, int generation)
      Description copied from interface: NamingApi
      Retrieves the current state of a registered name based on the specified name and generation.
      Specified by:
      getCurrent in interface NamingApi
      Parameters:
      name - the name for which the current state is to be retrieved
      generation - the generation of the name for which the current state is required
      Returns:
      a RegisteredNameInfo object containing the current state information of the registered name, or null if the name with the specified generation is not found.
    • getPast

      public RegisteredNameInfo getPast(String name, int generation, long at)
      Description copied from interface: NamingApi
      Retrieves historical information about a registered name at a specific point in time.
      Specified by:
      getPast in interface NamingApi
      Parameters:
      name - the name to retrieve information for
      generation - the generation of the name to retrieve information for
      at - the specific timestamp (in epoch seconds) for which the historical information is requested
      Returns:
      a RegisteredNameInfo object containing details about the registered name at the specified time, or null if no matching information is found.
    • isFree

      public boolean isFree(String name, int generation)
      Description copied from interface: NamingApi
      Checks whether a given name is free for registration in the naming service.
      Specified by:
      isFree in interface NamingApi
      Parameters:
      name - the name to be checked for availability
      generation - the generation of the name to check
      Returns:
      true if the name is free for the specified generation, false otherwise
    • getAllKeys

      public List<SigningKeyInfo> getAllKeys(String name, int generation)
      Description copied from interface: NamingApi
      Retrieves all signing keys associated with the specified name and generation.
      Specified by:
      getAllKeys in interface NamingApi
      Parameters:
      name - the name for which the signing keys are to be retrieved
      generation - the generation of the name
      Returns:
      a list of SigningKeyInfo objects containing signing keys and their validity periods
    • getSimilar

      public RegisteredNameInfo getSimilar(String name)
      Description copied from interface: NamingApi
      Retrieves a RegisteredNameInfo object that represents a name similar to the specified name. This may be useful for obtaining details of a name that closely resembles the one provided.
      Specified by:
      getSimilar in interface NamingApi
      Parameters:
      name - the name to search for a similar registered name
      Returns:
      an instance of RegisteredNameInfo containing details of a similar registered name, or null if no similar name is found.
    • getAll

      public List<RegisteredNameInfo> getAll(long at, int page, int size)
      Description copied from interface: NamingApi
      Retrieves a paginated list of all registered names up to a specific moment in time.
      Specified by:
      getAll in interface NamingApi
      Parameters:
      at - the timestamp (in epoch seconds) up to which the registered names are returned
      page - the page number of the results (starting from 0)
      size - the number of entries per page
      Returns:
      a list of RegisteredNameInfo containing details of the registered names
    • getAllNewer

      public List<RegisteredNameInfo> getAllNewer(long at, int page, int size)
      Description copied from interface: NamingApi
      Retrieves a list of registered names that were created or updated after the specified timestamp. The results are paginated based on the provided page number and size.
      Specified by:
      getAllNewer in interface NamingApi
      Parameters:
      at - the timestamp (in epoch seconds) to filter names that are newer
      page - the page number of the results (starting from 0)
      size - the number of entries per page
      Returns:
      a list of RegisteredNameInfo objects representing the names that match the criteria, or an empty list if no such names exist