public class JsonRpcClient extends RpcClient implements java.lang.reflect.InvocationHandler
JsonRpcClient
class.
JSON-RPC services are self-describing - each service is able
to list its supported procedures, and each procedure
describes its parameters and types. An instance of
JsonRpcClient retrieves its service description using the
standard system.describe
procedure when it is
constructed, and uses the information to coerce parameter
types appropriately. A JSON service description is parsed
into instances of ServiceDescription
. Client
code can access the service description by reading the
serviceDescription
field of
JsonRpcClient
instances.call(String, Object[])
,
call(String[])
NO_TIMEOUT
Constructor and Description |
---|
JsonRpcClient(Channel channel,
java.lang.String exchange,
java.lang.String routingKey) |
JsonRpcClient(Channel channel,
java.lang.String exchange,
java.lang.String routingKey,
int timeout)
Construct a new JsonRpcClient, passing the parameters through
to RpcClient's constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
call(java.lang.String[] args)
Public API - as
call(String,Object[]) , but takes the
method name from the first entry in args , and the
parameters from subsequent entries. |
java.lang.Object |
call(java.lang.String method,
java.lang.Object[] params)
Public API - builds, encodes and sends a JSON-RPC request, and
waits for the response.
|
static java.lang.Object |
checkReply(java.util.Map<java.lang.String,java.lang.Object> reply)
Private API - parses a JSON-RPC reply object, checking it for exceptions.
|
static java.lang.Object |
coerce(java.lang.String val,
java.lang.String type)
Private API - used by
call(String[]) to ad-hoc convert
strings into the required data types for a call. |
java.lang.Object |
createProxy(java.lang.Class<?> klass)
Public API - gets a dynamic proxy for a particular interface class.
|
ServiceDescription |
getServiceDescription()
Public API - gets the service description record that this
service loaded from the server itself at construction time.
|
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
Public API - implements InvocationHandler.invoke.
|
checkConsumer, close, getChannel, getConsumer, getContinuationMap, getCorrelationId, getExchange, getRoutingKey, mapCall, mapCall, primitiveCall, primitiveCall, publish, setupConsumer, stringCall
public JsonRpcClient(Channel channel, java.lang.String exchange, java.lang.String routingKey, int timeout) throws java.io.IOException, JsonRpcException, java.util.concurrent.TimeoutException
java.util.concurrent.TimeoutException
- if a response is not received within the timeout specified, if anyjava.io.IOException
JsonRpcException
public JsonRpcClient(Channel channel, java.lang.String exchange, java.lang.String routingKey) throws java.io.IOException, JsonRpcException, java.util.concurrent.TimeoutException
java.io.IOException
JsonRpcException
java.util.concurrent.TimeoutException
public static java.lang.Object checkReply(java.util.Map<java.lang.String,java.lang.Object> reply) throws JsonRpcException
JsonRpcException
public java.lang.Object call(java.lang.String method, java.lang.Object[] params) throws java.io.IOException, JsonRpcException, java.util.concurrent.TimeoutException
JsonRpcException
- if the reply object contained an exceptionjava.util.concurrent.TimeoutException
- if a response is not received within the timeout specified, if anyjava.io.IOException
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
invoke
in interface java.lang.reflect.InvocationHandler
java.lang.Throwable
public java.lang.Object createProxy(java.lang.Class<?> klass) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static java.lang.Object coerce(java.lang.String val, java.lang.String type) throws java.lang.NumberFormatException
call(String[])
to ad-hoc convert
strings into the required data types for a call.java.lang.NumberFormatException
public java.lang.Object call(java.lang.String[] args) throws java.lang.NumberFormatException, java.io.IOException, JsonRpcException, java.util.concurrent.TimeoutException
call(String,Object[])
, but takes the
method name from the first entry in args
, and the
parameters from subsequent entries. All parameter values are
passed through coerce() to attempt to make them the types the
server is expecting.JsonRpcException
- if the reply object contained an exceptionjava.lang.NumberFormatException
- if a coercion failedjava.util.concurrent.TimeoutException
- if a response is not received within the timeout specified, if anyjava.io.IOException
coerce(java.lang.String, java.lang.String)
public ServiceDescription getServiceDescription()