Package zephyr.common
Class ZephyrRpcConnection
java.lang.Object
zephyr.common.ZephyrRpcConnection
Maintains a connection and sends requests to a Zephyr RPC API.
TODO: refactor ZephyrRpcConnection extends ZephyrConnection?
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionZephyrRpcConnection(String uri, String username, String password) ZephyrRpcConnection(String uri, String username, String password, String zmqUri) ZephyrRpcConnection(URI uri) ZephyrRpcConnection(URI uri, String username, String password) ZephyrRpcConnection(URI uri, String username, String password, URI zmqUri) ZephyrRpcConnection(ZephyrRpcConnection connection) -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckConnection(long timeoutInMs) Check the connection to update online, authentication, and response time status.booleangetAttribute(String key) intGet the response time of the last call to checkConnection().
Note: must call checkConnection() manually unless using ZephyrConnectionManager.getUri()inthashCode()Indicates if the connection is authenticated according to the last call to checkConnection().
Note: must call checkConnection() manually unless using ZephyrConnectionManager.Indicates if the connection is connected according to the last call to checkConnection().
Note: must call checkConnection() manually unless using ZephyrConnectionManager.booleanisOnion()isOnline()Indicates if the connection is online according to the last call to checkConnection().
Note: must call checkConnection() manually unless using ZephyrConnectionManager.byte[]sendBinaryRequest(String path, Map<String, Object> params) Send a binary RPC request.byte[]Send a binary RPC request.sendJsonRequest(String method) Send a request to the RPC API.sendJsonRequest(String method, Object params) Send a request to the RPC API.sendJsonRequest(String method, Object params, Long timeoutInMs) Send a request to the RPC API.sendPathRequest(String path) Send a RPC request to the given path and with the given paramters.sendPathRequest(String path, Map<String, Object> params) Send a RPC request to the given path and with the given paramters.Send a RPC request to the given path and with the given paramters.setAttribute(String key, Object value) setCredentials(String username, String password) voidsetPrintStackTrace(boolean printStackTrace) Enable or disable printing a stack trace on each request for debug.setPriority(int priority) Set the connection's priority relative to other connections.setProxyUri(String proxyUri) toString()
-
Field Details
-
MAPPER
public static com.fasterxml.jackson.databind.ObjectMapper MAPPER
-
-
Constructor Details
-
ZephyrRpcConnection
-
ZephyrRpcConnection
-
ZephyrRpcConnection
-
ZephyrRpcConnection
-
ZephyrRpcConnection
-
ZephyrRpcConnection
-
ZephyrRpcConnection
-
-
Method Details
-
getUri
-
setUri
-
setUri
-
isOnion
public boolean isOnion() -
setCredentials
-
getUsername
-
getPassword
-
getZmqUri
-
setZmqUri
-
getPriority
public int getPriority() -
setProxyUri
-
getProxyUri
-
setPriority
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
-
getAttribute
-
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
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
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
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
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
Send a request to the RPC API.- Parameters:
method- specifies the method to request- Returns:
- the RPC API response as a map
-
sendJsonRequest
Send a request to the RPC API.- Parameters:
method- is the method to requestparams- are the request's input parameters (supports <Map<String, Object>, List<Object></code>, String, etc)- Returns:
- the RPC API response as a map
-
sendJsonRequest
Send a request to the RPC API.- Parameters:
method- is the method to requestparams- 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
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
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 invokeparams- are request parameters sent in the body- Returns:
- the request's deserialized response
-
sendPathRequest
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 invokeparams- are request parameters sent in the bodytimeoutInMs- is the request timeout in milliseconds- Returns:
- the request's deserialized response
-
sendBinaryRequest
Send a binary RPC request.- Parameters:
path- is the path of the binary RPC method to invokeparams- are the request parameters- Returns:
- byte[] is the binary response
-
sendBinaryRequest
Send a binary RPC request.- Parameters:
path- is the path of the binary RPC method to invokeparams- are the request parameterstimeoutInMs- 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
-
hashCode
public int hashCode() -
equals
-