public class JsonRpcServer extends StringRpcServer
Given a Java Class
, representing an interface, and an
implementation of that interface, JsonRpcServer will reflect on the
class to construct the ServiceDescription
, and will route
incoming requests for methods on the interface to the
implementation object while the mainloop() is running.
JsonRpcServer
delegates JSON parsing and generating to
a JsonRpcMapper
.
RpcServer
,
JsonRpcClient
,
JsonRpcMapper
,
JacksonJsonRpcMapper
RpcServer.RpcConsumer
STRING_ENCODING
Constructor and Description |
---|
JsonRpcServer(Channel channel,
Class<?> interfaceClass,
Object interfaceInstance)
Construct a server that talks to the outside world using the
given channel, and constructs a fresh temporary
queue.
|
JsonRpcServer(Channel channel,
Class<?> interfaceClass,
Object interfaceInstance,
JsonRpcMapper mapper) |
JsonRpcServer(Channel channel,
String queueName,
Class<?> interfaceClass,
Object interfaceInstance)
Construct a server that talks to the outside world using the
given channel and queue name.
|
JsonRpcServer(Channel channel,
String queueName,
Class<?> interfaceClass,
Object interfaceInstance,
JsonRpcMapper mapper) |
Modifier and Type | Method and Description |
---|---|
String |
doCall(String requestBody)
Runs a single JSON-RPC request.
|
ServiceDescription |
getServiceDescription()
Public API - gets the service description record that this
service built from interfaceClass at construction time.
|
String |
handleStringCall(String requestBody,
AMQP.BasicProperties replyProperties)
Override our superclass' method, dispatching to doCall.
|
Method |
matchingMethod(String methodName,
Object[] params)
Retrieves the best matching method for the given method name and parameters.
|
handleCall, handleCast, handleStringCall, handleStringCast
close, getChannel, getQueueName, handleCall, handleCall, handleCast, handleCast, mainloop, postprocessReplyProperties, preprocessReplyProperties, processRequest, setupConsumer, terminateMainloop
public JsonRpcServer(Channel channel, Class<?> interfaceClass, Object interfaceInstance, JsonRpcMapper mapper) throws IOException
IOException
public JsonRpcServer(Channel channel, Class<?> interfaceClass, Object interfaceInstance) throws IOException
channel
- AMQP channel to useinterfaceClass
- Java interface that this server is exposing to the worldinterfaceInstance
- Java instance (of interfaceClass) that is being exposedIOException
- if something goes wrong during an AMQP operationpublic JsonRpcServer(Channel channel, String queueName, Class<?> interfaceClass, Object interfaceInstance, JsonRpcMapper mapper) throws IOException
IOException
public JsonRpcServer(Channel channel, String queueName, Class<?> interfaceClass, Object interfaceInstance) throws IOException
channel
- AMQP channel to usequeueName
- AMQP queue name to listen for requests oninterfaceClass
- Java interface that this server is exposing to the worldinterfaceInstance
- Java instance (of interfaceClass) that is being exposedIOException
- if something goes wrong during an AMQP operationpublic String handleStringCall(String requestBody, AMQP.BasicProperties replyProperties)
handleStringCall
in class StringRpcServer
public String doCall(String requestBody)
requestBody
- the JSON-RPC request string (a JSON encoded value)public Method matchingMethod(String methodName, Object[] params)
Subclasses may override this if they have specialised dispatching requirements, so long as they continue to honour their ServiceDescription.
public ServiceDescription getServiceDescription()
Copyright © 2022 VMware, Inc. or its affiliates.. All rights reserved.