-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerArbitrator.pm
67 lines (56 loc) · 1.43 KB
/
ServerArbitrator.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ServerArbitrator;
# This is the correspondent in the Server, that talks to the Arbitrator.
# Outbound Messages:
# db_status_report, and this message will suffice for a hello
# Inbound messages
# status_request - should be replied with a poll, and a status report
# make_primary
use strict;
use warnings;
use parent 'Correspondent';
use Class::Tiny qw(
status_group
server
),
{
}
;
my $singleton;
sub BUILD {
my $self=shift;
$singleton = $self;
$self->{peer}=ClusterConfig::nodeByTypeId('Arbitrator',0);
# $self->{peer_type} ='Arbitrator';
# $self->{peer_id} = 0;
# $self->{address} ='127.0.0.1';
# $self->{port} =3309;
$self->set_wakeup('db_status_report',30); # Will proabably get a "new_status" before that.
}
sub receive {
my $self = shift;
my @parms = @{$_[0]};
my $verb = shift @parms;
print "Message is $verb \n";
if ($verb eq 'status_request') {
print "VERB is status_request\n";
$self->{server}->poll();
$self->db_status_report();
}
if ($verb eq 'make_primary') {
print "Verb is make_primary";
$self->{server}->make_primary(\@parms);
}
if ($verb eq 'request_status') {
$self->db_status_report();
}
}
sub db_status_report {
my $self = shift;
my $status = $self->{server}->get_status();
$self->send("db_status_report $status",1);
$self->set_wakeup('db_status_report',30);
}
sub new_status {
$singleton->db_status_report;
}
1;