network.protocols.json rpc.client - Palamecia/mint GitHub Wiki

Module network.protocols.json-rpc.client

Description

load network.protocols.json-rpc.client

This module provides the JSON-RPC client transports exposed by Network.JsonRpc.Client and Network.JsonRpc.AsyncClient. The classes wrap the underlying channel abstraction and can be used either directly or through the runtime scheduler.

Packages

Classes

Network.JsonRpc.AsyncClient

This class provides an asynchronous implementation of the client-side JSON-RPC transport. It can be used with Runtime.Scheduler and Mint coroutines.

Public members

Modifiers Member Description
const close Closes the communication with the peer. Returns true if the client was succes...
connect Attempts to establish a connection to the remote device asynchronously. This ...
const getDefaultAttribute Returns the value for the attribute name used by default created messages.
const getDefaultAttributes Returns the attributes used by default created messages as a hash.
const getScheduler Returns the scheduler associated with the object. This method calls the Netwo...
const new Creates a new asynchronous client context for the given socket. The socket pa...
read Asynchronously receives the next message from the peer.
const removeDefaultAttribute Removes the attribute name used by default created messages.
const setDefaultAttribute Sets the attribute name used by default created messages to value.
const setDefaultAttributes Sets the attributes used by default created messages to attributes.
write Pushes the message object described by data to the request queue and asynchro...

Private members

Modifiers Member Description
final channel Internal channel.
final configuration Internal configuration.

Network.JsonRpc.Client

This class provides the event-driven client-side JSON-RPC transport. It can be used with a Network.Poller or directly through the runtime scheduler exposed by the underlying channel.

Public members

