X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FHandle.pm;h=782ddf678819721ac07f89b90e2167719f84bbd6;hp=40584b5c80a42e9e25c13b2d56d77e376ed9f417;hb=bef36e73e4257b2ba8e59eb55661ffc51d8a620a;hpb=901159798e5541050b7c3357a7148818610a4019 diff --git a/lib/Object/Remote/Handle.pm b/lib/Object/Remote/Handle.pm index 40584b5..782ddf6 100644 --- a/lib/Object/Remote/Handle.pm +++ b/lib/Object/Remote/Handle.pm @@ -2,17 +2,15 @@ package Object::Remote::Handle; use Object::Remote::Proxy; use Scalar::Util qw(weaken blessed); -use Object::Remote::Logging qw ( :log ); +use Object::Remote::Logging qw ( :log :dlog router ); use Object::Remote::Future; -#must find way to exclude certain log events -#from being forwarded - log events generated in -#response to log events cause exploding -#use Object::Remote::Logging qw(:log); use Module::Runtime qw(use_module); use Moo; +BEGIN { router()->exclude_forwarding } + has connection => ( - is => 'ro', required => 1, + is => 'ro', required => 1, handles => ['is_valid'], coerce => sub { blessed($_[0]) ? $_[0] @@ -32,7 +30,7 @@ sub proxy { sub BUILD { my ($self, $args) = @_; - log_debug { "constructing remote handle" }; + log_trace { "constructing remote handle" }; if ($self->id) { log_trace { "disarming free for this handle" }; $self->disarm_free; @@ -49,17 +47,21 @@ sub BUILD { )->{remote}->disarm_free->id ); } - log_trace { "finished constructing remote handle; registering it " . ref($self) }; + Dlog_trace { "finished constructing remote handle; id is $_" } $self->id; $self->connection->register_remote($self); } sub call { my ($self, $method, @args) = @_; my $w = wantarray; - log_debug { my $def = defined $w ? 1 : 0; "call() has been invoked on a remote handle; wantarray: '$def'" }; + my $id = $self->id; + $method = "start::${method}" if (caller(0)||'') eq 'start'; + log_trace { "call('$method') has been invoked on remote handle '$id'; creating future" }; + future { - $self->connection->send(call => $self->id, $w, $method, @args) + log_debug { "Invoking send on connection for handle '$id' method '$method'" }; + $self->connection->send(call => $id, $w, $method, @args) }; } @@ -78,9 +80,13 @@ sub call_discard_free { sub DEMOLISH { my ($self, $gd) = @_; - log_trace { "Demolishing remote handle" }; + Dlog_trace { "Demolishing remote handle $_" } $self->id; return if $gd or $self->disarmed_free; - $self->connection->send_free($self->id); + #this could happen after the connection has gone away + eval { $self->connection->send_free($self->id) }; + if ($@ && $@ !~ m/^Attempt to invoke _send on a connection that is not valid/) { + die "Could not invoke send_free on connection for handle " . $self->id; + } } 1;