From 00a59dcb398fd2a9e7c354ee3c9b426acc22152f Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 16 Feb 2005 17:17:26 +0000 Subject: [PATCH] using new config settings git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@69 9efc2488-bf62-4759-914b-345cdb29e865 --- src/perlmods/OpenSRF/Transport/Listener.pm | 4 +- src/perlmods/OpenSRF/Transport/PeerHandle.pm | 2 +- .../OpenSRF/Transport/SlimJabber/Client.pm | 23 +++---- .../OpenSRF/Transport/SlimJabber/Inbound.pm | 75 ++++++++++++++++------ .../OpenSRF/Transport/SlimJabber/PeerConnection.pm | 42 ++++++++---- 5 files changed, 99 insertions(+), 47 deletions(-) diff --git a/src/perlmods/OpenSRF/Transport/Listener.pm b/src/perlmods/OpenSRF/Transport/Listener.pm index f9de8a4..34e54a4 100644 --- a/src/perlmods/OpenSRF/Transport/Listener.pm +++ b/src/perlmods/OpenSRF/Transport/Listener.pm @@ -1,7 +1,8 @@ package OpenSRF::Transport::Listener; use base 'OpenSRF'; use OpenSRF::Utils::Logger qw(:level); - +use OpenSRF::Transport::SlimJabber::Inbound; +use base 'OpenSRF::Transport::SlimJabber::Inbound'; =head1 Description @@ -29,6 +30,7 @@ superclass and it will be pushed onto @ISA. sub set_listener { my( $class, $listener ) = @_; + OpenSRF::Utils::Logger->transport("Loading Listener $listener", INFO ); if( $listener ) { eval "use $listener;"; if( $@ ) { diff --git a/src/perlmods/OpenSRF/Transport/PeerHandle.pm b/src/perlmods/OpenSRF/Transport/PeerHandle.pm index e0bd53b..b0dc123 100644 --- a/src/perlmods/OpenSRF/Transport/PeerHandle.pm +++ b/src/perlmods/OpenSRF/Transport/PeerHandle.pm @@ -1,7 +1,7 @@ package OpenSRF::Transport::PeerHandle; use OpenSRF::Utils::Logger qw(:level); use OpenSRF::EX; -use base 'OpenSRF'; +use base qw/OpenSRF::Transport::SlimJabber::PeerConnection/; use vars '@ISA'; my $peer; diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm index ddbd231..cdbbee9 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm @@ -1,7 +1,6 @@ package OpenSRF::Transport::SlimJabber::Client; use strict; use warnings; use OpenSRF::EX; -#use Net::Jabber qw( Client ); use base qw( OpenSRF ); use OpenSRF::Utils::Logger qw(:level); use Time::HiRes qw(ualarm); @@ -56,20 +55,11 @@ sub new { $class = ref( $class ) || $class; - my $conf = OpenSRF::Utils::Config->current; - - my $host; - - my $port = $conf->transport->server->port; + my $port = $params{'port'} || return undef; my $username = $params{'username'} || return undef; my $resource = $params{'resource'} || return undef; my $password = $params{'password'} || return undef; - - if( $params{host} ) { - $host = $params{host}; - } else { - $host = $conf->transport->server->system_primary; - } + my $host = $params{'host'} || return undef; my $jid = "$username\@$host\/$resource"; @@ -407,7 +397,13 @@ sub send { "JabberClient Sending message to $to with thread $thread and body: \n$body", INTERNAL ); my $soc = $self->{_socket}; + unless( $soc and $soc->connected ) { + throw OpenSRF::EX::Jabber ("No longer connected to jabber server"); + } print $soc $msg->toString; + + $logger->transport( + "JabberClient Sent message to $to with thread $thread and body: \n$body", INTERNAL ); } @@ -452,10 +448,11 @@ sub initialize { # --- 5 tries to connect to the jabber server my $socket; for(1..5) { - $logger->transport( "$jid: Attempting to connect to server... (Try # $_)", WARN ); + $logger->transport( "$jid: Attempting to connect to server...$host:$port (Try # $_)", WARN ); $socket = IO::Socket::INET->new( PeerHost => $host, PeerPort => $port, Proto => 'tcp' ); + $logger->transport( "$jid: $_ connect attempt to $host:$port", WARN ); last if ( $socket and $socket->connected ); sleep 3; } diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm index 331c9eb..f8c1d09 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm @@ -1,9 +1,10 @@ package OpenSRF::Transport::SlimJabber::Inbound; use strict;use warnings; use base qw/OpenSRF::Transport::SlimJabber::Client/; -use OpenSRF::EX; -use OpenSRF::Utils::Config; +use OpenSRF::EX qw(:try); use OpenSRF::Utils::Logger qw(:level); +use OpenSRF::Utils::SettingsClient; +use OpenSRF::Utils::Config; my $logger = "OpenSRF::Utils::Logger"; @@ -30,32 +31,45 @@ This service should be loaded at system startup. my( $class, $app ) = @_; $class = ref( $class ) || $class; if( ! $instance ) { - my $app_state = $app . "_inbound"; - my $config = OpenSRF::Utils::Config->current; - if( ! $config ) { - throw OpenSRF::EX::Jabber( "No suitable config found" ); + my $client = OpenSRF::Utils::SettingsClient->new(); + + my $transport_info = $client->config_value( + "apps", $app, "transport_hosts", "transport_host" ); + + if( !ref($transport_info) eq "ARRAY" ) { + $transport_info = [$transport_info]; } - my $username = $config->transport->users->$app; - my $password = $config->transport->auth->password; + + # XXX for now, we just try the first host... + + my $username = $transport_info->[0]->{username}; + my $password = $transport_info->[0]->{password}; my $resource = 'system'; + my $host = $transport_info->[0]->{host}; + my $port = $transport_info->[0]->{port}; - if (defined $config->system->router_target) { - $resource .= '_' . $config->env->hostname . "_$$"; + if (defined $client->config_value("router_targets")) { + my $h = OpenSRF::Utils::Config->current->env->hostname; + $resource .= "_$h" . "_$$"; } + OpenSRF::Utils::Logger->transport("Inbound as $username, $password, $resource, $host, $port\n", INTERNAL ); + my $self = __PACKAGE__->SUPER::new( username => $username, resource => $resource, password => $password, + host => $host, + port => $port, ); $self->{app} = $app; - - my $f = $config->dirs->sock_dir; - $unix_sock = join( "/", $f, $config->unix_sock->$app ); + my $f = $client->config_value("dirs", "sock"); + $unix_sock = join( "/", $f, + $client->config_value("apps", $app, "unix_config", "unix_sock" )); bless( $self, $class ); $instance = $self; } @@ -67,15 +81,36 @@ This service should be loaded at system startup. sub listen { my $self = shift; - my $config = OpenSRF::Utils::Config->current; - my $routers = $config->system->router_target; - if (defined $routers) { - for my $router (@$routers) { - $self->send( to => $router, - body => "registering", router_command => "register" , router_class => $self->{app} ); + my $client = OpenSRF::Utils::SettingsClient->new(); + my $routers; + try { + + $routers = $client->config_value("router_targets","router_target"); + $logger->transport( $self->{app} . " connecting to router $routers", INFO ); + + if (defined $routers) { + if( !ref($routers) || !(ref($routers) eq "ARRAY") ) { + $routers = [$routers]; + } + + + for my $router (@$routers) { + $logger->transport( $self->{app} . " connecting to router $router", INFO ); + $self->send( to => $router, + body => "registering", router_command => "register" , router_class => $self->{app} ); + } + $logger->transport( $self->{app} . " :routers connected", INFO ); + } - } + } catch OpenSRF::EX::Config with { + $logger->transport( $self->{app} . ": No routers defined" , WARN ); + # no routers defined + }; + + + + $logger->transport( $self->{app} . " going into listen loop", INFO ); while(1) { my $sock = $self->unix_sock(); my $socket = IO::Socket::UNIX->new( Peer => $sock ); diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm index db969e2..1d065a7 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm @@ -35,35 +35,53 @@ sub retrieve { +# !! In here we use the bootstrap config .... sub new { my( $class, $app ) = @_; my $config = OpenSRF::Utils::Config->current; if( ! $config ) { - throw OpenSRF::EX::Config( "No suitable config found" ); + throw OpenSRF::EX::Config( "No suitable config found for PeerConnection" ); } - my $app_stat = $app . "_peer"; - my $username = $config->transport->users->$app; - my $password = $config->transport->auth->password; - my $resource = $config->env->hostname . "_$$"; - my $server; + my $trans_list = $config->bootstrap->transport; + unless( $trans_list && $trans_list->[0] ) { + throw OpenSRF::EX::Config ("Peer Connection needs transport info"); + } + + # For now we just use the first in the list... + my $trans = $trans_list->[0]; - my $host; - if( $app eq "client" ) { - $host = $config->transport->server->client_primary; + my $username; + if( $app eq "system_client" ) { + $username = $config->$trans->username; } else { - $host = ""; + $username = $app; } + + + 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 $server = $config->$trans->server; + OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->server, INTERNAL ); + my $port = $config->$trans->port; + OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->port, INTERNAL ); + + OpenSRF::EX::Config->throw( "JPeer could not load all necesarry values from config" ) - unless ( $username and $password and $resource ); + unless ( $username and $password and $resource and $server and $port ); + + OpenSRF::Utils::Logger->transport( "Built Peer with", INTERNAL ); my $self = __PACKAGE__->SUPER::new( username => $username, resource => $resource, password => $password, - host => $host, + host => $server, + port => $port, ); bless( $self, $class ); -- 2.11.0