public class JsonRpcClient extends RpcClient implements 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[])
RpcClient.Response
NO_TIMEOUT
Constructor and Description |
---|
JsonRpcClient(Channel channel,
String exchange,
String routingKey) |
JsonRpcClient(Channel channel,
String exchange,
String routingKey,
int timeout)
Construct a new JsonRpcClient, passing the parameters through
to RpcClient's constructor.
|
Modifier and Type | Method and Description |
---|---|
Object |
call(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. |
Object |
call(String method,
Object[] params)
Public API - builds, encodes and sends a JSON-RPC request, and
waits for the response.
|
static Object |
checkReply(Map<String,Object> reply)
Private API - parses a JSON-RPC reply object, checking it for exceptions.
|
static Object |
coerce(String val,
String type)
Private API - used by
call(String[]) to ad-hoc convert
strings into the required data types for a call. |
Object |
createProxy(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.
|
Object |
invoke(Object proxy,
Method method,
Object[] args)
Public API - implements InvocationHandler.invoke.
|
checkConsumer, close, doCall, doCall, getChannel, getConsumer, getContinuationMap, getCorrelationId, getExchange, getRoutingKey, mapCall, mapCall, primitiveCall, primitiveCall, primitiveCall, publish, responseCall, responseCall, setupConsumer, stringCall
public JsonRpcClient(Channel channel, String exchange, String routingKey, int timeout) throws IOException, JsonRpcException, TimeoutException
TimeoutException
- if a response is not received within the timeout specified, if anyIOException
JsonRpcException
public JsonRpcClient(Channel channel, String exchange, String routingKey) throws IOException, JsonRpcException, TimeoutException
public static Object checkReply(Map<String,Object> reply) throws JsonRpcException
JsonRpcException
public Object call(String method, Object[] params) throws IOException, JsonRpcException, TimeoutException
JsonRpcException
- if the reply object contained an exceptionTimeoutException
- if a response is not received within the timeout specified, if anyIOException
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
invoke
in interface InvocationHandler
Throwable
public Object createProxy(Class<?> klass) throws IllegalArgumentException
IllegalArgumentException
public static Object coerce(String val, String type) throws NumberFormatException
call(String[])
to ad-hoc convert
strings into the required data types for a call.NumberFormatException
public Object call(String[] args) throws NumberFormatException, IOException, JsonRpcException, 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 exceptionNumberFormatException
- if a coercion failedTimeoutException
- if a response is not received within the timeout specified, if anyIOException
coerce(java.lang.String, java.lang.String)
public ServiceDescription getServiceDescription()
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.