/[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 46 by knops.gerd, Mon Feb 4 19:24:25 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|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                            
103                          return;                          return;
104                  }                  }
105                                    
# Line 99  sub processLine { Line 115  sub processLine {
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                                    
# Line 107  sub processLine { Line 123  sub processLine {
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                                    
# Line 142  sub close { Line 177  sub close {
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

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

  ViewVC Help
Powered by ViewVC 1.1.26