[OpenSRF-GIT] OpenSRF branch master updated. 168b4cafe766ec976e075ec2ea496c00a27dc7d0
Evergreen Git
git at git.evergreen-ils.org
Tue Nov 1 17:23:10 EDT 2016
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenSRF".
The branch, master has been updated
via 168b4cafe766ec976e075ec2ea496c00a27dc7d0 (commit)
via 31a0bfea9911f24f563d70bfdea6ba7759071842 (commit)
via 1431100b4737a61b1a294bbf66f9a5867dec358b (commit)
via 9d106aef9ab0a8d5af75977ffb4cc5f8f3fe5c79 (commit)
from dbf9ec150dfa6a5b87028aa890a80b529dfe5683 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 168b4cafe766ec976e075ec2ea496c00a27dc7d0
Author: Galen Charlton <gmc at esilibrary.com>
Date: Tue Nov 1 17:22:48 2016 -0400
LP#1631522: add release notes for ->dispatch
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
diff --git a/doc/Dispatch-Mode-for-Subrequests.txt b/doc/Dispatch-Mode-for-Subrequests.txt
new file mode 100644
index 0000000..6b3a121
--- /dev/null
+++ b/doc/Dispatch-Mode-for-Subrequests.txt
@@ -0,0 +1,12 @@
+Dispatch mode for method_lookup Subrequests
+===========================================
+
+There is a pattern in the wild of using OpenSRF's method_lookup() facility
+to decide between one of several local methods when delegating to pre-existing
+logic. Often times, we want to simply hand control over to another method,
+but the output of a subrequest's run() is an array of results. The caller has
+to know if, and how, to restructure the result for the client.
+
+Instead, we can now call dispatch() instead of run() and have OpenSRF session
+control completely passed to the delegate code. This way, the delegate code
+need not know anything about its caller, and vice versa.
commit 31a0bfea9911f24f563d70bfdea6ba7759071842
Author: Galen Charlton <gmc at esilibrary.com>
Date: Tue Nov 1 17:20:49 2016 -0400
LP#1631522: dev doc now describes ->dispatch
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
diff --git a/doc/Application-HOWTO.txt b/doc/Application-HOWTO.txt
index 41deae1..36e508d 100644
--- a/doc/Application-HOWTO.txt
+++ b/doc/Application-HOWTO.txt
@@ -22,8 +22,12 @@ sends to the client:
my ($subresult) = $meth->run( @params )
# runs the subrequest method and returns the array of
- # results
+ # results
+ return $meth->dispatch( @params )
+ # like ->run, but control of the session is passed to
+ # to the delegated method, whose responses are sent
+ # directly to the original client
The method is also handed an OpenSRF::AppRequest object that has been
constructed for the client request that generated the call to the method.
commit 1431100b4737a61b1a294bbf66f9a5867dec358b
Author: Galen Charlton <gmc at esilibrary.com>
Date: Tue Nov 1 17:03:03 2016 -0400
LP#1631522: include example of ->dispatch in example app
This patch also makes the Perl opensrf.math demo app work
correctly, as it hadn't been constructing opensrf.dbmath
method names correctly.
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
diff --git a/src/perl/lib/OpenSRF/Application/Demo/Math.pm b/src/perl/lib/OpenSRF/Application/Demo/Math.pm
index 7f41456..9e53dcb 100644
--- a/src/perl/lib/OpenSRF/Application/Demo/Math.pm
+++ b/src/perl/lib/OpenSRF/Application/Demo/Math.pm
@@ -20,7 +20,7 @@ sub send_request {
my @params = @_;
my $session = OpenSRF::AppSession->create( "opensrf.dbmath" );
- my $request = $session->request( "dbmath.$method_name", @params );
+ my $request = $session->request( "$method_name", @params );
my $response = $request->recv();
if(!$response) { return undef; }
if($response->isa("Error")) {throw $response ($response->stringify);}
@@ -37,10 +37,9 @@ sub add_1 {
my $client = shift;
my @args = @_;
- my $meth = $self->method_lookup('_send_request');
- my ($result) = $meth->run('add', at args);
-
- return $result;
+ # use ->dispatch rather than run; results of the delegated
+ # method will be directly passed to the caller
+ return $self->method_lookup('_send_request')->dispatch('add', @args);
}
__PACKAGE__->register_method( method => 'sub_1', api_name => 'sub' );
commit 9d106aef9ab0a8d5af75977ffb4cc5f8f3fe5c79
Author: Mike Rylander <mrylander at gmail.com>
Date: Thu Aug 25 17:42:31 2016 -0400
LP#1631522: Dispatch mode for method_lookup subrequests
There is a pattern in the wild of using OpenSRF's method_lookup() facility
to decide between one of several local methods when delegating to pre-existing
logic. Often times, we want to simply hand control over to another method,
but the output of a subrequest's run() is an array of results. The caller has
to know if, and how, to restructure the result for the client.
Instead, we can now call dispatch() instead of run() and have OpenSRF session
control completely passed to the delegate code. This way, the delegate code
need not know anything about its caller, and vice versa.
Signed-off-by: Mike Rylander <mrylander at gmail.com>
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
diff --git a/src/perl/lib/OpenSRF/AppSession.pm b/src/perl/lib/OpenSRF/AppSession.pm
index ba3aa54..158513b 100644
--- a/src/perl/lib/OpenSRF/AppSession.pm
+++ b/src/perl/lib/OpenSRF/AppSession.pm
@@ -1135,29 +1135,54 @@ sub gather {
package OpenSRF::AppSubrequest;
+use base 'OpenSRF::AppRequest';
sub respond {
my $self = shift;
return if $self->complete;
my $resp = shift;
+ return $self->SUPER::respond($resp) if $self->respond_directly;
+
push @{$$self{resp}}, $resp if (defined $resp);
}
sub respond_complete {
my $self = shift;
+ return $self->SUPER::respond_complete(@_) if $self->respond_directly;
$self->respond(@_);
$self->complete(1);
}
sub new {
- my $class = shift;
- $class = ref($class) || $class;
- return bless({complete => 0, resp => [], @_}, $class);
+ my $class = shift;
+ $class = ref($class) || $class;
+ my $self = bless({
+ complete => 0,
+ respond_directly=> 0, # use the passed session directly (RD mode)
+ resp => [],
+ threadTrace => 0, # needed for respond in RD mode
+ max_chunk_count => 0, # needed for respond in RD mode
+ max_chunk_size => 0, # needed for respond in RD mode
+ current_chunk => [], # needed for respond_complete in RD mode
+ @_
+ }, $class);
+ if ($self->session) {
+ # steal the thread trace from the parent session for RD mode
+ $self->{threadTrace} = $self->session->session_threadTrace || $self->session->last_threadTrace;
+ }
+ return $self;
}
sub responses { @{$_[0]->{resp}} }
+sub respond_directly {
+ my $x = shift;
+ my $s = shift;
+ $x->{respond_directly} = $s if (defined $s);
+ return $x->session && $x->{respond_directly};
+}
+
sub session {
my $x = shift;
my $s = shift;
diff --git a/src/perl/lib/OpenSRF/Application.pm b/src/perl/lib/OpenSRF/Application.pm
index 9a958e0..5d01cb5 100644
--- a/src/perl/lib/OpenSRF/Application.pm
+++ b/src/perl/lib/OpenSRF/Application.pm
@@ -576,6 +576,13 @@ sub method_lookup {
return $meth;
}
+sub dispatch {
+ my $self = shift;
+ $log->debug("Creating a dispatching SubRequest object", DEBUG);
+ my $req = OpenSRF::AppSubrequest->new( session => $self->session, respond_directly => 1 );
+ return $self->run($req, at _);
+}
+
sub run {
my $self = shift;
my $req = shift;
@@ -627,7 +634,7 @@ sub run {
$log->debug("Coderef for [$$self{package}::$$self{method}] has been run", DEBUG);
- if ( ref($req) and UNIVERSAL::isa($req, 'OpenSRF::AppSubrequest') ) {
+ if ( ref($req) and UNIVERSAL::isa($req, 'OpenSRF::AppSubrequest') and !$req->respond_directly ) {
$req->respond($resp) if (defined $resp);
$log->debug("SubRequest object is responding with : " . join(" ",$req->responses), DEBUG);
return $req->responses;
-----------------------------------------------------------------------
Summary of changes:
doc/Application-HOWTO.txt | 6 ++++-
doc/Dispatch-Mode-for-Subrequests.txt | 12 +++++++++
src/perl/lib/OpenSRF/AppSession.pm | 31 ++++++++++++++++++++++--
src/perl/lib/OpenSRF/Application.pm | 9 ++++++-
src/perl/lib/OpenSRF/Application/Demo/Math.pm | 9 +++----
5 files changed, 57 insertions(+), 10 deletions(-)
create mode 100644 doc/Dispatch-Mode-for-Subrequests.txt
hooks/post-receive
--
OpenSRF
More information about the opensrf-commits
mailing list