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";
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()
<query xmlns='jabber:iq:auth'>
<username>$username</username>
<password>$password</password>
-<resource>$resource</resource>
+<resource>${resource}_$$</resource>
</query>
</iq>
XML
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 );
=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};
}
# !! 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 ) {
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;
$self->app($app);
+ $_singleton_connection = $self;
$apps_hash{$app} = $self;
+
+ return $_singleton_connection;
return $apps_hash{$app};
}
"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 );
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;
}