abstract class JsonRpc::Client
- JsonRpc::Client
- Reference
- Object
Overview
Client class for JSON-RPC. See one of its sub-classes for implementations.
The client offers a built-in flood-protection for received messages. Note that these are counted towards all messages, and thus include responses to made remote invocations from our end.
By default, the flood-protection allows for 6000 messages per minute, or
about 100 messages per second. You can change these values through
#flood_time_span
and #flood_messages
.
Direct Known Subclasses
Defined in:
json_rpc/client.crConstructors
Instance Method Summary
-
#async_call : Bool
If
true
, all locally invoked methods will be run in their own fiber. -
#async_call=(async_call : Bool)
If
true
, all locally invoked methods will be run in their own fiber. -
#call(result_type, method : String, params = nil)
Calls a remote method with optional params, returning a result_type.
-
#call?(result_type, method : String, params = nil)
Calls a remote method, returning the result.
-
#close
Closes the connection.
- #connection_lost : Signal_connection_lost
- #fatal_local_error : Signal_fatal_local_error
- #fatal_remote_error : Signal_fatal_remote_error
-
#flood_messages : Int32 | Nil
Count of max messages in
#flood_time_span
, after which the flood protection is triggered. -
#flood_messages=(flood_messages : Int32 | Nil)
Count of max messages in
#flood_time_span
, after which the flood protection is triggered. - #flood_protection_triggered : Signal_flood_protection_triggered
-
#flood_time_span : Time::Span
Time span in which a max count of
#flood_messages
messages can be received before triggering the flood protection. -
#flood_time_span=(flood_time_span : Time::Span)
Time span in which a max count of
#flood_messages
messages can be received before triggering the flood protection. -
#handler : Handler
Handler which is called whenever a call is received from the remote end.
-
#handler=(handler : Handler)
Handler which is called whenever a call is received from the remote end.
-
#invoke_from_remote(request : Request, raw : String) : Nil
Called by
Client
implementations to invoke a local method. -
#messages_received : UInt64
Total count of messages received.
-
#messages_sent : UInt64
Total count of messages sent.
- #notification : Signal_notification
-
#notify(method : String, params = nil)
Sends a notification to method with params to the remote end.
-
#notify_raw(message : String)
Sends a notification to the remote end, that is already serialized.
-
#recv_message(id)
Called to receive a message.
-
#remote_address : String
Returns the remote address for display/logging purposes
-
#running? : Bool
If the client is currently running, accepting messages, and hopefully also still connected.
-
#send_message(id, message_data : String)
Called to send message_data identified by id.
-
#send_response(response : Response)
Used by
DelayedResponse
to send a response.
Constructor Detail
Instance Method Detail
If true
, all locally invoked methods will be run in their own fiber.
Calls a remote method with optional params, returning a result_type.
Error behaviour
On success the result of the invocation is returned. If however the
remote signals an error through the "error"
field (per JSON-RPC), it
will be re-raised locally as RemoteCallError
.
See #call?
for a non-raising version.
Calls a remote method, returning the result. On error, a
RemoteCallError
is returned. Otherwise, the nilable result is
returned.
Count of max messages in #flood_time_span
, after which the flood
protection is triggered.
Set to nil
to disable the flood-protection.
Count of max messages in #flood_time_span
, after which the flood
protection is triggered.
Set to nil
to disable the flood-protection.
Time span in which a max count of #flood_messages
messages can be
received before triggering the flood protection.
Time span in which a max count of #flood_messages
messages can be
received before triggering the flood protection.
Handler which is called whenever a call is received from the remote end. The default implementation rejects every call immediately.
See also Handler#call
.
Handler which is called whenever a call is received from the remote end. The default implementation rejects every call immediately.
See also Handler#call
.
Called by Client
implementations to invoke a local method.
Sends a notification to method with params to the remote end.
Sends a notification to the remote end, that is already serialized. Useful to send a notification to many clients in bulk.
Use Request#to_json
for easy construction of a message.
If the client is currently running, accepting messages, and hopefully also still connected.
Called to send message_data identified by id.