Skip to content

Commit

Permalink
GenericDaemon: rename to GenericListener
Browse files Browse the repository at this point in the history
The defining property of these objects is that they are listening
on a port, which conflicts with Cyrus's use of DAEMON for things
that are not listening on a port.
  • Loading branch information
elliefm committed Jun 26, 2023
1 parent c307c86 commit 6830341
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions cassandane/Cassandane/Cyrus/Annotator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ sub start_my_instances
{
my ($self) = @_;

$self->{instance}->add_generic_daemon(
$self->{instance}->add_generic_listener(
name => 'annotator',
port => $self->{instance}->{config}->get('annotation_callout'),
argv => sub {
my ($daemon) = @_;
my ($listener) = @_;
return (
abs_path('utils/annotator.pl'),
'--port', $daemon->port(),
'--port', $listener->port(),
'--pidfile', '@basedir@/run/annotator.pid',
);
});
Expand Down
3 changes: 2 additions & 1 deletion cassandane/Cassandane/Cyrus/TestCase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use base qw(Cassandane::Unit::TestCase);
use Cassandane::Util::Log;
use Cassandane::Util::Words;
use Cassandane::Generator;
use Cassandane::GenericListener;
use Cassandane::MessageStoreFactory;
use Cassandane::Instance;
use Cassandane::PortManager;
Expand Down Expand Up @@ -1026,7 +1027,7 @@ sub post_tear_down
}

die "Found some stray processes"
if (Cassandane::GenericDaemon::kill_processes_on_ports(
if (Cassandane::GenericListener::kill_processes_on_ports(
Cassandane::PortManager::free_all()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# OF THIS SOFTWARE.
#

package Cassandane::GenericDaemon;
package Cassandane::GenericListener;
use strict;
use warnings;

Expand Down Expand Up @@ -108,7 +108,7 @@ sub set_port
$self->{port} = $port;
}

# Return a hash of parameters for connecting to the daemon.
# Return a hash of parameters for connecting to the listener.
# These will ultimately go through to MessageStoreFactory::create.
sub connection_params
{
Expand Down
44 changes: 21 additions & 23 deletions cassandane/Cassandane/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use Cassandane::Mboxname;
use Cassandane::Config;
use Cassandane::Service;
use Cassandane::ServiceFactory;
use Cassandane::GenericDaemon;
use Cassandane::GenericListener;
use Cassandane::MasterStart;
use Cassandane::MasterEvent;
use Cassandane::Cassini;
Expand Down Expand Up @@ -104,7 +104,7 @@ sub new
starts => [],
services => {},
events => [],
generic_daemons => {},
generic_listeners => {},
re_use_dir => 0,
setup_mailbox => 1,
persistent => 0,
Expand Down Expand Up @@ -465,24 +465,24 @@ sub add_event
push(@{$self->{events}}, Cassandane::MasterEvent->new(%params));
}

sub add_generic_daemon
sub add_generic_listener
{
my ($self, %params) = @_;

my $name = delete $params{name};
die "Missing parameter 'name'"
unless defined $name;
die "Already have a generic daemon named \"$name\""
if defined $self->{generic_daemons}->{$name};
die "Already have a generic listener named \"$name\""
if defined $self->{generic_listeners}->{$name};

my $daemon = Cassandane::GenericDaemon->new(
name => $name,
config => $self->{config},
%params
my $listener = Cassandane::GenericListener->new(
name => $name,
config => $self->{config},
%params
);

$self->{generic_daemons}->{$name} = $daemon;
return $daemon;
$self->{generic_listeners}->{$name} = $listener;
return $listener;
}

sub set_config
Expand All @@ -491,7 +491,7 @@ sub set_config

$self->{config} = $conf;
map { $_->set_config($conf); } (values %{$self->{services}},
values %{$self->{generic_daemons}});
values %{$self->{generic_listeners}});
}

sub _find_binary
Expand Down Expand Up @@ -786,8 +786,6 @@ sub _generate_master_conf
print MASTER "}\n";
}

# $self->{generic_daemons} is daemons *not* managed by master

close MASTER;
}

Expand Down Expand Up @@ -837,7 +835,7 @@ sub _add_services_from_cyrus_conf

if ($k eq 'listen')
{
my $aa = Cassandane::GenericDaemon::parse_address($v);
my $aa = Cassandane::GenericListener::parse_address($v);
$params{host} = $aa->{host};
$params{port} = $aa->{port};
}
Expand Down Expand Up @@ -908,7 +906,7 @@ sub _start_master
# a second set of Cassandane tests on this machine, which is
# also going to fail miserably. In any case we want to know.
foreach my $srv (values %{$self->{services}},
values %{$self->{generic_daemons}})
values %{$self->{generic_listeners}})
{
die "Some process is already listening on " . $srv->address()
if $srv->is_listening();
Expand Down Expand Up @@ -941,10 +939,10 @@ sub _start_master
description => "the master PID file to exist");
xlog "_start_master: PID file present and correct";

