Skip to content
Snippets Groups Projects
Commit f12b73bc authored by Yuriy Nevinitsin's avatar Yuriy Nevinitsin
Browse files

Merge branch 'perl-iproto-async'

parents f5c82683 e9f6ed35
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,14 @@ Or asynchronously:
$client->send($request, $callback);
# callback is called when reply is received or error is occured
It is recommended to disconnect all connections in child after fork() to
prevent possible conflicts:
my $pid = fork();
if ($pid == 0) {
MR::IProto->disconnect_all();
}
=head1 DESCRIPTION
This client is used to communicate with cluster of balanced servers using
......@@ -334,6 +342,18 @@ sub SetTimeout {
return;
}
=item disconnect_all
Class method used to disconnect all iproto-connections. Very useful in case of fork().
=cut
sub disconnect_all {
my ($class) = @_;
MR::IProto::Cluster::Server->disconnect_all();
return;
}
=back
=head1 PROTECTED METHODS
......
......@@ -12,6 +12,7 @@ This class is used to implement all communication with one server.
use Mouse;
use Mouse::Util::TypeConstraints;
use Scalar::Util;
use MR::IProto::Connection::Async;
use MR::IProto::Connection::Sync;
use MR::IProto::Message;
......@@ -170,14 +171,48 @@ has sync => (
lazy_build => 1,
);
my %servers;
=back
=head1 PUBLIC METHODS
=over
=item disconnect_all
Class method used to disconnect all iproto-connections. Very useful in case of fork().
=cut
sub disconnect_all {
my ($class) = @_;
foreach my $server (values %servers) {
$server->clear_async();
$server->clear_sync();
}
return;
}
=head1 PROTECTED METHODS
=over
=cut
sub BUILD {
my ($self) = @_;
$servers{Scalar::Util::refaddr($self)} = $self;
Scalar::Util::weaken($servers{Scalar::Util::refaddr($self)});
return;
}
sub DEMOLISH {
my ($self) = @_;
delete $servers{Scalar::Util::refaddr($self)};
return;
}
sub _build_async {
my ($self) = @_;
return MR::IProto::Connection::Async->new( server => $self );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment