| 1 | package XAS::Collector::Output::Socket::Base; | ||
| 2 | |||
| 3 | our $VERSION = '0.01'; | ||
| 4 | |||
| 5 | 1 | ▶ | use POE; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Try::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use XAS::Lib::POE::PubSub; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | use XAS::Class | ||
| 10 | debug => 0, | ||
| 11 | version => $VERSION, | ||
| 12 | base => 'XAS::Lib::Stomp::POE::Client', | ||
| 13 | mixin => 'XAS::Lib::Mixins::Handlers', | ||
| 14 | accessors => 'event', | ||
| 15 | vars => { | ||
| 16 | PARAMS => { | ||
| 17 | -eol => { optional => 1, default => "\n" }, # really? silly ruby programmers | ||
| 18 | } | ||
| 19 | } | ||
| 20 | ; | ||
| 21 | |||
| 22 | #use Data::Dumper; | ||
| 23 | |||
| 24 | # ---------------------------------------------------------------------- | ||
| 25 | # Public Events | ||
| 26 | # ---------------------------------------------------------------------- | ||
| 27 | |||
| 28 | sub handle_connection { | ||
| 29 | my ($self) = $_[OBJECT]; | ||
| 30 | |||
| 31 | my $alias = $self->alias; | ||
| 32 | |||
| 33 | $self->log->debug("$alias: handle_connection()"); | ||
| 34 | |||
| 35 | if ($self->tcp_keepalive) { | ||
| 36 | |||
| 37 | $self->log->info_msg('tcp_keepalive_enabled', $alias); | ||
| 38 | |||
| 39 | $self->init_keepalive( | ||
| 40 | -tcp_keepidle => 100, | ||
| 41 | ); | ||
| 42 | |||
| 43 | $self->enable_keepalive($self->socket); | ||
| 44 | |||
| 45 | } | ||
| 46 | |||
| 47 | $self->log->info_msg('collector_connected', $alias, $self->host, $self->port); | ||
| 48 | |||
| 49 | } | ||
| 50 | |||
| 51 | sub read_data { | ||
| 52 | my ($self, $data) = @_[OBJECT, ARG0]; | ||
| 53 | |||
| 54 | my $alias = $self->alias; | ||
| 55 | |||
| 56 | $self->log->warn("$alias: $data"); | ||
| 57 | |||
| 58 | } | ||
| 59 | |||
| 60 | sub connection_down { | ||
| 61 | my ($self) = $_[OBJECT]; | ||
| 62 | |||
| 63 | my $alias = $self->alias; | ||
| 64 | |||
| 65 | $self->log->warn_msg('collector_down', $alias); | ||
| 66 | |||
| 67 | $self->event->publish( | ||
| 68 | -event => 'stop_queue', | ||
| 69 | -args => $alias | ||
| 70 | ); | ||
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | sub connection_up { | ||
| 75 | my ($self) = $_[OBJECT]; | ||
| 76 | |||
| 77 | my $alias = $self->alias; | ||
| 78 | |||
| 79 | $self->log->warn_msg('collector_up', $alias); | ||
| 80 | |||
| 81 | $self->event->publish( | ||
| 82 | -event => 'start_queue', | ||
| 83 | -args => $alias | ||
| 84 | ); | ||
| 85 | |||
| 86 | } | ||
| 87 | |||
| 88 | # ---------------------------------------------------------------------- | ||
| 89 | # Public Methods | ||
| 90 | # ---------------------------------------------------------------------- | ||
| 91 | |||
| 92 | sub session_initialize { | ||
| 93 | my $self = shift; | ||
| 94 | |||
| 95 | my $alias = $self->alias; | ||
| 96 | |||
| 97 | $self->log->debug("$alias: entering session_initialize()"); | ||
| 98 | |||
| 99 | $poe_kernel->state('store_data', $self); | ||
| 100 | |||
| 101 | # walk the chain | ||
| 102 | |||
| 103 | $self->SUPER::session_initialize(); | ||
| 104 | |||
| 105 | $self->log->debug("$alias: leasing session_initialize()"); | ||
| 106 | |||
| 107 | } | ||
| 108 | |||
| 109 | sub session_shutdown { | ||
| 110 | my $self = shift; | ||
| 111 | |||
| 112 | my $alias = $self->alias; | ||
| 113 | |||
| 114 | $self->log->debug("$alias: entering session_shutdown"); | ||
| 115 | |||
| 116 | $poe_kernel->alarm_remove_all(); | ||
| 117 | |||
| 118 | # walk the chain | ||
| 119 | |||
| 120 | $self->SUPER::session_shutdown(); | ||
| 121 | |||
| 122 | $self->log->debug("$alias: leaving session_shutdown"); | ||
| 123 | |||
| 124 | } | ||
| 125 | |||
| 126 | # ---------------------------------------------------------------------- | ||
| 127 | # Private Methods | ||
| 128 | # ---------------------------------------------------------------------- | ||
| 129 | |||
| 130 | sub init { | ||
| 131 | my $class = shift; | ||
| 132 | |||
| 133 | my $self = $class->SUPER::init(@_); | ||
| 134 | |||
| 135 | $self->{'event'} = XAS::Lib::POE::PubSub->new(); | ||
| 136 | |||
| 137 | return $self; | ||
| 138 | |||
| 139 | } | ||
| 140 | |||
| 141 | 1; | ||
| 142 | |||
| 143 | __END__ | ||
| 144 | |||
| 145 | =head1 NAME | ||
| 146 | |||
| 147 | XAS::Collector::Output::Socket::Base - Base method to interact with socket servers | ||
| 148 | |||
| 149 | =head1 SYNOPSIS | ||
| 150 | |||
| 151 | use XAS::Collector::Output::Socket::Logstash; | ||
| 152 | |||
| 153 | my $output = XAS::Collector::Output::Socket::Logstash->new( | ||
| 154 | -alias => 'socket-logstash', | ||
| 155 | -eol => "\n", | ||
| 156 | ); | ||
| 157 | |||
| 158 | =head1 DESCRIPTION | ||
| 159 | |||
| 160 | This module will open and maintain a connection to a socker server. | ||
| 161 | |||
| 162 | =head1 METHODS | ||
| 163 | |||
| 164 | =head2 new | ||
| 165 | |||
| 166 | This module inherits from L<XAS::Lib::Net::POE::Client|XAS::Lib::Net::POE::Client> and | ||
| 167 | takes these additional parameters: | ||
| 168 | |||
| 169 | =over 4 | ||
| 170 | |||
| 171 | =item B<-eol> | ||
| 172 | |||
| 173 | The end-of-line terminator to use. Defaults to "\n". | ||
| 174 | |||
| 175 | =back | ||
| 176 | |||
| 177 | =head1 PUBLIC EVENTS | ||
| 178 | |||
| 179 | This module declares the following events. | ||
| 180 | |||
| 181 | =head2 store_data | ||
| 182 | |||
| 183 | This event is called when a packet is ready for processing. | ||
| 184 | |||
| 185 | =head1 SEE ALSO | ||
| 186 | |||
| 187 | =over 4 | ||
| 188 | |||
| 189 | =item L<XAS::Collector::Output::Socket::Logstash|XAS::Collector::Output::Socket::Logstash> | ||
| 190 | |||
| 191 | =item L<XAS::Collector::Output::Socket::OpenTSDB|XAS::Collector::Output::Socket::OpenTSDB> | ||
| 192 | |||
| 193 | =item L<XAS::Collector|XAS::Collector> | ||
| 194 | |||
| 195 | =item L<XAS|XAS> | ||
| 196 | |||
| 197 | =back | ||
| 198 | |||
| 199 | =head1 AUTHOR | ||
| 200 | |||
| 201 | Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> | ||
| 202 | |||
| 203 | =head1 COPYRIGHT AND LICENSE | ||
| 204 | |||
| 205 | Copyright (c) 2012-2015 Kevin L. Esteb | ||
| 206 | |||
| 207 | This is free software; you can redistribute it and/or modify it under | ||
| 208 | the terms of the Artistic License 2.0. For details, see the full text | ||
| 209 | of the license at http://www.perlfoundation.org/artistic_license_2_0. | ||
| 210 | |||
| 211 | =cut | ||