using a single jabber connection per process, since we do not actually care about...
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 23 Feb 2005 16:48:38 +0000 (16:48 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 23 Feb 2005 16:48:38 +0000 (16:48 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@95 9efc2488-bf62-4759-914b-345cdb29e865

src/perlmods/OpenSRF/System.pm
src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm
src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm
src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm
src/perlmods/OpenSRF/UnixServer.pm

index ec2276c..c01d8ea 100644 (file)
@@ -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"; 
index cdbbee9..8d1988e 100644 (file)
@@ -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 "</stream:stream>";
                close( $socket );
        }
-};
+}
 
 
 =head2 new()
@@ -439,7 +444,7 @@ sub initialize {
 <query xmlns='jabber:iq:auth'>
 <username>$username</username>
 <password>$password</password>
-<resource>$resource</resource>
+<resource>${resource}_$$</resource>
 </query>
 </iq>
        XML
index f8c1d09..6d7616d 100644 (file)
@@ -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 );
index 1d065a7..c615205 100644 (file)
@@ -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};
 }
 
index 5e379f0..64e6292 100644 (file)
@@ -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;
 
 }