# Start any other defined daemons
foreach my $daemon (values %{$self->{generic_daemons}})
# Start any other defined listeners
foreach my $listener (values %{$self->{generic_listeners}})
{
$self->run_command({ cyrus => 0 }, $daemon->get_argv());
$self->run_command({ cyrus => 0 }, $listener->get_argv());
}

# Wait until all the defined services are reported as listening.
Expand All @@ -953,7 +951,7 @@ sub _start_master
# might be a bit slow.
xlog "_start_master: PID waiting for services";
foreach my $srv (values %{$self->{services}},
values %{$self->{generic_daemons}})
values %{$self->{generic_listeners}})
{
timed_wait(sub
{
Expand Down Expand Up @@ -1987,11 +1985,11 @@ sub describe
printf " ";
$srv->describe();
}
printf " generic daemons:\n";
foreach my $daemon (values %{$self->{generic_daemons}})
printf " generic listeners:\n";
foreach my $listener (values %{$self->{generic_listeners}})
{
printf " ";
$daemon->describe();
$listener->describe();
}
}

Expand Down
27 changes: 14 additions & 13 deletions cassandane/Cassandane/Service.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use warnings;

use lib '.';
use base qw(Cassandane::MasterEntry);
use Cassandane::GenericDaemon;
use Cassandane::GenericListener;
use Cassandane::Util::Log;
use Cassandane::MessageStoreFactory;
use Cassandane::Util::Socket;
Expand All @@ -60,9 +60,10 @@ sub new

my $self = $class->SUPER::new(%params);

$self->{_daemon} = Cassandane::GenericDaemon->new(name => $params{name},
host => $host,
port => $port);
$self->{_listener} = Cassandane::GenericListener->new(
name => $params{name},
host => $host,
port => $port);
$self->{type} = $type;

return $self;
Expand All @@ -78,27 +79,27 @@ sub set_config
{
my ($self, $config) = @_;
$self->SUPER::set_config($config);
$self->{_daemon}->set_config($config);
$self->{_listener}->set_config($config);
}

# Return the host
sub host
{
my ($self) = @_;
return $self->{_daemon}->host();
return $self->{_listener}->host();
}

# Return the port
sub port
{
my ($self) = @_;
return $self->{_daemon}->port();
return $self->{_listener}->port();
}

sub set_port
{
my ($self, $port) = @_;
return $self->{_daemon}->set_port($port);
return $self->{_listener}->set_port($port);
}

# Return a hash of parameters suitable for passing
Expand All @@ -107,7 +108,7 @@ sub store_params
{
my ($self, %params) = @_;

my $pp = $self->{_daemon}->connection_params(%params);
my $pp = $self->{_listener}->connection_params(%params);
$pp->{type} ||= $self->{type};
$pp->{username} ||= 'cassandane';
$pp->{password} ||= 'testpw';
Expand Down Expand Up @@ -143,25 +144,25 @@ sub master_params
sub address
{
my ($self) = @_;
return $self->{_daemon}->address();
return $self->{_listener}->address();
}

sub address_family
{
my ($self) = @_;
return $self->{_daemon}->address_family();
return $self->{_listener}->address_family();
}

sub is_listening
{
my ($self) = @_;
return $self->{_daemon}->is_listening();
return $self->{_listener}->is_listening();
}

sub describe
{
my ($self) = @_;
$self->{_daemon}->describe();
$self->{_listener}->describe();
}


Expand Down

0 comments on commit 6830341

Please sign in to comment.