38 |
|
|
39 |
use Meteor::Connection; |
use Meteor::Connection; |
40 |
use Meteor::Channel; |
use Meteor::Channel; |
41 |
|
use Meteor::Subscriber; |
42 |
|
|
43 |
@Meteor::Controller::ISA=qw(Meteor::Connection); |
@Meteor::Controller::ISA=qw(Meteor::Connection); |
44 |
|
|
45 |
############################################################################### |
############################################################################### |
46 |
|
# Factory methods |
47 |
|
############################################################################### |
48 |
|
sub newFromServer { |
49 |
|
my $class=shift; |
50 |
|
|
51 |
|
my $self=$class->SUPER::newFromServer(shift); |
52 |
|
|
53 |
|
$::Statistics->{'current_controllers'}++; |
54 |
|
$::Statistics->{'controller_connections_accepted'}++; |
55 |
|
|
56 |
|
$self; |
57 |
|
} |
58 |
|
|
59 |
|
############################################################################### |
60 |
# Instance methods |
# Instance methods |
61 |
############################################################################### |
############################################################################### |
62 |
sub processLine { |
sub processLine { |
70 |
# COUNTSUBSCRIBERS channel1 |
# COUNTSUBSCRIBERS channel1 |
71 |
# < OK 344 |
# < OK 344 |
72 |
|
|
73 |
unless($line=~s/^(ADDMESSAGE|COUNTSUBSCRIBERS|LISTCHANNELS|QUIT)//) |
unless($line=~s/^(ADDMESSAGE|COUNTSUBSCRIBERS|LISTCHANNELS|SHOWSTATS|QUIT)//) |
74 |
{ |
{ |
75 |
$self->write("ERR Invalid command syntax$::CRLF"); |
$self->write("ERR Invalid command syntax$::CRLF"); |
76 |
|
|
84 |
unless($line=~s/^\s+(\S+)\s//) |
unless($line=~s/^\s+(\S+)\s//) |
85 |
{ |
{ |
86 |
$self->write("ERR Invalid command syntax$::CRLF"); |
$self->write("ERR Invalid command syntax$::CRLF"); |
87 |
|
|
88 |
return; |
return; |
89 |
} |
} |
90 |
|
|
98 |
unless($line=~s/^\s+(\S+)$//) |
unless($line=~s/^\s+(\S+)$//) |
99 |
{ |
{ |
100 |
$self->write("ERR Invalid command syntax$::CRLF"); |
$self->write("ERR Invalid command syntax$::CRLF"); |
101 |
|
|
102 |
return; |
return; |
103 |
} |
} |
104 |
|
|
114 |
unless($line eq '') |
unless($line eq '') |
115 |
{ |
{ |
116 |
$self->write("ERR Invalid command syntax$::CRLF"); |
$self->write("ERR Invalid command syntax$::CRLF"); |
117 |
|
|
118 |
return; |
return; |
119 |
} |
} |
120 |
|
|
122 |
|
|
123 |
$self->write($txt); |
$self->write($txt); |
124 |
} |
} |
125 |
|
elsif($cmd eq 'SHOWSTATS') |
126 |
|
{ |
127 |
|
# uptime |
128 |
|
my $uptime=time-$::STARTUP_TIME; |
129 |
|
my $txt="uptime: $uptime$::CRLF"; |
130 |
|
|
131 |
|
# channel_count |
132 |
|
my $numChannels=Meteor::Channel->numChannels(); |
133 |
|
$txt.="channel_count: $numChannels$::CRLF"; |
134 |
|
|
135 |
|
foreach my $key (keys %{$::Statistics}) |
136 |
|
{ |
137 |
|
$txt.=$key.': '.$::Statistics->{$key}.$::CRLF; |
138 |
|
} |
139 |
|
|
140 |
|
$self->write($txt); |
141 |
|
} |
142 |
elsif($cmd eq 'QUIT') |
elsif($cmd eq 'QUIT') |
143 |
{ |
{ |
144 |
unless($line eq '') |
unless($line eq '') |
145 |
{ |
{ |
146 |
$self->write("ERR Invalid command syntax$::CRLF"); |
$self->write("ERR Invalid command syntax$::CRLF"); |
147 |
|
|
148 |
return; |
return; |
149 |
} |
} |
150 |
|
|
174 |
$self->SUPER::close(); |
$self->SUPER::close(); |
175 |
} |
} |
176 |
|
|
177 |
|
sub didClose { |
178 |
|
|
179 |
|
$::Statistics->{'current_controllers'}--; |
180 |
|
} |
181 |
|
|
182 |
1; |
1; |
183 |
############################################################################EOF |
############################################################################EOF |