public final class JsonRPCMessageHandler extends java.lang.Object implements MessageReceiver<java.lang.String>
MessageSender
, and
handles the incoming JSON RPC messages when delivered to onMessage(String)
.
RPCfy
Constructor and Description |
---|
JsonRPCMessageHandler(MessageSender<java.lang.String> messageSender)
Creates an instance of
JsonRPCMessageHandler . |
Modifier and Type | Method and Description |
---|---|
void |
addMethodDelegate(RPCMethodDelegate methodDelegate)
Adds a delegate for a given method in a interface.
|
static <T> T |
asException(java.lang.String exceptionName,
java.lang.String exceptionMessage,
java.lang.Class<T> exception)
Internal use to convert exception
|
void |
clear()
Clears all the stubs registered with this.
|
void |
clearStub(java.lang.Object object)
Clears any stub created for the given instance
|
void |
clearStub(RPCStub stub)
Clears any previously registered
RPCStub |
java.util.Map<java.lang.String,java.lang.String> |
getExtras()
Return any extras set
|
java.lang.Object |
getMethodDelegate(RPCMethodDelegate delegate)
Returns any method delegate set for the given method
|
RPCStub |
getStub(java.lang.Object object)
Returns any stub assosiated with given object
|
void |
onMessage(java.lang.String message)
Called to processes given message
|
void |
registerStub(RPCStub stub)
Register a
RPCStub with this handler, so that any message intended
for the stub can be delivered. |
void |
sendMessage(java.lang.String message)
Used internally by generated Proxy/Stub to send the message using the
MessageSender associated with this |
java.lang.String |
sendMessageAndWaitForResponse(java.lang.String message,
java.lang.String interfaceName,
int methodID,
int rpcID)
Used internally by generated Proxy/Stub to send the message using the
MessageSender associated with this |
void |
setExtra(java.util.Map<java.lang.String,java.lang.String> requestExtras)
Put any extra json key/value to be send with the request message.
|
void |
setLogEnabled(boolean logEnabled)
Enable/disable debug loging
|
void |
setRequestTimeout(long requestTimeout)
Sets the request timeout for blocking requests.
|
public JsonRPCMessageHandler(MessageSender<java.lang.String> messageSender)
JsonRPCMessageHandler
.
Use a single instance for client side, and another single instance at server side.messageSender
- The generated messages will be send using this.public void setLogEnabled(boolean logEnabled)
public void setExtra(java.util.Map<java.lang.String,java.lang.String> requestExtras)
Any key starting with custom_ will also be relayed back in the response
public void addMethodDelegate(RPCMethodDelegate methodDelegate)
public java.lang.Object getMethodDelegate(RPCMethodDelegate delegate)
public java.util.Map<java.lang.String,java.lang.String> getExtras()
public void onMessage(java.lang.String message)
MessageReceiver
onMessage
in interface MessageReceiver<java.lang.String>
public void sendMessage(java.lang.String message)
MessageSender
associated with thispublic java.lang.String sendMessageAndWaitForResponse(java.lang.String message, java.lang.String interfaceName, int methodID, int rpcID)
MessageSender
associated with thispublic void registerStub(RPCStub stub)
RPCStub
with this handler, so that any message intended
for the stub can be delivered.public void clearStub(RPCStub stub)
RPCStub
registerStub(RPCStub)
public void clear()
public void clearStub(java.lang.Object object)
object
- public RPCStub getStub(java.lang.Object object)
public void setRequestTimeout(long requestTimeout)
public static <T> T asException(java.lang.String exceptionName, java.lang.String exceptionMessage, java.lang.Class<T> exception)