1 package OpenSRF::Transport::SlimJabber::PeerConnection;
3 use base qw/OpenSRF::Transport::SlimJabber::Client/;
4 use OpenSRF::Utils::Config;
5 use OpenSRF::Utils::Logger qw(:level);
6 use OpenSRF::EX qw/:try/;
10 Represents a single connection to a remote peer. The
11 Jabber values are loaded from the config file.
13 Subclasses OpenSRF::Transport::SlimJabber::Client.
21 The $appname parameter tells this class how to find the correct
22 Jabber username, password, etc to connect to the server.
27 our $_singleton_connection;
30 my( $class, $app ) = @_;
31 my @keys = keys %apps_hash;
32 OpenSRF::Utils::Logger->transport(
33 "Requesting peer for $app and we have @keys", INFO );
34 return $_singleton_connection;
35 return $apps_hash{$app};
40 # !! In here we use the bootstrap config ....
42 my( $class, $app ) = @_;
44 my $peer_con = $class->retrieve;
45 return $peer_con if ($peer_con and $peer_con->tcp_connected);
47 my $config = OpenSRF::Utils::Config->current;
50 throw OpenSRF::EX::Config( "No suitable config found for PeerConnection" );
53 my $trans_list = $config->bootstrap->transport;
54 unless( $trans_list && $trans_list->[0] ) {
55 throw OpenSRF::EX::Config ("Peer Connection needs transport info");
58 # For now we just use the first in the list...
59 my $trans = $trans_list->[0];
62 if( $app eq "system_client" ) {
63 $username = $config->$trans->username;
70 my $password = $config->$trans->password;
71 OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->password, INTERNAL );
72 my $h = $config->env->hostname;
74 my $server = $config->$trans->server;
75 OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->server, INTERNAL );
76 my $port = $config->$trans->port;
77 OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->port, INTERNAL );
80 OpenSRF::EX::Config->throw( "JPeer could not load all necesarry values from config" )
81 unless ( $username and $password and $resource and $server and $port );
83 OpenSRF::Utils::Logger->transport( "Built Peer with", INTERNAL );
85 my $self = __PACKAGE__->SUPER::new(
86 username => $username,
87 resource => $resource,
88 password => $password,
93 bless( $self, $class );
97 $_singleton_connection = $self;
98 $apps_hash{$app} = $self;
100 return $_singleton_connection;
101 return $apps_hash{$app};
106 my $val = $self->SUPER::process(@_);
107 return 0 unless $val;
108 OpenSRF::Utils::Logger->transport( "Calling transport handler for ".$self->app." with: $val", INTERNAL );
111 $t = OpenSRF::Transport->handler($self->app, $val);
113 # } catch OpenSRF::EX with {
117 # } catch Error with { return undef; }
126 OpenSRF::Utils::Logger->transport( "PEER changing app to $app: ".$self->jid, INTERNAL );
129 $self->{app} = $app if ($app);