1 package OpenSRF::Transport::SlimJabber::Inbound;
2 use strict;use warnings;
3 use base qw/OpenSRF::Transport::SlimJabber::Client/;
4 use OpenSRF::EX qw(:try);
5 use OpenSRF::Utils::Logger qw(:level);
6 use OpenSRF::Utils::SettingsClient;
7 use OpenSRF::Utils::Config;
8 use Time::HiRes qw/usleep/;
10 my $logger = "OpenSRF::Utils::Logger";
14 This is the jabber connection where all incoming client requests will be accepted.
15 This connection takes the data, passes it off to the system then returns to take
16 more data. Connection params are all taken from the config file and the values
17 retreived are based on the $app name passed into new().
19 This service should be loaded at system startup.
23 # XXX This will be overhauled to connect as a component instead of as
24 # a user. all in good time, though.
28 sub unix_sock { return $unix_sock; }
32 my( $class, $app ) = @_;
33 $class = ref( $class ) || $class;
36 my $conf = OpenSRF::Utils::Config->current;
37 my $domain = $conf->bootstrap->domain;
38 $logger->error("use of <domains/> is deprecated") if $conf->bootstrap->domains;
40 my $username = $conf->bootstrap->username;
41 my $password = $conf->bootstrap->passwd;
42 my $port = $conf->bootstrap->port;
44 my $resource = $app . '_listener_at_' . $conf->env->hostname;
46 my $router_name = $conf->bootstrap->router_name;
47 # no router, only one listener running..
53 OpenSRF::Utils::Logger->transport("Inbound as $username, $password, $resource, $host, $port\n", INTERNAL );
55 my $self = __PACKAGE__->SUPER::new(
56 username => $username,
57 resource => $resource,
58 password => $password,
65 my $client = OpenSRF::Utils::SettingsClient->new();
66 my $f = $client->config_value("dirs", "sock");
67 $unix_sock = join( "/", $f,
68 $client->config_value("apps", $app, "unix_config", "unix_sock" ));
69 bless( $self, $class );
79 for my $router (@{$self->{routers}}) {
80 if($self->tcp_connected()) {
81 $logger->info("disconnecting from router $router");
82 $self->send( to => $router, body => "registering",
83 router_command => "unregister" , router_class => $self->{app} );
91 $self->{routers} = [];
95 my $conf = OpenSRF::Utils::Config->current;
96 my $router_name = $conf->bootstrap->router_name;
97 my $routers = $conf->bootstrap->routers;
98 $logger->info("loading router info $routers");
100 for my $router (@$routers) {
103 if( !$router->{services} || grep { $_ eq $self->{app} } @{$router->{services}->{service}} ) {
104 my $name = $router->{name};
105 my $domain = $router->{domain};
106 my $target = "$name\@$domain/router";
107 push(@{$self->{routers}}, $target);
108 $logger->info( $self->{app} . " connecting to router $target");
109 $self->send( to => $target, body => "registering", router_command => "register" , router_class => $self->{app} );
112 my $target = "$router_name\@$router/router";
113 push(@{$self->{routers}}, $target);
114 $logger->info( $self->{app} . " connecting to router $target");
115 $self->send( to => $target, body => "registering", router_command => "register" , router_class => $self->{app} );
120 $logger->transport( $self->{app} . ": No routers defined" , WARN );
127 $logger->transport( $self->{app} . " going into listen loop", INFO );
131 my $sock = $self->unix_sock();
134 $logger->debug("Inbound listener calling process()");
137 $o = $self->process( -1 );
139 $logger->debug("Inbound listener received ".length($o)." bytes of data");
143 "Inbound received no data from the Jabber socket in process()");
144 usleep(100000); # otherwise we loop and pound syslog logger with errors
147 } catch OpenSRF::EX::JabberDisconnected with {
149 $logger->error("Inbound process lost its ".
150 "jabber connection. Attempting to reconnect...");
157 my $socket = IO::Socket::UNIX->new( Peer => $sock );
158 throw OpenSRF::EX::Socket(
159 "Unable to connect to UnixServer: socket-file: $sock \n :=> $! " )
160 unless ($socket->connected);
166 throw OpenSRF::EX::Socket( "How did we get here?!?!" );