--- googlecode.com/svn/trunk/Meteor/Controller.pm 2007/05/20 14:19:00 24 +++ googlecode.com/svn/trunk/Meteor/Controller.pm 2007/05/20 19:40:53 25 @@ -38,10 +38,25 @@ use Meteor::Connection; use Meteor::Channel; + use Meteor::Subscriber; @Meteor::Controller::ISA=qw(Meteor::Connection); ############################################################################### +# Factory methods +############################################################################### +sub newFromServer { + my $class=shift; + + my $self=$class->SUPER::newFromServer(shift); + + $::Statistics->{'current_controllers'}++; + $::Statistics->{'controller_connections_accepted'}++; + + $self; +} + +############################################################################### # Instance methods ############################################################################### sub processLine { @@ -55,7 +70,7 @@ # COUNTSUBSCRIBERS channel1 # < OK 344 - unless($line=~s/^(ADDMESSAGE|COUNTSUBSCRIBERS|LISTCHANNELS|QUIT)//) + unless($line=~s/^(ADDMESSAGE|COUNTSUBSCRIBERS|LISTCHANNELS|SHOWSTATS|QUIT)//) { $self->write("ERR Invalid command syntax$::CRLF"); @@ -69,7 +84,7 @@ unless($line=~s/^\s+(\S+)\s//) { $self->write("ERR Invalid command syntax$::CRLF"); - + return; } @@ -83,7 +98,7 @@ unless($line=~s/^\s+(\S+)$//) { $self->write("ERR Invalid command syntax$::CRLF"); - + return; } @@ -99,7 +114,7 @@ unless($line eq '') { $self->write("ERR Invalid command syntax$::CRLF"); - + return; } @@ -107,12 +122,29 @@ $self->write($txt); } + elsif($cmd eq 'SHOWSTATS') + { + # uptime + my $uptime=time-$::STARTUP_TIME; + my $txt="uptime: $uptime$::CRLF"; + + # channel_count + my $numChannels=Meteor::Channel->numChannels(); + $txt.="channel_count: $numChannels$::CRLF"; + + foreach my $key (keys %{$::Statistics}) + { + $txt.=$key.': '.$::Statistics->{$key}.$::CRLF; + } + + $self->write($txt); + } elsif($cmd eq 'QUIT') { unless($line eq '') { $self->write("ERR Invalid command syntax$::CRLF"); - + return; } @@ -139,6 +171,8 @@ } } + $::Statistics->{'current_controllers'}--; + $self->SUPER::close(); }