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 |
|
|
91 |
my $channelName=$1; |
my $channelName=$1; |
92 |
my $channel=Meteor::Channel->channelWithName($channelName); |
my $channel=Meteor::Channel->channelWithName($channelName); |
93 |
$channel->addMessage($line); |
my $msg=$channel->addMessage($line); |
94 |
$self->write("OK$::CRLF"); |
my $msgID=$msg->id(); |
95 |
|
$self->write("OK\t$msgID$::CRLF"); |
96 |
} |
} |
97 |
elsif($cmd eq 'COUNTSUBSCRIBERS') |
elsif($cmd eq 'COUNTSUBSCRIBERS') |
98 |
{ |
{ |
99 |
unless($line=~s/^\s+(\S+)$//) |
unless($line=~s/^\s+(\S+)$//) |
100 |
{ |
{ |
101 |
$self->write("ERR Invalid command syntax$::CRLF"); |
$self->write("ERR Invalid command syntax$::CRLF"); |
102 |
|
|
103 |
return; |
return; |
104 |
} |
} |
105 |
|
|
115 |
unless($line eq '') |
unless($line eq '') |
116 |
{ |
{ |
117 |
$self->write("ERR Invalid command syntax$::CRLF"); |
$self->write("ERR Invalid command syntax$::CRLF"); |
118 |
|
|
119 |
return; |
return; |
120 |
} |
} |
121 |
|
|
123 |
|
|
124 |
$self->write($txt); |
$self->write($txt); |
125 |
} |
} |
126 |
|
elsif($cmd eq 'SHOWSTATS') |
127 |
|
{ |
128 |
|
# uptime |
129 |
|
my $uptime=time-$::STARTUP_TIME; |
130 |
|
my $txt="OK$::CRLF"."uptime: $uptime$::CRLF"; |
131 |
|
|
132 |
|
# channel_count |
133 |
|
my $numChannels=Meteor::Channel->numChannels(); |
134 |
|
$txt.="channel_count: $numChannels$::CRLF"; |
135 |
|
|
136 |
|
foreach my $key (keys %{$::Statistics}) |
137 |
|
{ |
138 |
|
$txt.=$key.': '.$::Statistics->{$key}.$::CRLF; |
139 |
|
} |
140 |
|
|
141 |
|
$txt.="--EOT--$::CRLF"; |
142 |
|
|
143 |
|
$self->write($txt); |
144 |
|
} |
145 |
elsif($cmd eq 'QUIT') |
elsif($cmd eq 'QUIT') |
146 |
{ |
{ |
147 |
unless($line eq '') |
unless($line eq '') |
148 |
{ |
{ |
149 |
$self->write("ERR Invalid command syntax$::CRLF"); |
$self->write("ERR Invalid command syntax$::CRLF"); |
150 |
|
|
151 |
return; |
return; |
152 |
} |
} |
153 |
|
|
177 |
$self->SUPER::close(); |
$self->SUPER::close(); |
178 |
} |
} |
179 |
|
|
180 |
|
sub didClose { |
181 |
|
|
182 |
|
$::Statistics->{'current_controllers'}--; |
183 |
|
} |
184 |
|
|
185 |
1; |
1; |
186 |
############################################################################EOF |
############################################################################EOF |