NAME
jQluster::Server - jQluster tranport server independent of underlying connection implementation
SYNOPSIS
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);
DESCRIPTION
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.
CLASS METHODS
$server = jQluster::Server->new(%args)
The constructor. Fields in %args are:
logger=> CODE (optional, default: log nothing)-
A subroutine reference that is called when the
$serverwants to log something.The
$loggeris called like$logger->($level, $message)where
$levelis a log level string such as "info", "warning", "error" etc.$messageis the log message string.
OBJECT METHODS
$server->register(%args)
Register a new jQluster connection to a client node.
Fields in %args are:
unique_id=> ID (mandatory)-
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=> jQluster MESSAGE HASH (mandatory)-
A jQluster message for registration. The message is usually created by a jQluster client node.
sender=> CODE (mandatory)-
A subroutine reference that is called when the
$serversends a message to this connection.The
$senderis called like$sender->($jqluster_message)where
$jqluster_messageis a jQluster message object. It's a plain hash-ref. It's up to the$senderhow to deliver the message to the client node.
$server->distribute($message)
Distirbute the given jQluster message to destination nodes.
$message is a jQluster message object. It's a plain hash-ref.
$server->unregister($unique_id)
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.
AUTHOR
Toshio Ito toshioito [at] cpan.org