| 1 | package Message::Passing::Fluentd::ConnectionManager; | ||
| 2 | |||
| 3 | use Moo; | ||
| 4 | use Scalar::Util 'weaken'; | ||
| 5 | use Fluent::Logger; | ||
| 6 | use AnyEvent; | ||
| 7 | use namespace::autoclean; | ||
| 8 | |||
| 9 | with qw/ | ||
| 10 | Message::Passing::Role::ConnectionManager | ||
| 11 | Message::Passing::Role::HasHostnameAndPort | ||
| 12 | /; | ||
| 13 | |||
| 14 | sub _default_port { 24224 } | ||
| 15 | |||
| 16 | sub _build_connection { | ||
| 17 | my $self = shift; | ||
| 18 | weaken($self); | ||
| 19 | my $client = Fluent::Logger->new( | ||
| 20 | host => $self->hostname || 'localhost', | ||
| 21 | port => $self->port || $self->_default_port, | ||
| 22 | retry_immediately => 1, | ||
| 23 | timeout => $self->timeout, | ||
| 24 | buffer_overflow_handler => sub { | ||
| 25 | $self->error->consume(shift) | ||
| 26 | } | ||
| 27 | ); | ||
| 28 | # Delay calling set_connected till we've finished building the client | ||
| 29 | my $i; $i = AnyEvent->idle(cb => sub { undef $i; $self->_set_connected(1) }); | ||
| 30 | return $client; | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; |