]>
Dogcows Code - chaz/chatty/blob - extra/cometd/Meteor/Controller.pm
2 ###############################################################################
4 # An HTTP server for the 2.0 web
5 # Copyright (c) 2006 contributing authors
12 ###############################################################################
14 # This program is free software; you can redistribute it and/or modify it
15 # under the terms of the GNU General Public License as published by the Free
16 # Software Foundation; either version 2 of the License, or (at your option)
19 # This program is distributed in the hope that it will be useful, but WITHOUT
20 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write to the Free Software Foundation, Inc.,
26 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 # For more information visit www.meteorserver.org
30 ###############################################################################
32 package Meteor
::Controller
;
33 ###############################################################################
35 ###############################################################################
39 use Meteor
::Connection
;
41 use Meteor
::Subscriber
;
43 @Meteor::Controller
::ISA
=qw(Meteor::Connection);
45 ###############################################################################
47 ###############################################################################
51 my $self=$class->SUPER::newFromServer
(shift);
53 $::Statistics-
>{'current_controllers'}++;
54 $::Statistics-
>{'controller_connections_accepted'}++;
59 ###############################################################################
61 ###############################################################################
66 # ADDMESSAGE channel1 Message text
69 # < ERR Invalid command syntax
70 # COUNTSUBSCRIBERS channel1
73 unless($line=~s/^(ADDMESSAGE|COUNTSUBSCRIBERS|LISTCHANNELS|SHOWSTATS|QUIT)//)
75 $self->write("ERR Invalid command syntax$::CRLF");
82 if($cmd eq 'ADDMESSAGE')
84 unless($line=~s/^\s+(\S+)\s//)
86 $self->write("ERR Invalid command syntax$::CRLF");
92 my $channel=Meteor
::Channel-
>channelWithName($channelName);
93 my $msg=$channel->addMessage($line);
95 $self->write("OK\t$msgID$::CRLF");
97 elsif($cmd eq 'COUNTSUBSCRIBERS')
99 unless($line=~s/^\s+(\S+)$//)
101 $self->write("ERR Invalid command syntax$::CRLF");
107 my $numSubscribers=0;
108 my $channel=Meteor
::Channel-
>channelWithName($channelName,1);
109 $numSubscribers=$channel->subscriberCount() if($channel);
111 $self->write("OK $numSubscribers$::CRLF");
113 elsif($cmd eq 'LISTCHANNELS')
117 $self->write("ERR Invalid command syntax$::CRLF");
122 my $txt="OK$::CRLF".Meteor
::Channel-
>listChannels()."--EOT--$::CRLF";
126 elsif($cmd eq 'SHOWSTATS')
129 my $uptime=time-
$::STARTUP_TIME
;
130 my $txt="OK$::CRLF"."uptime: $uptime$::CRLF";
133 my $numChannels=Meteor
::Channel-
>numChannels();
134 $txt.="channel_count: $numChannels$::CRLF";
136 foreach my $key (keys %{$::Statistics
})
138 $txt.=$key.': '.$::Statistics-
>{$key}.$::CRLF
;
141 $txt.="--EOT--$::CRLF";
145 elsif($cmd eq 'QUIT')
149 $self->write("ERR Invalid command syntax$::CRLF");
154 $self->write("OK$::CRLF");
159 # Should never get here
160 die("Unknown command '$cmd'");
166 my $noShutdownMsg=shift;
168 unless($noShutdownMsg || $self->{'remoteClosed'})
170 my $msg=$::CONF
{'ControllerShutdownMsg'};
171 if(defined($msg) && $msg ne '')
177 $self->SUPER::close();
182 $::Statistics-
>{'current_controllers'}--;
186 ############################################################################EOF
This page took 0.044982 seconds and 4 git commands to generate.