jQluster::Server - jQluster tranport server independent of underlying connection implementation
my @logs = (); my $server = jQluster::Server->new( logger => sub { ## OPTIONAL my ($level, $msg) = @_; push(@logs, [$level, $msg]); } ); $server->register( unique_id => "global unique ID for the connection", message => $registration_message, sender => sub { my ($message) = @_; $some_transport->send($message); } ); $server->distribute($message); $server->unregister($unique_id);
jQluster::Server is part of jQluster project. To learn more about jQluster, visit https://github.com/debug-ito/jQluster.
jQluster::Server accepts connections from jQluster client nodes, receives messages from these nodes and distributes the messages to appropriate destination nodes.
jQluster::Server is independent of connection implementations. It just tells the destination connection's sender routine that it has incoming messages to the connection.
The constructor. Fields in %args are:
%args
logger
A subroutine reference that is called when the $server wants to log something.
$server
The $logger is called like
$logger
$logger->($level, $message)
where $level is a log level string such as "info", "warning", "error" etc. $message is the log message string.
$level
$message
Register a new jQluster connection to a client node.
Fields in %args are:
unique_id
The ID for the new connection. The ID must be unique within the $server. If you try to register an ID that is already registered, it croaks.
message
A jQluster message for registration. The message is usually created by a jQluster client node.
sender
A subroutine reference that is called when the $server sends a message to this connection.
The $sender is called like
$sender
$sender->($jqluster_message)
where $jqluster_message is a jQluster message object. It's a plain hash-ref. It's up to the $sender how to deliver the message to the client node.
$jqluster_message
Distirbute the given jQluster message to destination nodes.
$message is a jQluster message object. It's a plain hash-ref.
Unregister a connection to a client node.
$unique_id is the unique ID you give when calling register() method. If $unique_id is not registered, it does nothing.
$unique_id
register()
Toshio Ito toshioito [at] cpan.org
toshioito [at] cpan.org
To install jQluster::Server::WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm jQluster::Server::WebSocket
CPAN shell
perl -MCPAN -e shell install jQluster::Server::WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.