Package org.moera.lib.naming
Class MoeraNaming
java.lang.Object
org.moera.lib.jsonrpc.JsonRpcClient
org.moera.lib.naming.MoeraNaming
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of theMoeraNaming
class using the default naming server (MAIN_NAMING_SERVER
).MoeraNaming
(String server) Constructs a new instance of theMoeraNaming
class and initializes it with the specified naming server.MoeraNaming
(Function<JsonRpcRequest, JsonRpcResponse> fetcher) Constructs a new instance of theMoeraNaming
class using the provided fetcher function. -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> T
Performs a JSON-RPC call to invoke a method on a remote server.getAll
(long at, int page, int size) Retrieves a paginated list of all registered names up to a specific moment in time.getAllKeys
(String name, int generation) Retrieves all signing keys associated with the specified name and generation.getAllNewer
(long at, int page, int size) Retrieves a list of registered names that were created or updated after the specified timestamp.getCurrent
(String name, int generation) Retrieves the current state of a registered name based on the specified name and generation.Retrieves historical information about a registered name at a specific point in time.getSimilar
(String name) Retrieves aRegisteredNameInfo
object that represents a name similar to the specified name.Retrieves the status of the operation based on the provided operation ID.boolean
Checks whether a given name is free for registration in the naming service.put
(String name, int generation, byte[] updatingKey, String nodeUri, byte[] signingKey, Long validFrom, byte[] previousDigest, byte[] signature) Registers or updates the given name in the Moera Naming Service.static String
Resolves the specified name using the default naming server.static String
Resolves the given name using the specified naming server.
-
Field Details
-
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
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 theMoeraNaming
class using the default naming server (MAIN_NAMING_SERVER
). -
MoeraNaming
Constructs a new instance of theMoeraNaming
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
Constructs a new instance of theMoeraNaming
class using the provided fetcher function.- Parameters:
fetcher
- aFunction
that takes aJsonRpcRequest
as input and returns a correspondingJsonRpcResponse
as output. This function is responsible for handling the communication with the naming server.
-
-
Method Details
-
resolve
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
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
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 aJsonRpcApiException
. If the response is successful, the result is converted to the specified type and returned.- Overrides:
fetch
in classJsonRpcClient
- 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 isnull
or the remote method does not return a value, the method will returnnull
.method
- the name of the remote method to invokeparameters
- 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 interfaceNamingApi
- 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 benull
– 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 benull
– the current URI is preserved in this case.signingKey
- the public signing key of the name owner. May benull
– the current key is preserved in this case.validFrom
- the moment in time (in epoch seconds) the owner's key is valid from. May benull
, ifsigningKey
is alsonull
.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 benull
, 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
Description copied from interface:NamingApi
Retrieves the status of the operation based on the provided operation ID.- Specified by:
getStatus
in interfaceNamingApi
- Parameters:
operationId
- the unique identifier of the operation- Returns:
- an
OperationStatusInfo
object containing details about the operation's status, ornull
if the operation ID is unknown
-
getCurrent
Description copied from interface:NamingApi
Retrieves the current state of a registered name based on the specified name and generation.- Specified by:
getCurrent
in interfaceNamingApi
- Parameters:
name
- the name for which the current state is to be retrievedgeneration
- 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, ornull
if the name with the specified generation is not found.
-
getPast
Description copied from interface:NamingApi
Retrieves historical information about a registered name at a specific point in time.- Specified by:
getPast
in interfaceNamingApi
- Parameters:
name
- the name to retrieve information forgeneration
- the generation of the name to retrieve information forat
- 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, ornull
if no matching information is found.
-
isFree
Description copied from interface:NamingApi
Checks whether a given name is free for registration in the naming service. -
getAllKeys
Description copied from interface:NamingApi
Retrieves all signing keys associated with the specified name and generation.- Specified by:
getAllKeys
in interfaceNamingApi
- Parameters:
name
- the name for which the signing keys are to be retrievedgeneration
- the generation of the name- Returns:
- a list of
SigningKeyInfo
objects containing signing keys and their validity periods
-
getSimilar
Description copied from interface:NamingApi
Retrieves aRegisteredNameInfo
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 interfaceNamingApi
- Parameters:
name
- the name to search for a similar registered name- Returns:
- an instance of
RegisteredNameInfo
containing details of a similar registered name, ornull
if no similar name is found.
-
getAll
Description copied from interface:NamingApi
Retrieves a paginated list of all registered names up to a specific moment in time.- Specified by:
getAll
in interfaceNamingApi
- Parameters:
at
- the timestamp (in epoch seconds) up to which the registered names are returnedpage
- 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
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 interfaceNamingApi
- Parameters:
at
- the timestamp (in epoch seconds) to filter names that are newerpage
- 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
-