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.
29 my( $class, $app ) = @_;
30 my @keys = keys %apps_hash;
31 OpenSRF::Utils::Logger->transport(
32 "Requesting peer for $app and we have @keys", INFO );
33 return $apps_hash{$app};
38 # !! In here we use the bootstrap config ....
40 my( $class, $app ) = @_;
41 my $config = OpenSRF::Utils::Config->current;
44 throw OpenSRF::EX::Config( "No suitable config found for PeerConnection" );
47 my $trans_list = $config->bootstrap->transport;
48 unless( $trans_list && $trans_list->[0] ) {
49 throw OpenSRF::EX::Config ("Peer Connection needs transport info");
52 # For now we just use the first in the list...
53 my $trans = $trans_list->[0];
56 if( $app eq "system_client" ) {
57 $username = $config->$trans->username;
64 my $password = $config->$trans->password;
65 OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->password, INTERNAL );
66 my $h = $config->env->hostname;
67 my $resource = "$h" . "_$$";
68 my $server = $config->$trans->server;
69 OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->server, INTERNAL );
70 my $port = $config->$trans->port;
71 OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->port, INTERNAL );
74 OpenSRF::EX::Config->throw( "JPeer could not load all necesarry values from config" )
75 unless ( $username and $password and $resource and $server and $port );
77 OpenSRF::Utils::Logger->transport( "Built Peer with", INTERNAL );
79 my $self = __PACKAGE__->SUPER::new(
80 username => $username,
81 resource => $resource,
82 password => $password,
87 bless( $self, $class );
91 $apps_hash{$app} = $self;
92 return $apps_hash{$app};
97 my $val = $self->SUPER::process(@_);
99 OpenSRF::Utils::Logger->transport( "Calling transport handler for ".$self->app." with: $val", INTERNAL );
102 $t = OpenSRF::Transport->handler($self->app, $val);
104 # } catch OpenSRF::EX with {
108 # } catch Error with { return undef; }
117 OpenSRF::Utils::Logger->transport( "PEER changing app to $app: ".$self->jid, INTERNAL );
120 $self->{app} = $app if ($app);