network.protocols.jsonrpc.server - Palamecia/mint GitHub Wiki
Module
load network.protocols.jsonrpc.server
This module provides the Network.JsonRpc.Server class which implement the server side of the JSON RPC protocol.
Packages
Classes
Network.JsonRpc.RequestHandler
This class provides a base implementation to handle Network.JsonRpc.Server's clients requets.
Members
Modifiers | Member | Description |
---|---|---|
- final |
attributes | Internal default attributes. |
- final |
channel | Internal channel. |
+ const |
close | Closes the communication with the peer. This method calls the Network.Asynchr... |
+ const |
getDefaultAttribute | Returns the value for the attribute name used by default created messages o... |
+ const |
getDefaultAttributes | Returns the attributes used by default created messages of the contexte as a... |
+ const |
getEndpoint | Returns the underling end point object. This method calls the Network.Asynchr... |
+ const |
getEvents | Returns the events expected by the handler as mask of values from the Network... |
+ const |
getSocket | Returns the handler's socket as a number. This method calls the Network.Async... |
+ const |
getState | Returns the current state of the handler as a value of Network.EndPoint.State... |
+ const |
isNonBlocking | Returns true if the channel performs I/O operations asynchronously (i.e. re... |
+ const |
new | Creates a new handler for the given endpoint client. The endpoint paramet... |
+ const |
notifyClosed | Notifies the channel that the connection was closed by the peer. This method ... |
+ const |
notifyError | Notifies the channel that the underling end point has received an error. This... |
+ const |
notifyReadable | Notifies the context that the underling channel is readable. This method call... |
+ const |
notifyWritable | Notifies the channel that the underling end point is writable. This method ca... |
+ |
onClose | This method can be rebinded to handle close events. The client parameter is... |
+ |
onMessage | This method can be rebinded to handle message events. The client parameter ... |
+ |
onOpen | This method can be rebinded to handle connection success events. The client ... |
+ |
onRpcNotification | This method can be rebinded to handle notification messages. The method par... |
+ |
onRpcRequest | This method can be rebinded to handle request messages. The id parameter is... |
+ |
onRpcResponse | This method can be rebinded to handle rezsponse messages. The id parameter ... |
+ |
onState | This method can be rebinded to handle state change events. The client param... |
+ const |
read | Returns the next message object in the reply queue or none if no more messa... |
+ const |
removeDefaultAttribute | Removes the attribute name used by default created messages. The remaining ... |
+ const |
setDefaultAttribute | Sets the attribute name used by default created messages to value . The at... |
+ const |
setDefaultAttributes | Sets the attributes used by default created messages to attributes . The att... |
+ const |
setNonBlocking | Sets the non blocking mode of the channel to enabled . This method calls the... |
+ @ const |
toMethodSymbol | Returns the name of the method from the handler that must be called for the J... |
+ const |
unwatch | Removes the channel from the Network.Scheduler object. This method calls the ... |
+ const |
watch | Adds the channel to the Network.Scheduler object. This method calls the Netwo... |
+ const |
write | Pushes the message object described by data to the request queue. This meth... |
Network.JsonRpc.Server
This class provides an implementation of the server side of the JSON RPC protocol. It can be used with the Network.Scheduler class where a channel is expected.
Members
Modifiers | Member | Description |
---|---|---|
- final |
attributes | Internal default attributes. |
- final |
channel | Internal channel. |
+ const |
close | Stops listening if the context was openned with listen. This method calls the... |
+ const |
getDefaultAttribute | Returns the value for the attribute name used by default created messages o... |
+ const |
getDefaultAttributes | Returns the attributes used by default created messages of the contexte as a... |
+ const |
getEndpoint | Returns the underling end point object. This method calls the Network.Asynchr... |
+ const |
getEvents | Returns the events expected by the context as mask of values from the Network... |
+ const |
getSocket | Returns the context's socket as a number. This method calls the Network.Async... |
+ const |
getState | Returns the current state of the context as a value of Network.EndPoint.State... |
+ const |
isNonBlocking | Returns true if the channel performs I/O operations asynchronously (i.e. re... |
+ const |
listen | Tells the channel to listen for incoming connections on address configured by... |
+ const |
new | Creates a new server context for the given endpoint . The endpoint paramet... |
+ const |
notifyClosed | Notifies the channel that the connection was closed by the peer. This method ... |
+ const |
notifyConnection | Notifies the channel that the underling end point has received a new connecti... |
+ const |
notifyError | Notifies the channel that the underling end point has received an error. This... |
+ const |
notifyReadable | Notifies the context that the underling channel is readable. This method call... |
+ const |
notifyWritable | Notifies the channel that the underling end point is writable. This method ca... |
+ |
onClose | This method can be rebinded to handle close events. The server parameter is... |
+ |
onConnection | This method can be rebinded to handle client connection events. The client ... |
+ |
onDisconnection | This method can be rebinded to handle client disconnection events. The clie ... |
+ |
onOpen | This method can be rebinded to handle connection success events. The server ... |
+ |
onState | This method can be rebinded to handle state change events. The server param... |
+ const |
read | Returns the next end point in the connection queue. This method calls the Net... |
+ const |
removeDefaultAttribute | Removes the attribute name used by default created messages. The remaining ... |
+ const |
setDefaultAttribute | Sets the attribute name used by default created messages to value . The at... |
+ const |
setDefaultAttributes | Sets the attributes used by default created messages to attributes . The att... |
+ const |
setNonBlocking | Sets the non blocking mode of the channel to enabled . This method calls the... |
+ const |
unwatch | Removes the channel from the Network.Scheduler object. This method calls the ... |
+ const |
watch | Adds the channel to the Network.Scheduler object. This method calls the Netwo... |
Descriptions
Network.JsonRpc.RequestHandler.attributes
{}
Internal default attributes.
Network.JsonRpc.RequestHandler.channel
null
Internal channel.
Network.JsonRpc.RequestHandler.close
def (self)
Closes the communication with the peer. This method calls the Network.AsynchronousChannel.close method of the underling 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.getDefaultAttribute
def (const self, name)
Returns the value for the attribute name
used by default
created messages of the contexte.
Network.JsonRpc.RequestHandler.getDefaultAttributes
def (const self)
Returns the attributes used by default created messages of the contexte as a hash.
Network.JsonRpc.RequestHandler.getEndpoint
def (const self)
Returns the underling end point object. This method calls the Network.AsynchronousChannel.getEndpoint method of the underling channel.
Network.JsonRpc.RequestHandler.getEvents
def (const self)
Returns the events expected by the handler as mask of values from the Network.Scheduler.PollEvent enum. This method calls the Network.AsynchronousChannel.getEvents method of the underling channel.
Network.JsonRpc.RequestHandler.getSocket
def (const self)
Returns the handler's socket as a number. This method calls the Network.AsynchronousChannel.getSocket method of the underling channel.
Network.JsonRpc.RequestHandler.getState
def (const self)
Returns the current state of the handler as a value of Network.EndPoint.State. This method calls the Network.AsynchronousChannel.getState method of the underling 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.AsynchronousChannel.isNonBlocking method of the underling
channel.
Network.JsonRpc.RequestHandler.new
def (self, endpoint, Channel = Network.AsynchronousChannel)
Creates a new handler for the given endpoint
client. The
endpoint
parameter must implement the Network.EndPoint
interface.
The Channel
parameter can provide a class that will be used to
create the underling channel.
Network.JsonRpc.RequestHandler.notifyClosed
def (self)
Notifies the channel that the connection was closed by the peer. This method calls the Network.AsynchronousChannel.notifyClosed method of the underling channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.RequestHandler.notifyError
def (self)
Notifies the channel that the underling end point has received an error. This method calls the Network.AsynchronousChannel.notifyClosed method of the underling channel and an instance of Exception.SocketError is raised.
Network.JsonRpc.RequestHandler.notifyReadable
def (self)
Notifies the context that the underling channel is readable. This method calls the Network.AsynchronousChannel.notifyReadable method of the underling channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.RequestHandler.notifyWritable
def (self)
Notifies the channel that the underling end point is writable. This method calls the Network.AsynchronousChannel.notifyWritable method of the underling channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.RequestHandler.onClose
def (self, client)
This method can be rebinded 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 rebinded 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 receiveid message depending on its type.
[!NOTE] This method can be called for one or more messages and will not be called until the underling end point receive more data. The read method should then be called by this method until
none
is returned.
Network.JsonRpc.RequestHandler.onOpen
def (self, client)
This method can be rebinded 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.onRpcNotification
def (self, method, params)
This method can be rebinded 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 methode return by {see{@ toMethodSymbol} for the notification method.
Network.JsonRpc.RequestHandler.onRpcRequest
def (self, id, method, params)
This method can be rebinded 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 methode return by {see{@ toMethodSymbol} for the request method.
Network.JsonRpc.RequestHandler.onRpcResponse
def (self, id, result, error)
This method can be rebinded 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.RequestHandler.onState
def (self, client, % state)
This method can be rebinded 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 underling 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.AsynchronousChannel.read method of the underling channel.
Network.JsonRpc.RequestHandler.removeDefaultAttribute
def (self, name)
Removes the attribute name
used by default created messages.
The remaining attributes will be passed to the
Network.JsonRpc.Message.setAttribute of the default created
messages.
Network.JsonRpc.RequestHandler.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.setAttribute
of the default created messages.
Network.JsonRpc.RequestHandler.setDefaultAttributes
def (self, attributes)
Sets the attributes used by default created messages to attributes
.
The attributes will be passed to the Network.JsonRpc.Message.setAttribute
of the default created messages.
Network.JsonRpc.RequestHandler.setNonBlocking
def (self, enabled)
Sets the non blocking mode of the channel to enabled
. This method
calls the Network.AsynchronousChannel.setNonBlocking method of
the underling 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.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.RequestHandler.unwatch
def (self)
Removes the channel from the Network.Scheduler object. This method calls the Network.Scheduler.remove method.
Network.JsonRpc.RequestHandler.watch
def (self)
Adds the channel to the Network.Scheduler object. This method calls the Network.Scheduler.watch method.
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.AsynchronousChannel.write method
of the underling 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.attributes
{}
Internal default attributes.
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.AsynchronousChannel.close method of the underling 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.getDefaultAttribute
def (const self, name)
Returns the value for the attribute name
used by default
created messages of the contexte.
Network.JsonRpc.Server.getDefaultAttributes
def (const self)
Returns the attributes used by default created messages of the contexte as a hash.
Network.JsonRpc.Server.getEndpoint
def (const self)
Returns the underling end point object. This method calls the Network.AsynchronousChannel.getEndpoint method of the underling channel.
Network.JsonRpc.Server.getEvents
def (const self)
Returns the events expected by the context as mask of values from the Network.Scheduler.PollEvent enum. This method calls the Network.AsynchronousChannel.getEvents method of the underling channel.
Network.JsonRpc.Server.getSocket
def (const self)
Returns the context's socket as a number. This method calls the Network.AsynchronousChannel.getSocket method of the underling channel.
Network.JsonRpc.Server.getState
def (const self)
Returns the current state of the context as a value of Network.EndPoint.State. This method calls the Network.AsynchronousChannel.getState method of the underling 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.AsynchronousChannel.isNonBlocking method of the underling
channel.
Network.JsonRpc.Server.listen
def (self)
Tells the channel to listen for incoming connections on address
configured by the end point. Returns true
on success; otherwise
returns false
. This method calls the Network.AsynchronousChannel.listen
method of the underling channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.Server.new
def (self, endpoint, RequestHandler = Network.JsonRpc.RequestHandler, Channel = Network.AsynchronousChannel)
Creates a new server context for the given endpoint
. The
endpoint
parameter must implement the Network.EndPoint
interface.
The RequestHandler
can provide a class that will be used to
create clients context on client connection.
The Channel
parameter can provide a class that will be used to
create the underling channel.
Network.JsonRpc.Server.notifyClosed
def (self)
Notifies the channel that the connection was closed by the peer. This method calls the Network.AsynchronousChannel.notifyClosed method of the underling channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.Server.notifyConnection
def (self)
Notifies the channel that the underling end point has received a new connection request. This method calls the Network.AsynchronousChannel.notifyConnection method of the underling channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.Server.notifyError
def (self)
Notifies the channel that the underling end point has received an error. This method calls the Network.AsynchronousChannel.notifyClosed method of the underling channel and an instance of Exception.SocketError is raised.
Network.JsonRpc.Server.notifyReadable
def (self)
Notifies the context that the underling channel is readable. This method calls the Network.AsynchronousChannel.notifyReadable method of the underling channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.Server.notifyWritable
def (self)
Notifies the channel that the underling end point is writable. This method calls the Network.AsynchronousChannel.notifyWritable method of the underling channel.
An instance of Exception.SocketError is raised on error.
Network.JsonRpc.Server.onClose
def (self, server)
This method can be rebinded 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.onConnection
def (self, client)
This method can be rebinded 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.onDisconnection
def (self, client)
This method can be rebinded to handle client disconnection events. The
client
parameter is the handler that received the event. This
can be used to cleanup a context.
Network.JsonRpc.Server.onOpen
def (self, server)
This method can be rebinded 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 rebinded 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 underling 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.read
def (self)
Returns the next end point in the connection queue. This method calls the Network.AsynchronousChannel.read method of the underling channel. If there is at least one pending connection in the queue, a call to this method will create a client handler that will be automatically watched by the Network.Scheduler instance.
Network.JsonRpc.Server.removeDefaultAttribute
def (self, name)
Removes the attribute name
used by default created messages.
The remaining attributes will be passed to the
Network.JsonRpc.Message.setAttribute of the default created
messages.
Network.JsonRpc.Server.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.setAttribute
of the default created messages.
Network.JsonRpc.Server.setDefaultAttributes
def (self, attributes)
Sets the attributes used by default created messages to attributes
.
The attributes will be passed to the Network.JsonRpc.Message.setAttribute
of the default created messages.
Network.JsonRpc.Server.setNonBlocking
def (self, enabled)
Sets the non blocking mode of the channel to enabled
. This method
calls the Network.AsynchronousChannel.setNonBlocking method of
the underling 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.unwatch
def (self)
Removes the channel from the Network.Scheduler object. This method calls the Network.Scheduler.remove method.
Network.JsonRpc.Server.watch
def (self)
Adds the channel to the Network.Scheduler object. This method calls the Network.Scheduler.watch method.
An instance of Exception.SocketError is raised on error.