]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/perlmods/OpenSRF/Transport/Jabber/JPeerConnection.pm
Initial revision
[Evergreen.git] / OpenSRF / src / perlmods / OpenSRF / Transport / Jabber / JPeerConnection.pm
1 package OpenSRF::Transport::Jabber::JPeerConnection;
2 use strict;
3 use base qw/OpenSRF::Transport::Jabber::JabberClient/;
4 use OpenSRF::Utils::Config;
5 use OpenSRF::Utils::Logger qw(:level);
6
7 =head1 Description
8
9 Represents a single connection to a remote peer.  The 
10 Jabber values are loaded from the config file.  
11
12 Subclasses OpenSRF::Transport::JabberClient.
13
14 =cut
15
16 =head2 new()
17
18         new( $appname );
19
20         The $appname parameter tells this class how to find the correct
21         Jabber username, password, etc to connect to the server.
22
23 =cut
24
25 our $main_instance;
26 our %apps_hash;
27
28 sub retrieve { 
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};
34 }
35
36
37
38 sub new {
39         my( $class, $app ) = @_;
40         my $config = OpenSRF::Utils::Config->current;
41
42         if( ! $config ) {
43                 throw OpenSRF::EX::Config( "No suitable config found" );
44         }
45
46         my $app_stat    = $app . "_peer";
47         my $host                        = $config->transport->server->primary;
48         my $username    = $config->transport->users->$app;
49         my $password    = $config->transport->auth->password;
50         my $debug               = $config->transport->llevel->$app_stat;
51         my $log                 = $config->transport->log->$app_stat;
52         my $resource    = $config->env->hostname . "_$$";
53
54         OpenSRF::EX::Config->throw( "JPeer could not load all necesarry values from config" )
55                 unless ( $host and $username and $password and $resource );
56
57
58         my $self = __PACKAGE__->SUPER::new( 
59                 username                => $username,
60                 host                    => $host,
61                 resource                => $resource,
62                 password                => $password,
63                 log_file                => $log,
64                 debug                   => $debug,
65                 );      
66                                         
67          bless( $self, $class );
68
69          $self->SetCallBacks( message => sub {
70                          my $msg = $_[1];
71                          OpenSRF::Utils::Logger->transport( 
72                                  "JPeer passing \n$msg \n to Transport->handler for $app", INTERNAL );
73                          OpenSRF::Transport->handler( $app, $msg ); } );
74
75         $apps_hash{$app} = $self;
76         return $apps_hash{$app};
77 }
78         
79 1;
80