Alien-ActiveMQ
view release on metacpan or search on metacpan
lib/Alien/ActiveMQ.pm view on Meta::CPAN
}
method get_installed_versions {
my @dirs = $self->_dist_dir->children;
my @versions = ();
foreach my $dir (@dirs) {
if ( $dir->basename =~ /^\d[\d.]+$/ ) {
push @versions, $dir->basename;
}
}
return ( sort { versioncmp( $b, $a ); } @versions );
}
method get_version_dir($version) {
if ( !$version ) {
$version = ( $self->get_installed_versions )[0];
}
if ($version) {
return dir( $self->_dist_dir, $version );
}
return;
}
method is_version_installed($version) {
return $self->get_version_dir($version)
&& ( -d $self->get_version_dir($version) );
}
method get_license_filename($version) {
my $dir = $self->get_version_dir($version);
return file( $dir, 'LICENSE' );
}
method get_licence_filename($version) {
return $self->get_license_filename($version);
}
method run_server($version) {
my $dir = $self->get_version_dir($version);
my @cmd = ( file( $dir, 'bin', 'activemq' ) );
# Check if we need to use the console verb to get the command to start.
my $consoleflag = $self->_check_output( [ @cmd, '--help' ], qr/(stop)/ );
if ($consoleflag) {
push @cmd, 'console';
}
# Start activemq in a subprocess
$self->_output("Running @cmd");
my $h = start \@cmd, \undef;
my $pid = $h->{KIDS}[0]{PID}; # FIXME!
# Spin until we can get a connection
my ( $stomp, $loop_count );
while ( !$stomp ) {
if ( $loop_count++ > $self->startup_timeout ) {
$h->signal("KILL");
die "Can't connect to ActiveMQ after trying "
. $self->startup_timeout
. " seconds.";
}
eval {
$stomp = Net::Stomp->new(
{
hostname => 'localhost',
port => 61613
}
);
};
if ($@) {
sleep 1;
}
}
return Scope::Guard->new(
sub {
$self->_output("Killing ApacheMQ...");
$h ? $h->signal ( "KILL" ) : kill $pid, 15;
}
);
}
method _check_output( $cmd, $output ) {
my $text = '';
run( $cmd, \undef, \$text );
if ( my @matches = $text =~ $output ) {
return @matches;
}
return;
}
1;
__END__
=for stopwords ActiveMQ MQ perl queueing TODO github Doran undef
=head1 NAME
Alien::ActiveMQ - Manages installs of versions of Apache ActiveMQ, and provides a standard
way to start an MQ server from perl.
=head1 SYNOPSIS
use Alien::ActiveMQ;
{
my $mq = Alien::ActiveMQ->run_server
# Apache MQ is now running on the default port, you
# can now test your Net::Stomp based code
}
# And Apache MQ shuts down once $mq goes out of scope here
=head1 DESCRIPTION
This module, along with the bundled C< install-apachemq > script,
helps to manage installations of the Apache ActiveMQ message queueing software,
from L<http://activemq.apache.org>.
( run in 0.679 second using v1.01-cache-2.11-cpan-39bf76dae61 )