/[meteor]/googlecode.com/svn/trunk/Meteor/Controller.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /googlecode.com/svn/trunk/Meteor/Controller.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 11 by knops.gerd, Thu Dec 14 16:29:42 2006 UTC revision 62 by andrew.betts, Thu Nov 27 00:33:21 2008 UTC
# Line 38  package Meteor::Controller; Line 38  package Meteor::Controller;
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 {
# Line 55  sub processLine { Line 70  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|LISTSUBSCRIBERS|LISTCONNECTIONS|DESCRIBE|SHOWSTATS|QUIT)//)
74          {          {
75                  $self->write("ERR Invalid command syntax$::CRLF");                  $self->write("ERR Invalid command syntax$::CRLF");
76                                    
# Line 69  sub processLine { Line 84  sub processLine {
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                          return;                          return;
103                  }                  }
104                                    
# Line 99  sub processLine { Line 114  sub processLine {
114                  unless($line eq '')                  unless($line eq '')
115                  {                  {
116                          $self->write("ERR Invalid command syntax$::CRLF");                          $self->write("ERR Invalid command syntax$::CRLF");
   
117                          return;                          return;
118                  }                  }
119                                    
# Line 107  sub processLine { Line 121  sub processLine {
121                                    
122                  $self->write($txt);                  $self->write($txt);
123          }          }
124          elsif($cmd eq 'QUIT')          elsif($cmd eq 'LISTSUBSCRIBERS')
125            {
126                    unless($line eq '')
127                    {
128                            $self->write("ERR Invalid command syntax$::CRLF");
129                            return;
130                    }
131                    
132                    my $txt="OK$::CRLF".Meteor::Subscriber->listSubscribers()."--EOT--$::CRLF";
133                    
134                    $self->write($txt);
135            }
136            elsif($cmd eq 'LISTCONNECTIONS')
137          {          {
138                  unless($line eq '')                  unless($line eq '')
139                  {                  {
140                          $self->write("ERR Invalid command syntax$::CRLF");                          $self->write("ERR Invalid command syntax$::CRLF");
141                            return;
142                    }
143                    
144                    my $txt="OK$::CRLF".Meteor::Connection->listConnections()."--EOT--$::CRLF";
145                    
146                    $self->write($txt);
147            }
148            elsif($cmd eq 'DESCRIBE')
149            {
150                    unless($line=~s/^\s+(\S+)$//)
151                    {
152                            $self->write("ERR Invalid command syntax$::CRLF");
153                            return;
154                    }
155                    
156                    my $filenum=$1;
157                    my $condesc=Meteor::Connection->describeConnWithFileNum($filenum);
158                    if ($condesc != -1) {
159                            $self->write("OK$::CRLF");
160                            $self->write($condesc);
161                            $self->write("--EOT--$::CRLF");
162    
163                    } else {
164                            $self->write("ERR Unknown client$::CRLF");
165                    }              
166            }
167            elsif($cmd eq 'SHOWSTATS')
168            {
169                    # uptime
170                    my $uptime=time-$::STARTUP_TIME;
171                    my $txt="OK$::CRLF"."uptime: $uptime$::CRLF";
172                    
173                    # channel_count
174                    my $numChannels=Meteor::Channel->numChannels();
175                    $txt.="channel_count: $numChannels$::CRLF";
176                    
177                    # connection_count
178                    my $numConnections=Meteor::Connection->connectionCount();
179                    $txt.="connection_count: $numConnections$::CRLF";
180    
181                    # subscriber count = current_subscribers + number of pollers in last minute
182                    my $now = time; my $numpoll = 0;
183                    foreach my $key (keys %{$::Pollers}) {
184                            if($::Pollers->{$key} < ($now-60) || Meteor::Subscriber->subscriberExists($key)) {
185                                    delete $::Pollers->{$key};
186                            } else {
187                                    $numpoll++;
188                            }
189                    }
190                    my $numsub = 0;
191                    if (exists($::Statistics->{'current_subscribers'})) {
192                            $numsub = $::Statistics->{'current_subscribers'};
193                    }
194                    $txt.="real_subscribers: ".($numpoll+$numsub)."$::CRLF";
195    
196                    foreach my $key (keys %{$::Statistics})
197                    {
198                            $txt.=$key.': '.$::Statistics->{$key}.$::CRLF;
199                    }
200                    
201                    $txt.="--EOT--$::CRLF";
202                    
203                    $self->write($txt);
204            }
205            elsif($cmd eq 'QUIT')
206            {
207                    unless($line eq '')
208                    {
209                            $self->write("ERR Invalid command syntax$::CRLF");
210                            
211                          return;                          return;
212                  }                  }
213                                    
# Line 142  sub close { Line 237  sub close {
237          $self->SUPER::close();          $self->SUPER::close();
238  }  }
239    
240    sub didClose {
241            
242            $::Statistics->{'current_controllers'}--;
243    }
244    
245  1;  1;
246  ############################################################################EOF  ############################################################################EOF

Legend:
Removed from v.11  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.26