File: | blib/lib/OpenSRF/System.pm |
Coverage: | 59.3% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package OpenSRF::System; | ||||||
2 | 9 9 9 9 9 9 | 49 34 54 64 28 53 | use strict; use warnings; | ||||
3 | 9 9 9 | 68 40 93 | use OpenSRF; | ||||
4 | 9 9 9 | 63 35 76 | use base 'OpenSRF'; | ||||
5 | 9 9 9 | 66 34 57 | use OpenSRF::Utils::Logger qw(:level); | ||||
6 | 9 9 9 | 113 41 100 | use OpenSRF::Transport::Listener; | ||||
7 | 9 9 9 | 1211 36 107 | use OpenSRF::Transport; | ||||
8 | 9 9 9 | 103 38 112 | use OpenSRF::UnixServer; | ||||
9 | 9 9 9 | 77 31 98 | use OpenSRF::Utils; | ||||
10 | 9 9 9 | 65 34 62 | use OpenSRF::EX qw/:try/; | ||||
11 | 9 9 9 | 64 33 80 | use POSIX qw/setsid :sys_wait_h/; | ||||
12 | 9 9 9 | 67 34 66 | use OpenSRF::Utils::Config; | ||||
13 | 9 9 9 | 65 35 68 | use OpenSRF::Utils::SettingsParser; | ||||
14 | 9 9 9 | 60 32 54 | use OpenSRF::Utils::SettingsClient; | ||||
15 | 9 9 9 | 61 30 62 | use OpenSRF::Application; | ||||
16 | 9 9 9 | 156 40 169 | use Net::Server::PreFork; | ||||
17 | |||||||
18 | my $bootstrap_config_file; | ||||||
19 | sub import { | ||||||
20 | 10 | 57 | my( $self, $config ) = @_; | ||||
21 | 10 | 42 | $bootstrap_config_file = $config; | ||||
22 | } | ||||||
23 | |||||||
24 | $| = 1; | ||||||
25 | |||||||
26 | 0 | sub DESTROY {} | |||||
27 | |||||||
28 | sub load_bootstrap_config { | ||||||
29 | 0 | 0 | return if OpenSRF::Utils::Config->current; | ||||
30 | |||||||
31 | 0 | die "Please provide a bootstrap config file to OpenSRF::System\n" | |||||
32 | unless $bootstrap_config_file; | ||||||
33 | |||||||
34 | 0 | OpenSRF::Utils::Config->load(config_file => $bootstrap_config_file); | |||||
35 | 0 | OpenSRF::Utils::JSON->register_class_hint(name => "OpenSRF::Application", hint => "method", type => "hash"); | |||||
36 | 0 | OpenSRF::Transport->message_envelope("OpenSRF::Transport::SlimJabber::MessageWrapper"); | |||||
37 | 0 | OpenSRF::Transport::PeerHandle->set_peer_client("OpenSRF::Transport::SlimJabber::PeerConnection"); | |||||
38 | 0 | OpenSRF::Transport::Listener->set_listener("OpenSRF::Transport::SlimJabber::Inbound"); | |||||
39 | 0 | OpenSRF::Application->server_class('client'); | |||||
40 | } | ||||||
41 | |||||||
42 | # ---------------------------------------------- | ||||||
43 | # Bootstraps a single client connection. | ||||||
44 | # named params are 'config_file' and 'client_name' | ||||||
45 | sub bootstrap_client { | ||||||
46 | 0 | 0 | my $self = shift; | ||||
47 | |||||||
48 | 0 | my $con = OpenSRF::Transport::PeerHandle->retrieve; | |||||
49 | 0 | return if $con and $con->tcp_connected; | |||||
50 | |||||||
51 | 0 | my %params = @_; | |||||
52 | |||||||
53 | 0 | $bootstrap_config_file = | |||||
54 | $params{config_file} || $bootstrap_config_file; | ||||||
55 | |||||||
56 | 0 | my $app = $params{client_name} || "client"; | |||||
57 | |||||||
58 | 0 | load_bootstrap_config(); | |||||
59 | 0 | OpenSRF::Utils::Logger::set_config(); | |||||
60 | 0 | OpenSRF::Transport::PeerHandle->construct($app); | |||||
61 | } | ||||||
62 | |||||||
63 | sub connected { | ||||||
64 | 0 | 0 | if (my $con = OpenSRF::Transport::PeerHandle->retrieve) { | ||||
65 | 0 | return 1 if $con->tcp_connected; | |||||
66 | } | ||||||
67 | 0 | return 0; | |||||
68 | } | ||||||
69 | |||||||
70 | 1; |