abstract class JsonRpc::Client

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def async_call : Bool #

If true, all locally invoked methods will be run in their own fiber.


[View source]
def async_call=(async_call : Bool) #

If true, all locally invoked methods will be run in their own fiber.


[View source]
def call(result_type, method : String, params = nil) #

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.


[View source]
def call?(result_type, method : String, params = nil) #

Calls a remote method, returning the result. On error, a RemoteCallError is returned. Otherwise, the nilable result is returned.


[View source]
def close #

Closes the connection.


[View source]
def connection_lost : Signal_connection_lost #

[View source]
def fatal_local_error : Signal_fatal_local_error #

[View source]
def fatal_remote_error : Signal_fatal_remote_error #

[View source]
def flood_messages : Int32 | Nil #

Count of max messages in #flood_time_span, after which the flood protection is triggered.

Set to nil to disable the flood-protection.


[View source]
def flood_messages=(flood_messages : Int32 | Nil) #

Count of max messages in #flood_time_span, after which the flood protection is triggered.

Set to nil to disable the flood-protection.


[View source]
def flood_protection_triggered : Signal_flood_protection_triggered #

[View source]
def flood_time_span : Time::Span #

Time span in which a max count of #flood_messages messages can be received before triggering the flood protection.


[View source]
def 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.


[View source]
def handler : Handler #

Handler which is called whenever a call is received from the remote end. The default implementation rejects every call immediately.

See also Handler#call.


[View source]
def handler=(handler : Handler) #

Handler which is called whenever a call is received from the remote end. The default implementation rejects every call immediately.

See also Handler#call.


[View source]
def invoke_from_remote(request : Request, raw : String) : Nil #

Called by Client implementations to invoke a local method.


[View source]
def messages_received : UInt64 #

Total count of messages received.


[View source]
def messages_sent : UInt64 #

Total count of messages sent.


[View source]
def notification : Signal_notification #

[View source]
def notify(method : String, params = nil) #

Sends a notification to method with params to the remote end.


[View source]
def notify_raw(message : String) #

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.


[View source]
abstract def recv_message(id) #

Called to receive a message.


[View source]
abstract def remote_address : String #

Returns the remote address for display/logging purposes


[View source]
def running? : Bool #

If the client is currently running, accepting messages, and hopefully also still connected.


[View source]
abstract def send_message(id, message_data : String) #

Called to send message_data identified by id.


[View source]
def send_response(response : Response) #

Used by DelayedResponse to send a response.


[View source]