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", INTERNAL );
33 return $apps_hash{$app};
39 my( $class, $app ) = @_;
40 my $config = OpenSRF::Utils::Config->current;
43 throw OpenSRF::EX::Config( "No suitable config found" );
46 my $app_stat = $app . "_peer";
47 my $username = $config->transport->users->$app;
48 my $password = $config->transport->auth->password;
49 my $resource = $config->env->hostname . "_$$";
51 OpenSRF::EX::Config->throw( "JPeer could not load all necesarry values from config" )
52 unless ( $username and $password and $resource );
55 my $self = __PACKAGE__->SUPER::new(
56 username => $username,
57 resource => $resource,
58 password => $password,
61 bless( $self, $class );
65 $apps_hash{$app} = $self;
66 return $apps_hash{$app};
71 my $val = $self->SUPER::process(@_);
73 OpenSRF::Utils::Logger->transport( "Calling transport handler for ".$self->app." with: $val", INTERNAL );
76 $t = OpenSRF::Transport->handler($self->app, $val);
78 # } catch OpenSRF::EX with {
82 # } catch Error with { return undef; }
91 OpenSRF::Utils::Logger->transport( "PEER changing app to $app: ".$self->jid, INTERNAL );
94 $self->{app} = $app if ($app);