network.protocols.json rpc.server - Palamecia/mint GitHub Wiki
Module network.protocols.json-rpc.server
Description
load network.protocols.json-rpc.server
This module provides the JSON-RPC server transports and request handlers exposed by Network.JsonRpc.Server, Network.JsonRpc.AsyncServer, and Network.JsonRpc.RequestHandler. The classes wrap the underlying channel abstraction and can be used either directly or through the runtime scheduler.
Packages
Classes
Network.JsonRpc.AbstractRequestHandler
Base class for JSON-RPC request handlers that process incoming client messages.
Public members
| Modifiers | Member | Description |
|---|---|---|
| onRpcNotification | This method can be rebound to handle notification messages. The method parame... |
|
| onRpcRequest | This method can be rebound to handle request messages. The id parameter is th... |
|
| onRpcResponse | This method can be rebound to handle rezsponse messages. The id parameter is ... |
|
@ const |
toMethodSymbol | Returns the name of the method from the handler that must be called for the J... |
Network.JsonRpc.AsyncRequestHandler
This class provides an asynchronous request handler for Network.JsonRpc.AsyncServer.
Inherits
Public members
| Modifiers | Member | Description |
|---|---|---|
const |
close | Closes the communication with the peer. Returns true if the context was succe... |
const |
getScheduler | Returns the scheduler associated with the object. This method calls the Netwo... |
const |
new | Creates a new handler for the given socket client. The socket parameter must ... |
| onMessage | This method can be rebound to handle a message. The client parameter is the c... |
|
| read | Asynchronously receives the next message from the peer. | |
| run | Runs the asynchronous server loop. The loop will read messages from the under... | |
| 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.AsyncServer
This class provides an asynchronous implementation of the server-side JSON-RPC transport. It can be used with Runtime.Scheduler and Mint coroutines.
Public members
| Modifiers | Member | Description |
|---|---|---|
| accept | Accepts the next incoming connection and returns a request handler for it. | |
const |
close | Stops listening for incoming connections. Returns true if the server was succ... |
const |
getConfiguration | Returns the server's configuration as an instance of Network.JsonRpc.AsyncSer... |
const |
getScheduler | Returns the scheduler associated with the object. This method calls the Netwo... |
const |
listen | Tells the channel to listen for incoming connections on address configured by ``... |
const |
new | Creates a new asynchronous server context for the given endpoint. The endpoint... |
| onAccept | This method can be rebound to handle client connection events. The client par... |
|
| run | Runs the asynchronous server loop. The loop will accept incoming connections ... | |
const |
setConfiguration | Sets the server's configuration to configuration. The configuration parameter... |
Private members
| Modifiers | Member | Description |
|---|---|---|
final const |
RequestHandler | Internal request handler class. |
final |
channel | Internal listening channel. |
final |
configuration | Internal configuration. |
Network.JsonRpc.RequestHandler
This class provides a base implementation to handle requests received by Network.JsonRpc.Server.
Inherits
Public members
| Modifiers | Member | Description |
|---|---|---|
const |
close | Closes the communication with the peer. This method calls the Network.JsonRpc... |
const |
getConfiguration | Returns the handler's configuration as an instance of Network.JsonRpc.Request... |
const |
getEndpoint | Returns the underlying end point object. This method calls the Network.JsonRp... |
const |
getEvents | Returns the events expected by the handler as mask of values from the Network... |
const |
getHandle | Returns the handler's socket's handle as an instance of mint::handle_t. This ... |
const |
getState | Returns the current state of the handler as a value of Network.JsonRpc.Reques... |
const |
isNonBlocking | Returns true if the channel performs I/O operations asynchronously (i.e. read... |
const |
new | Creates a new handler for the given socket client. The socket parameter must ... |
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 |
setConfiguration | Sets the handler's configuration to configuration. The configuration paramete... |
const |
setNonBlocking | Sets the non blocking mode of the channel to enabled. This method calls the N... |
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 default configuration. |
Network.JsonRpc.Server
This class provides the event-driven server-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 | Stops listening if the context was openned with Network.JsonRpc.Server.listen. ... |
const |
getConfiguration | Returns the server's configuration as an instance of Network.JsonRpc.Server.N... |
const |
getEndpoint | Returns the underlying end point object. This method calls the Network.JsonRp... |
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.Server... |
const |
isNonBlocking | Returns true if the channel performs I/O operations asynchronously (i.e. read... |
const |
listen | Tells the channel to listen for incoming connections on address configured by ``... |
const |
new | Creates a new server context for the given socket. The socket parameter must ... |
const |
notifyClosed | Notifies the channel that the connection was closed by the peer. This method ... |
const |
notifyConnection | Notifies the channel that the underlying end point has received a new connect... |
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... |
| onAccept | This method can be rebound to handle client connection events. The client par... |
|
| onClose | This method can be rebound to handle close events. The server parameter is th... |
|
| onOpen | This method can be rebound to handle connection success events. The server pa... |
|
| onState | This method can be rebound to handle state change events. The server paramete... |
|
const |
setConfiguration | Sets the server's configuration to configuration. The configuration parameter... |
const |
setNonBlocking | Sets the non blocking mode of the channel to enabled. This method calls the N... |
const |
watchedBy | Makes the server watched by poller. The poller parameter should be an instanc... |
Private members
| Modifiers | Member | Description |
|---|---|---|
final |
channel | Internal channel. |
final |
configuration | Internal default configuration. |
Network.JsonRpc.ServerConfiguration
Stores the default configuration values used by JSON-RPC server instances.
Public members
| Modifiers | Member | Description |
|---|---|---|
| attributes | Server's default HTTP attributes. |
Descriptions
Network.JsonRpc.AbstractRequestHandler.onRpcNotification
def (self, method, params)
This method can be rebound to handle notification messages. The method
parameter is the method of the notification. The params parameter is a
hash containing the parameters of the notification.
The default implementation calls the handler's method return by toMethodSymbol for the notification method.
Network.JsonRpc.AbstractRequestHandler.onRpcRequest
def (self, id, method, params)
This method can be rebound to handle request messages. The id
parameter is the identifier of the message. The method parameter
is the method of the request. The params parameter is a hash
containing the parameters of the request. The method can return
a value that will be used as the result of the request.
The default implementation calls the handler's method return by toMethodSymbol for the request method.
Network.JsonRpc.AbstractRequestHandler.onRpcResponse
def (self, id, result, error)
This method can be rebound to handle rezsponse messages. The id
parameter is the identifier of the message. The result parameter
is the result of the request if any or none. The error parameter
is a hash containing the error encontred when handling the request
if any or none.
The default implementation does nothing.
Network.JsonRpc.AbstractRequestHandler.toMethodSymbol
def (method)
Returns the name of the method from the handler that must be called for the JSON-RPC method identified
by method.
The method name is created by replacing each non alpha numeric character from the method with '_' and
adding the 'rpc_' prefix.
Network.JsonRpc.AsyncRequestHandler.channel
null
Internal channel.
Network.JsonRpc.AsyncRequestHandler.close
def (self)
Closes the communication with the peer.
Returns true if the context was successfully closed.
This method calls the Network.AsyncChannel.close method of the underlying channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.AsyncRequestHandler.configuration
null
Internal configuration.
Network.JsonRpc.AsyncRequestHandler.getScheduler
def (const self)
Returns the scheduler associated with the object. This method calls the Network.AsyncChannel.getScheduler method of the underlying object.
Network.JsonRpc.AsyncRequestHandler.new
def (self, socket, configuration)
Creates a new handler for the given socket client. The socket parameter must implement the
Network.Socket interface. The configuration parameter is the default configuration provided by the
Network.JsonRpc.AsyncServer.
Network.JsonRpc.AsyncRequestHandler.onMessage
def (self, message)
This method can be rebound to handle a message. The client parameter is the context that received the
message and the message parameter is the message that was received.
Network.JsonRpc.AsyncRequestHandler.read
def (self)
Asynchronously receives the next message from the peer.
Network.JsonRpc.AsyncRequestHandler.run
def (self)
Runs the asynchronous server loop. The loop will read messages from the underlying channel and call onMessage for each message received. The loop will continue until the channel is closed or an error occurs.
Network.JsonRpc.AsyncRequestHandler.write
def (self, data)
Pushes the message object described by data to the request queue and asynchronously sends it to the
peer.
Network.JsonRpc.AsyncServer.RequestHandler
none
Internal request handler class.
Network.JsonRpc.AsyncServer.accept
def (self)
Accepts the next incoming connection and returns a request handler for it.
Network.JsonRpc.AsyncServer.channel
null
Internal listening channel.
Network.JsonRpc.AsyncServer.close
def (self)
Stops listening for incoming connections.
Returns true if the server was successfully closed.
This method calls the Network.AsyncChannel.close method of the underlying channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.AsyncServer.configuration
null
Internal configuration.
Network.JsonRpc.AsyncServer.getConfiguration
def (const self)
Returns the server's configuration as an instance of Network.Http.ServerConfiguration.
Network.JsonRpc.AsyncServer.getScheduler
def (const self)
Returns the scheduler associated with the object. This method calls the Network.AsyncChannel.getScheduler method of the underlying object.
Network.JsonRpc.AsyncServer.listen
def (self, endpoint)
Tells the channel to listen for incoming connections on address
configured by endpoint. Returns true on success; otherwise
returns false.
Network.JsonRpc.AsyncServer.new
def (self, endpoint, RequestHandler = Network.JsonRpc.AsyncRequestHandler)
Creates a new asynchronous server context for the given endpoint.
The endpoint parameter must implement the Network.Socket interface.
The RequestHandler parameter can provide a class that will be used to
create client contexts on incoming connections.
Network.JsonRpc.AsyncServer.onAccept
def (self, client)
This method can be rebound to handle client connection events. The
client parameter is the handler that received the event. This
method can be used to begin exchanges with the peer.
Network.JsonRpc.AsyncServer.run
def (self)
Runs the asynchronous server loop. The loop will accept incoming connections and call onAccept for each connection. The loop will continue until the channel is closed or an error occurs.
Network.JsonRpc.AsyncServer.setConfiguration
def (self, configuration)
Sets the server's configuration to configuration. The configuration parameter should be an instance
of Network.Http.ServerConfiguration.
Network.JsonRpc.RequestHandler.channel
null
Internal channel.
Network.JsonRpc.RequestHandler.close
def (self)
Closes the communication with the peer. 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.RequestHandler.configuration
null
Internal default configuration.
Network.JsonRpc.RequestHandler.getConfiguration
def (const self)
Returns the handler's configuration as an instance of Network.JsonRpc.ServerConfiguration.
Network.JsonRpc.RequestHandler.getEndpoint
def (const self)
Returns the underlying end point object. This method calls the Network.EventChannel.getEndpoint method of the underlying channel.
Network.JsonRpc.RequestHandler.getEvents
def (const self)
Returns the events expected by the handler as mask of values from the Network.PollEvent enum. This method calls the Network.EventChannel.getEvents method of the underlying channel.
Network.JsonRpc.RequestHandler.getHandle
def (const self)
Returns the handler'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.RequestHandler.getState
def (const self)
Returns the current state of the handler as a value of Network.Socket.State. This method calls the Network.EventChannel.getState method of the underlying channel.
Network.JsonRpc.RequestHandler.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.RequestHandler.new
def (self, socket, configuration)
Creates a new handler for the given socket client. The socket parameter must implement the
Network.Socket interface. The configuration parameter is the default configuration provided by the
Network.JsonRpc.Server.
Network.JsonRpc.RequestHandler.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.RequestHandler.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.RequestHandler.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.RequestHandler.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.RequestHandler.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.RequestHandler.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.
The default implementation calls onRpcNotification, onRpcRequest or onRpcResponse for each received message depending on its type.
[!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
noneis returned.
Network.JsonRpc.RequestHandler.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.RequestHandler.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.RequestHandler.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.RequestHandler.setConfiguration
def (self, configuration)
Sets the handler's configuration to configuration. The configuration parameter should be an instance
of Network.JsonRpc.ServerConfiguration.
Network.JsonRpc.RequestHandler.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.RequestHandler.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.Server.channel
null
Internal channel.
Network.JsonRpc.Server.close
def (self)
Stops listening if the context was openned with listen. 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.Server.configuration
null
Internal default configuration.
Network.JsonRpc.Server.getConfiguration
def (const self)
Returns the server's configuration as an instance of Network.JsonRpc.ServerConfiguration.
Network.JsonRpc.Server.getEndpoint
def (const self)
Returns the underlying end point object. This method calls the Network.EventChannel.getEndpoint method of the underlying channel.
Network.JsonRpc.Server.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.Server.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.Server.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.Server.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.Server.listen
def (self, endpoint)
Tells the channel to listen for incoming connections on address configured by endpoint. Returns true
on success; otherwise returns false. This method calls the Network.EventChannel.listen method of the
underlying channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.Server.new
def (self, socket, RequestHandler = Network.JsonRpc.RequestHandler)
Creates a new server context for the given socket. The socket parameter must implement the
Network.Socket interface.
The RequestHandler can provide a class that will be used to create clients context on client
connection.
Network.JsonRpc.Server.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.Server.notifyConnection
def (self)
Notifies the channel that the underlying end point has received a new connection request. This method calls the Network.EventChannel.notifyConnection method of the underlying channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.Server.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.Server.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.Server.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.Server.onAccept
def (self, client)
This method can be rebound to handle client connection events. The
client parameter is the handler that received the event. This
method can be used to begin exchanges with the peer.
Network.JsonRpc.Server.onClose
def (self, server)
This method can be rebound to handle close events. The server
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.Server.onOpen
def (self, server)
This method can be rebound to handle connection success events. The
server parameter is the context that received the event. This
method can be used to begin exchanges with the peer.
Network.JsonRpc.Server.onState
def (self, server, % state)
This method can be rebound to handle state change events. The server
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.Server.setConfiguration
def (self, configuration)
Sets the server's configuration to configuration. The configuration parameter should be an instance
of Network.JsonRpc.ServerConfiguration.
Network.JsonRpc.Server.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.Server.watchedBy
def (self, poller)
Makes the server watched by poller. The poller parameter should be an instance of Network.Poller
that will be used to watch for network events on the server. Network.Poller.watch will be
automatically called for the server and also all the create client contexts.
Network.JsonRpc.ServerConfiguration.attributes
{}
Server's default HTTP attributes.