App-EventStreamr
view release on metacpan or search on metacpan
lib/App/EventStreamr/DVswitch/Roles/MixerWait.pm view on Meta::CPAN
package App::EventStreamr::DVswitch::Roles::MixerWait;
use v5.010;
use strict;
use warnings;
use Method::Signatures 20140224; # libmethod-signatures-perl
use IO::Socket::INET;
use Moo::Role; # libmoo-perl
# ABSTRACT: Wait for DVswitch Mixer to Start
our $VERSION = '0.5'; # VERSION: Generated by DZP::OurPkg:Version
requires 'run_stop','status','config','id','type';
method _test_port() {
my $state;
my $sock = new IO::Socket::INET ( PeerAddr => $self->{config}{mixer}{host},
PeerPort => $self->{config}{mixer}{port},
Proto => 'tcp'
);
if ($sock) {
$state = 1;
$sock->close;
} else {
$state = 0;
}
return $state;
}
method _dvswitch_started() {
# TODO: Not 100% happy with this, but DVswitch likes to accept
# connections before it's ready to accept them...
if (! $self->config->dvswitch_running) {
$self->status->waiting($self->{id},$self->{type},"waiting_dvswitch") if ((time % 10) == 0 );
return 0 if (! $self->_test_port());
# Give DVswitch time to settle.
sleep 1;
$self->config->dvswitch_running('1');
$self->info("DVswitch found running");
return 1;
} else {
return 1;
}
}
around 'run_stop' => sub {
my $orig = shift;
my $self = shift;
if ( $self->_dvswitch_started() ) {
$orig->($self);
}
};
1;
__END__
=pod
=encoding UTF-8
( run in 1.364 second using v1.01-cache-2.11-cpan-39bf76dae61 )