package OpenSRF::Transport::SlimJabber::Client;
use strict; use warnings;
use OpenSRF::EX;
-#use Net::Jabber qw( Client );
use base qw( OpenSRF );
use OpenSRF::Utils::Logger qw(:level);
use Time::HiRes qw(ualarm);
$class = ref( $class ) || $class;
- my $conf = OpenSRF::Utils::Config->current;
-
- my $host;
-
- my $port = $conf->transport->server->port;
+ my $port = $params{'port'} || return undef;
my $username = $params{'username'} || return undef;
my $resource = $params{'resource'} || return undef;
my $password = $params{'password'} || return undef;
-
- if( $params{host} ) {
- $host = $params{host};
- } else {
- $host = $conf->transport->server->system_primary;
- }
+ my $host = $params{'host'} || return undef;
my $jid = "$username\@$host\/$resource";
"JabberClient Sending message to $to with thread $thread and body: \n$body", INTERNAL );
my $soc = $self->{_socket};
+ unless( $soc and $soc->connected ) {
+ throw OpenSRF::EX::Jabber ("No longer connected to jabber server");
+ }
print $soc $msg->toString;
+
+ $logger->transport(
+ "JabberClient Sent message to $to with thread $thread and body: \n$body", INTERNAL );
}
# --- 5 tries to connect to the jabber server
my $socket;
for(1..5) {
- $logger->transport( "$jid: Attempting to connect to server... (Try # $_)", WARN );
+ $logger->transport( "$jid: Attempting to connect to server...$host:$port (Try # $_)", WARN );
$socket = IO::Socket::INET->new( PeerHost => $host,
PeerPort => $port,
Proto => 'tcp' );
+ $logger->transport( "$jid: $_ connect attempt to $host:$port", WARN );
last if ( $socket and $socket->connected );
sleep 3;
}
package OpenSRF::Transport::SlimJabber::Inbound;
use strict;use warnings;
use base qw/OpenSRF::Transport::SlimJabber::Client/;
-use OpenSRF::EX;
-use OpenSRF::Utils::Config;
+use OpenSRF::EX qw(:try);
use OpenSRF::Utils::Logger qw(:level);
+use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::Config;
my $logger = "OpenSRF::Utils::Logger";
my( $class, $app ) = @_;
$class = ref( $class ) || $class;
if( ! $instance ) {
- my $app_state = $app . "_inbound";
- my $config = OpenSRF::Utils::Config->current;
- if( ! $config ) {
- throw OpenSRF::EX::Jabber( "No suitable config found" );
+ my $client = OpenSRF::Utils::SettingsClient->new();
+
+ my $transport_info = $client->config_value(
+ "apps", $app, "transport_hosts", "transport_host" );
+
+ if( !ref($transport_info) eq "ARRAY" ) {
+ $transport_info = [$transport_info];
}
- my $username = $config->transport->users->$app;
- my $password = $config->transport->auth->password;
+
+ # XXX for now, we just try the first host...
+
+ my $username = $transport_info->[0]->{username};
+ my $password = $transport_info->[0]->{password};
my $resource = 'system';
+ my $host = $transport_info->[0]->{host};
+ my $port = $transport_info->[0]->{port};
- if (defined $config->system->router_target) {
- $resource .= '_' . $config->env->hostname . "_$$";
+ if (defined $client->config_value("router_targets")) {
+ my $h = OpenSRF::Utils::Config->current->env->hostname;
+ $resource .= "_$h" . "_$$";
}
+ OpenSRF::Utils::Logger->transport("Inbound as $username, $password, $resource, $host, $port\n", INTERNAL );
+
my $self = __PACKAGE__->SUPER::new(
username => $username,
resource => $resource,
password => $password,
+ host => $host,
+ port => $port,
);
$self->{app} = $app;
-
- my $f = $config->dirs->sock_dir;
- $unix_sock = join( "/", $f, $config->unix_sock->$app );
+ my $f = $client->config_value("dirs", "sock");
+ $unix_sock = join( "/", $f,
+ $client->config_value("apps", $app, "unix_config", "unix_sock" ));
bless( $self, $class );
$instance = $self;
}
sub listen {
my $self = shift;
- my $config = OpenSRF::Utils::Config->current;
- my $routers = $config->system->router_target;
- if (defined $routers) {
- for my $router (@$routers) {
- $self->send( to => $router,
- body => "registering", router_command => "register" , router_class => $self->{app} );
+ my $client = OpenSRF::Utils::SettingsClient->new();
+ my $routers;
+ try {
+
+ $routers = $client->config_value("router_targets","router_target");
+ $logger->transport( $self->{app} . " connecting to router $routers", INFO );
+
+ if (defined $routers) {
+ if( !ref($routers) || !(ref($routers) eq "ARRAY") ) {
+ $routers = [$routers];
+ }
+
+
+ for my $router (@$routers) {
+ $logger->transport( $self->{app} . " connecting to router $router", INFO );
+ $self->send( to => $router,
+ body => "registering", router_command => "register" , router_class => $self->{app} );
+ }
+ $logger->transport( $self->{app} . " :routers connected", INFO );
+
}
- }
+ } catch OpenSRF::EX::Config with {
+ $logger->transport( $self->{app} . ": No routers defined" , WARN );
+ # no routers defined
+ };
+
+
+
+ $logger->transport( $self->{app} . " going into listen loop", INFO );
while(1) {
my $sock = $self->unix_sock();
my $socket = IO::Socket::UNIX->new( Peer => $sock );
+# !! In here we use the bootstrap config ....
sub new {
my( $class, $app ) = @_;
my $config = OpenSRF::Utils::Config->current;
if( ! $config ) {
- throw OpenSRF::EX::Config( "No suitable config found" );
+ throw OpenSRF::EX::Config( "No suitable config found for PeerConnection" );
}
- my $app_stat = $app . "_peer";
- my $username = $config->transport->users->$app;
- my $password = $config->transport->auth->password;
- my $resource = $config->env->hostname . "_$$";
- my $server;
+ my $trans_list = $config->bootstrap->transport;
+ unless( $trans_list && $trans_list->[0] ) {
+ throw OpenSRF::EX::Config ("Peer Connection needs transport info");
+ }
+
+ # For now we just use the first in the list...
+ my $trans = $trans_list->[0];
- my $host;
- if( $app eq "client" ) {
- $host = $config->transport->server->client_primary;
+ my $username;
+ if( $app eq "system_client" ) {
+ $username = $config->$trans->username;
} else {
- $host = "";
+ $username = $app;
}
+
+
+ my $password = $config->$trans->password;
+ OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->password, INTERNAL );
+ my $h = $config->env->hostname;
+ my $resource = "$h" . "_$$";
+ my $server = $config->$trans->server;
+ OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->server, INTERNAL );
+ my $port = $config->$trans->port;
+ OpenSRF::Utils::Logger->transport( "Building Peer with " .$config->$trans->port, INTERNAL );
+
+
OpenSRF::EX::Config->throw( "JPeer could not load all necesarry values from config" )
- unless ( $username and $password and $resource );
+ unless ( $username and $password and $resource and $server and $port );
+
+ OpenSRF::Utils::Logger->transport( "Built Peer with", INTERNAL );
my $self = __PACKAGE__->SUPER::new(
username => $username,
resource => $resource,
password => $password,
- host => $host,
+ host => $server,
+ port => $port,
);
bless( $self, $class );