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;
36 my( $class, $app ) = @_;
38 my $peer_con = $class->retrieve;
39 return $peer_con if ($peer_con and $peer_con->tcp_connected);
41 my $config = OpenSRF::Utils::Config->current;
44 throw OpenSRF::EX::Config( "No suitable config found for PeerConnection" );
47 my $conf = OpenSRF::Utils::Config->current;
48 my $domain = $conf->bootstrap->domain;
49 my $h = $conf->env->hostname;
50 OpenSRF::Utils::Logger->error("use of <domains/> is deprecated") if $conf->bootstrap->domains;
52 my $username = $conf->bootstrap->username;
53 my $password = $conf->bootstrap->passwd;
54 my $port = $conf->bootstrap->port;
55 my $resource = "${app}_drone_at_$h";
56 my $host = $domain; # XXX for now...
58 if( $app eq "client" ) { $resource = "client_at_$h"; }
60 OpenSRF::EX::Config->throw( "JPeer could not load all necessary values from config" )
61 unless ( $username and $password and $resource and $host and $port );
63 my $self = __PACKAGE__->SUPER::new(
64 username => $username,
65 resource => $resource,
66 password => $password,
71 bless( $self, $class );
75 $_singleton_connection = $self;
76 $apps_hash{$app} = $self;
78 return $_singleton_connection;
79 return $apps_hash{$app};
84 my $val = $self->SUPER::process(@_);
86 return OpenSRF::Transport->handler($self->app, $val);
92 $self->{app} = $app if $app;