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 return $_singleton_connection;
32 # my @keys = keys %apps_hash;
33 # OpenSRF::Utils::Logger->transport(
34 # "Requesting peer for $app and we have @keys", INFO );
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 $conf = OpenSRF::Utils::Config->current;
54 my $domains = $conf->bootstrap->domains;
55 my $h = $conf->env->hostname;
57 my $username = $conf->bootstrap->username;
58 my $password = $conf->bootstrap->passwd;
59 my $port = $conf->bootstrap->port;
60 my $resource = "${app}_drone_at_$h";
61 my $host = $domains->[0]; # XXX for now...
63 if( $app eq "client" ) { $resource = "client_at_$h"; }
65 unless ( $conf->bootstrap->router_name ) {
71 OpenSRF::EX::Config->throw( "JPeer could not load all necesarry values from config" )
72 unless ( $username and $password and $resource and $host and $port );
74 OpenSRF::Utils::Logger->transport( "Built Peer with", INTERNAL );
76 my $self = __PACKAGE__->SUPER::new(
77 username => $username,
78 resource => $resource,
79 password => $password,
84 bless( $self, $class );
88 $_singleton_connection = $self;
89 $apps_hash{$app} = $self;
91 return $_singleton_connection;
92 return $apps_hash{$app};
98 my $val = $self->SUPER::process(@_);
101 OpenSRF::Utils::Logger->transport( "Calling transport handler for ".$self->app." with: $val", INTERNAL );
103 $t = OpenSRF::Transport->handler($self->app, $val);
112 OpenSRF::Utils::Logger->transport( "PEER changing app to $app: ".$self->jid, INTERNAL );
115 $self->{app} = $app if ($app);