Package zephyr.common

Class ZephyrRpcConnection

java.lang.Object
zephyr.common.ZephyrRpcConnection

public class ZephyrRpcConnection extends Object
Maintains a connection and sends requests to a Zephyr RPC API. TODO: refactor ZephyrRpcConnection extends ZephyrConnection?
  • Field Details

    • MAPPER

      public static com.fasterxml.jackson.databind.ObjectMapper MAPPER
  • Constructor Details

    • ZephyrRpcConnection

      public ZephyrRpcConnection(URI uri)
    • ZephyrRpcConnection

      public ZephyrRpcConnection(String uri)
    • ZephyrRpcConnection

      public ZephyrRpcConnection(String uri, String username, String password)
    • ZephyrRpcConnection

      public ZephyrRpcConnection(String uri, String username, String password, String zmqUri)
    • ZephyrRpcConnection

      public ZephyrRpcConnection(URI uri, String username, String password)
    • ZephyrRpcConnection

      public ZephyrRpcConnection(URI uri, String username, String password, URI zmqUri)
    • ZephyrRpcConnection

      public ZephyrRpcConnection(ZephyrRpcConnection connection)
  • Method Details

    • getUri

      public String getUri()
    • setUri

      public ZephyrRpcConnection setUri(String uri)
    • setUri

      public ZephyrRpcConnection setUri(URI uri)
    • isOnion

      public boolean isOnion()
    • setCredentials

      public ZephyrRpcConnection setCredentials(String username, String password)
    • getUsername

      public String getUsername()
    • getPassword

      public String getPassword()
    • getZmqUri

      public String getZmqUri()
    • setZmqUri

      public ZephyrRpcConnection setZmqUri(String zmqUri)
    • getPriority

      public int getPriority()
    • setProxyUri

      public ZephyrRpcConnection setProxyUri(String proxyUri)
    • getProxyUri

      public String getProxyUri()
    • setPriority

      public ZephyrRpcConnection setPriority(int priority)
      Set the connection's priority relative to other connections. Priority 1 is highest, then priority 2, etc. The default priority of 0 is lowest priority.
      Parameters:
      priority - is the connection priority (default 0)
      Returns:
      this connection
    • setAttribute

      public ZephyrRpcConnection setAttribute(String key, Object value)
    • getAttribute

      public Object getAttribute(String key)
    • checkConnection

      public boolean checkConnection(long timeoutInMs)
      Check the connection to update online, authentication, and response time status.
      Parameters:
      timeoutInMs - the maximum response time before considered offline
      Returns:
      true if there is a change in status, false otherwise
    • isConnected

      public Boolean isConnected()
      Indicates if the connection is connected according to the last call to checkConnection().

      Note: must call checkConnection() manually unless using ZephyrConnectionManager.
      Returns:
      true or false to indicate if connected, or null if checkConnection() has not been called
    • isOnline

      public Boolean isOnline()
      Indicates if the connection is online according to the last call to checkConnection().

      Note: must call checkConnection() manually unless using ZephyrConnectionManager.
      Returns:
      true or false to indicate if online, or null if checkConnection() has not been called
    • isAuthenticated

      public Boolean isAuthenticated()
      Indicates if the connection is authenticated according to the last call to checkConnection().

      Note: must call checkConnection() manually unless using ZephyrConnectionManager.
      Returns:
      true if authenticated or no authentication, false if not authenticated, or null if checkConnection() has not been called
    • getResponseTime

      public Long getResponseTime()
      Get the response time of the last call to checkConnection().

      Note: must call checkConnection() manually unless using ZephyrConnectionManager.
      Returns:
      the response time of the last call to checkConnection() or null if checkConnection() has not been called
    • sendJsonRequest

      public Map<String,Object> sendJsonRequest(String method)
      Send a request to the RPC API.
      Parameters:
      method - specifies the method to request
      Returns:
      the RPC API response as a map
    • sendJsonRequest

      public Map<String,Object> sendJsonRequest(String method, Object params)
      Send a request to the RPC API.
      Parameters:
      method - is the method to request
      params - are the request's input parameters (supports <Map<String, Object>, List<Object></code>, String, etc)
      Returns:
      the RPC API response as a map
    • sendJsonRequest

      public Map<String,Object> sendJsonRequest(String method, Object params, Long timeoutInMs)
      Send a request to the RPC API.
      Parameters:
      method - is the method to request
      params - are the request's input parameters (supports <Map<String, Object>, List<Object></code>, String, etc)
      timeoutInMs - is the request timeout in milliseconds
      Returns:
      the RPC API response as a map
    • sendPathRequest

      public Map<String,Object> sendPathRequest(String path)
      Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params
      Parameters:
      path - is the url path of the request to invoke
      Returns:
      the request's deserialized response
    • sendPathRequest

      public Map<String,Object> sendPathRequest(String path, Map<String,Object> params)
      Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params
      Parameters:
      path - is the url path of the request to invoke
      params - are request parameters sent in the body
      Returns:
      the request's deserialized response
    • sendPathRequest

      public Map<String,Object> sendPathRequest(String path, Map<String,Object> params, Long timeoutInMs)
      Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params
      Parameters:
      path - is the url path of the request to invoke
      params - are request parameters sent in the body
      timeoutInMs - is the request timeout in milliseconds
      Returns:
      the request's deserialized response
    • sendBinaryRequest

      public byte[] sendBinaryRequest(String path, Map<String,Object> params)
      Send a binary RPC request.
      Parameters:
      path - is the path of the binary RPC method to invoke
      params - are the request parameters
      Returns:
      byte[] is the binary response
    • sendBinaryRequest

      public byte[] sendBinaryRequest(String path, Map<String,Object> params, Long timeoutInMs)
      Send a binary RPC request.
      Parameters:
      path - is the path of the binary RPC method to invoke
      params - are the request parameters
      timeoutInMs - is the request timeout in milliseconds
      Returns:
      byte[] is the binary response
    • setPrintStackTrace

      public void setPrintStackTrace(boolean printStackTrace)
      Enable or disable printing a stack trace on each request for debug.
      Parameters:
      printStackTrace - sets if the stack trace should be printed
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object