From: miker Date: Wed, 23 Feb 2005 16:48:38 +0000 (+0000) Subject: using a single jabber connection per process, since we do not actually care about... X-Git-Tag: osrf_rel_2_0_1~1777 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eec0972b20f0c9aaeccd5ec76e1a45db972c79dd;p=OpenSRF.git using a single jabber connection per process, since we do not actually care about the JID we are git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@95 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/perlmods/OpenSRF/System.pm b/src/perlmods/OpenSRF/System.pm index ec2276c..c01d8ea 100644 --- a/src/perlmods/OpenSRF/System.pm +++ b/src/perlmods/OpenSRF/System.pm @@ -162,6 +162,7 @@ sub bootstrap { my $server_type = $client->config_value("server_type"); $server_type ||= "basic"; + OpenSRF::Transport::PeerHandle->retrieve->disconnect; if( $server_type eq "prefork" ) { $server_type = "Net::Server::PreFork"; diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm index cdbbee9..8d1988e 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm @@ -24,12 +24,17 @@ my $logger = "OpenSRF::Utils::Logger"; sub DESTROY{ my $self = shift; + $self->disconnect; +} + +sub disconnect{ + my $self = shift; my $socket = $self->{_socket}; if( $socket and $socket->connected() ) { print $socket ""; close( $socket ); } -}; +} =head2 new() @@ -439,7 +444,7 @@ sub initialize { $username $password -$resource +${resource}_$$ XML diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm index f8c1d09..6d7616d 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm @@ -52,7 +52,7 @@ This service should be loaded at system startup. if (defined $client->config_value("router_targets")) { my $h = OpenSRF::Utils::Config->current->env->hostname; - $resource .= "_$h" . "_$$"; + $resource .= "_$h"; } OpenSRF::Utils::Logger->transport("Inbound as $username, $password, $resource, $host, $port\n", INTERNAL ); diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm index 1d065a7..c615205 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm @@ -24,12 +24,14 @@ Subclasses OpenSRF::Transport::SlimJabber::Client. =cut our %apps_hash; +our $_singleton_connection; sub retrieve { my( $class, $app ) = @_; my @keys = keys %apps_hash; OpenSRF::Utils::Logger->transport( "Requesting peer for $app and we have @keys", INFO ); + return $_singleton_connection; return $apps_hash{$app}; } @@ -38,6 +40,10 @@ sub retrieve { # !! In here we use the bootstrap config .... sub new { my( $class, $app ) = @_; + + my $peer_con = $class->retrieve; + return $peer_con if ($peer_con and $peer_con->tcp_connected); + my $config = OpenSRF::Utils::Config->current; if( ! $config ) { @@ -64,7 +70,7 @@ sub new { my $password = $config->$trans->password; OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->password, INTERNAL ); my $h = $config->env->hostname; - my $resource = "$h" . "_$$"; + my $resource = $h; my $server = $config->$trans->server; OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->server, INTERNAL ); my $port = $config->$trans->port; @@ -88,7 +94,10 @@ sub new { $self->app($app); + $_singleton_connection = $self; $apps_hash{$app} = $self; + + return $_singleton_connection; return $apps_hash{$app}; } diff --git a/src/perlmods/OpenSRF/UnixServer.pm b/src/perlmods/OpenSRF/UnixServer.pm index 5e379f0..64e6292 100644 --- a/src/perlmods/OpenSRF/UnixServer.pm +++ b/src/perlmods/OpenSRF/UnixServer.pm @@ -173,7 +173,7 @@ sub serve { "port $port\npid_file $pid_file\nlog_level 3\n"; open F, "> $file" or die "Can't open $file : $!"; - print F $file_string; + print F $file_string; close F; $self->run( 'conf_file' => $file ); @@ -214,10 +214,9 @@ sub child_init_hook { OpenSRF::Transport::PeerHandle->construct( $self->app() ); $logger->transport( "PeerHandle Created from UnixServer child_init_hook", INTERNAL ); - my $peer_handle = OpenSRF::System::bootstrap_client("system_client"); OpenSRF::Application->application_implementation->child_init if (OpenSRF::Application->application_implementation->can('child_init')); - return $peer_handle; + return OpenSRF::Transport::PeerHandle->retrieve; }