Modifiers Member Description
const close Closes the communication with the peer if the context was connected using the ``...
const connect Attempts to make a connection to the remote device. This method calls the Net...
const getDefaultAttribute Returns the value for the attribute name used by default created messages of ...
const getDefaultAttributes Returns the attributes used by default created messages of the contexte as a...
const getEndpoint Returns the next message received from the peer. This method calls Network.Js...
const getEvents Returns the events expected by the context as mask of values from the Network...
const getHandle Returns the context's socket's handle as an instance of mint::handle_t. This ...
const getState Returns the current state of the context as a value of Network.JsonRpc.Client...
const isNonBlocking Returns true if the channel performs I/O operations asynchronously (i.e. read...
const new Creates a new client context for the given socket server. The socket paramete...
const notifyClosed Notifies the channel that the connection was closed by the peer. This method ...
const notifyError Notifies the channel that the underlying end point has received an error. Thi...
const notifyReadable Notifies the context that the underlying channel is readable. This method cal...
const notifyWritable Notifies the channel that the underlying end point is writable. This method c...
onClose This method can be rebound to handle close events. The client parameter is th...
onMessage This method can be rebound to handle message events. The client parameter is ...
onOpen This method can be rebound to handle connection success events. The client pa...
onState This method can be rebound to handle state change events. The client paramete...
const read Returns the next message object in the reply queue or none if no more message...
const removeDefaultAttribute Removes the attribute name used by default created messages. The remaining at...
const setDefaultAttribute Sets the attribute name used by default created messages to value. The attrib...
const setDefaultAttributes Sets the attributes used by default created messages to attributes. The attri...
const setNonBlocking Sets the non blocking mode of the channel to enabled. This method calls the N...
const watchedBy Makes the client watched by poller. The poller parameter should be an instanc...
const write Pushes the message object described by data to the request queue. This method...

Private members

Modifiers Member Description
final channel Internal channel.
final configuration Internal configuration.

Network.JsonRpc.ClientConfiguration

Stores the default configuration values used by JSON-RPC client instances.

Public members

Modifiers Member Description
attributes Default attributes.

Descriptions

Network.JsonRpc.AsyncClient.channel

null

Internal channel.

Network.JsonRpc.AsyncClient.close

def (self)

Closes the communication with the peer.

Returns true if the client was successfully closed.

This method calls the Network.AsyncChannel.close method of the underlying channel.

The client will enter the Network.Socket.State.Closed state on success or Network.Socket.State.Error on error.

Network.JsonRpc.AsyncClient.configuration

null

Internal configuration.

Network.JsonRpc.AsyncClient.connect

def (self, endpoint)

Attempts to establish a connection to the remote device asynchronously.

This method suspends the current coroutine until the connection attempt either succeeds or fails.

Returns true if the connection was successfully established; otherwise returns false.

Network.JsonRpc.AsyncClient.getDefaultAttribute

def (const self, name)

Returns the value for the attribute name used by default created messages.

Network.JsonRpc.AsyncClient.getDefaultAttributes

def (const self)

Returns the attributes used by default created messages as a hash.

Network.JsonRpc.AsyncClient.getScheduler

def (const self)

Returns the scheduler associated with the object. This method calls the Network.EventChannel.getScheduler method of the underlying channel.

Network.JsonRpc.AsyncClient.new

def (self, socket)

Creates a new asynchronous client context for the given socket. The socket parameter must implement the Network.Socket interface.

Network.JsonRpc.AsyncClient.read

def (self)

Asynchronously receives the next message from the peer.

Network.JsonRpc.AsyncClient.removeDefaultAttribute

def (self, name)

Removes the attribute name used by default created messages.

Network.JsonRpc.AsyncClient.setDefaultAttribute

def (self, name, value)

Sets the attribute name used by default created messages to value.

Network.JsonRpc.AsyncClient.setDefaultAttributes

def (self, attributes)

Sets the attributes used by default created messages to attributes.

Network.JsonRpc.AsyncClient.write

def (self, data)

Pushes the message object described by data to the request queue and asynchronously sends the data to the peer.

The data parameter can be an instance of Network.JsonRpc.Message; otherwise an instance will be created depending on the type of the parameter using Network.JsonRpc.Message.fromString for a string or Network.JsonRpc.Message.new for a hash. Attributes can be added to default created messages using setDefaultAttributes.

Network.JsonRpc.Client.channel

null

Internal channel.

Network.JsonRpc.Client.close

def (self)

Closes the communication with the peer if the context was connected using the connect. This method calls the Network.EventChannel.close method of the underlying channel. If the socket was successfully closed, onClose is called; otherwise the socket will be closed later.

An instance of Exception.SocketError is raised on error.

Network.JsonRpc.Client.configuration

null

Internal configuration.

Network.JsonRpc.Client.connect

def (self, endpoint)

Attempts to make a connection to the remote device. This method calls the Network.EventChannel.connect method of the underlying channel.

An instance of Exception.SocketError is raised on error.

Network.JsonRpc.Client.getDefaultAttribute

def (const self, name)

Returns the value for the attribute name used by default created messages of the contexte.

Network.JsonRpc.Client.getDefaultAttributes

def (const self)

Returns the attributes used by default created messages of the contexte as a hash.

Network.JsonRpc.Client.getEndpoint

def (const self)

Returns the next message received from the peer. This method calls Network.EventChannel.getEndpoint method of the underlying channel.

Network.JsonRpc.Client.getEvents

def (const self)

Returns the events expected by the context as mask of values from the Network.PollEvent enum. This method calls the Network.EventChannel.getEvents method of the underlying channel.

Network.JsonRpc.Client.getHandle

def (const self)

Returns the context's socket's handle as an instance of mint::handle_t. This method calls the Network.EventChannel.getHandle method of the underlying channel.

Network.JsonRpc.Client.getState

def (const self)

Returns the current state of the context as a value of Network.Socket.State. This method calls the Network.EventChannel.getState method of the underlying channel.

Network.JsonRpc.Client.isNonBlocking

def (const self)

Returns true if the channel performs I/O operations asynchronously (i.e. read or write data without blocking other channels); otherwise returns false. This method calls the Network.EventChannel.isNonBlocking method of the underlying channel.

Network.JsonRpc.Client.new

def (self, socket)

Creates a new client context for the given socket server. The socket parameter must implement the Network.Socket interface.

Network.JsonRpc.Client.notifyClosed

def (self)

Notifies the channel that the connection was closed by the peer. This method calls the Network.EventChannel.notifyClosed method of the underlying channel.

An instance of Exception.SocketError is raised on error.

Network.JsonRpc.Client.notifyError

def (self)

Notifies the channel that the underlying end point has received an error. This method calls the Network.EventChannel.notifyClosed method of the underlying channel and an instance of Exception.SocketError is raised.

Network.JsonRpc.Client.notifyReadable

def (self)

Notifies the context that the underlying channel is readable. This method calls the Network.EventChannel.notifyReadable method of the underlying channel.

An instance of Exception.SocketError is raised on error.

Network.JsonRpc.Client.notifyWritable

def (self)

Notifies the channel that the underlying end point is writable. This method calls the Network.EventChannel.notifyWritable method of the underlying channel.

An instance of Exception.SocketError is raised on error.

Network.JsonRpc.Client.onClose

def (self, client)

This method can be rebound to handle close events. The client parameter is the context that received the event. This can be used to cleanup a context or try to reconnect when the connection was closed by the peer.

Network.JsonRpc.Client.onMessage

def (self, client)

This method can be rebound to handle message events. The client parameter is the context that received the event. The messages can be accessed using the read method.

[!NOTE] This method can be called for one or more messages and will not be called until the underlying end point receive more data. The read method should then be called by this method until none is returned.

Network.JsonRpc.Client.onOpen

def (self, client)

This method can be rebound to handle connection success events. The client parameter is the context that received the event. This method can be used to begin exchanges with the peer.

Network.JsonRpc.Client.onState

def (self, client, % state)

This method can be rebound to handle state change events. The client parameter is the context that received the event and the state parameter is the state that will be applied to the underlying channel. The previous state can still be accessed with getState until the end of the method.

[!WARNING] Calling Network.Endpoint.setState in this method can result in an infinite loop.

Network.JsonRpc.Client.read

def (self)

Returns the next message object in the reply queue or none if no more message is available. This method calls the Network.EventChannel.read method of the underlying channel.

Network.JsonRpc.Client.removeDefaultAttribute

def (self, name)

Removes the attribute name used by default created messages. The remaining attributes will be passed to the Network.JsonRpc.Message.setHeader of the default created messages.

Network.JsonRpc.Client.setDefaultAttribute

def (self, name, value)

Sets the attribute name used by default created messages to value. The attributes will be passed to the Network.JsonRpc.Message.setHeader of the default created messages.

Network.JsonRpc.Client.setDefaultAttributes

def (self, attributes)

Sets the attributes used by default created messages to attributes. The attributes will be passed to the Network.JsonRpc.Message.setHeader of the default created messages.

Network.JsonRpc.Client.setNonBlocking

def (self, enabled)

Sets the non blocking mode of the channel to enabled. This method calls the Network.EventChannel.setNonBlocking method of the underlying channel. Returns true if the mode was successfully changed; otherwise returns false.

[!WARNING] Disable the non blocking mode on a context can slow down any network I/O operations of the application. Other channels will not be able to perform I/O operations until the current operation's acknowledgment by the peer.

An instance of Exception.SocketError is raised on error.

Network.JsonRpc.Client.watchedBy

def (self, poller)

Makes the client watched by poller. The poller parameter should be an instance of Network.Poller that will be used to watch for network events on the client. Network.Poller.watch will be automatically called for the client.

Network.JsonRpc.Client.write

def (self, data)

Pushes the message object described by data to the request queue. This method calls the Network.EventChannel.write method of the underlying channel.

The data parameter can be an instance of Network.JsonRpc.Message; otherwise an instance will be created depending on the type of the parameter using Network.JsonRpc.Message.fromString for a string or Network.JsonRpc.Message.new for a hash. Attributes can be added to default created messages using setDefaultAttributes.

Network.JsonRpc.ClientConfiguration.attributes

{}

Default attributes.