/[meteor]/googlecode.com/svn/trunk/Meteor/Subscriber.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/Subscriber.pm

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

revision 32 by andrew.betts, Thu Dec 20 21:24:24 2007 UTC revision 45 by knops.gerd, Mon Feb 4 19:02:49 2008 UTC
# Line 44  package Meteor::Subscriber; Line 44  package Meteor::Subscriber;
44                    
45          our %PersistentConnections=();          our %PersistentConnections=();
46          our $NumAcceptedConnections=0;          our $NumAcceptedConnections=0;
47        
48    
49  ###############################################################################  ###############################################################################
50  # Factory methods  # Factory methods
# Line 79  sub deleteSubscriberWithID { Line 80  sub deleteSubscriberWithID {
80                    
81          if(exists($PersistentConnections{$id}))          if(exists($PersistentConnections{$id}))
82          {          {
83                  $PersistentConnections{$id}->close(1);                  $PersistentConnections{$id}->close();
84          }          }
85  }  }
86    
87  sub pingPersistentConnections {  sub pingPersistentConnections {
88          my $class=shift;          my $class=shift;
89                    
         my $msg=$::CONF{'PingMessage'};  
90          my @cons=values %PersistentConnections;          my @cons=values %PersistentConnections;
91                    
92          map { $_->write($msg) } @cons;          map { $_->ping() } @cons;
93  }  }
94    
95  sub checkPersistentConnectionsForMaxTime {  sub checkPersistentConnectionsForMaxTime {
# Line 137  sub processLine { Line 137  sub processLine {
137                  if($self->{'headerBuffer'}=~/GET\s+$::CONF{'SubscriberDynamicPageAddress'}\/([0-9a-z]+)\/([0-9a-z]+)\/(\S+)/i)                  if($self->{'headerBuffer'}=~/GET\s+$::CONF{'SubscriberDynamicPageAddress'}\/([0-9a-z]+)\/([0-9a-z]+)\/(\S+)/i)
138                  {                  {
139                          my $subscriberID=$1;                          my $subscriberID=$1;
                         my $persist=0;  
140                          $self->{'mode'}=$2;                          $self->{'mode'}=$2;
141                            my $persist=$self->getConf('Persist');
142                            
143                          if ($self->{'mode'} eq "xhrinteractive" || $self->{'mode'} eq "iframe" || $self->{'mode'} eq "serversent" || $self->{'mode'} eq "longpoll") {                          if ($self->{'mode'} eq "xhrinteractive" || $self->{'mode'} eq "iframe" || $self->{'mode'} eq "serversent" || $self->{'mode'} eq "longpoll") {
144                                  $persist=1;                                  $persist=1;
145                                  $self->{'MaxMessageCount'}=1 unless(!($self->{'mode'} eq "longpoll"));                                  $self->{'MaxMessageCount'}=1 unless(!($self->{'mode'} eq "longpoll"));
# Line 148  sub processLine { Line 149  sub processLine {
149                          } else {                          } else {
150                                  $self->{'HeaderTemplateNumber'}=2;                                  $self->{'HeaderTemplateNumber'}=2;
151                          }                          }
152                            
153                            my $maxTime=$self->getConf('MaxTime');
154                            if($maxTime>0)
155                            {
156                                    $self->{'ConnectionTimeLimit'}=$self->{'ConnectionStart'}+$maxTime;
157                            }
158                            
159                          my @channelData=split('/',$3);                          my @channelData=split('/',$3);
160                          my $channels={};                          my $channels={};
161                          my $channelName;                          my $channelName;
162                          my $offset;                          my $offset;
163                          foreach my $chandef (@channelData)                          foreach my $chandef (@channelData) {
164                          {                                  if($chandef=~/^([a-z0-9]+)(.(r|b|h)([0-9]*))?$/i) {
                                 if($chandef=~/^([a-z0-9]+)(.(r|b|h)([0-9]*))?$/)  
                                 {  
165                                          $channelName = $1;                                          $channelName = $1;
166                                          $channels->{$channelName}->{'startIndex'} = undef;                                          $channels->{$channelName}->{'startIndex'} = undef;
167                                          for ($3) {                                          if ($3) {
168                                                  $offset = $4;                                             $offset = $4;
169                                                  /r/ && do { $channels->{$channelName}->{'startIndex'} = $offset; last; };                                             if ($3 eq 'r') { $channels->{$channelName}->{'startIndex'} = $offset; }
170                                                  /b/ && do { $channels->{$channelName}->{'startIndex'} = -$offset; last; };                                             if ($3 eq 'b') { $channels->{$channelName}->{'startIndex'} = -$offset; }
171                                                  /h/ && do { $channels->{$channelName}->{'startIndex'} = 0; last; };                                             if ($3 eq 'h') { $channels->{$channelName}->{'startIndex'} = 0; }
172                                          }                                          }
173                                  }                                  }
174                          }                          }
# Line 247  sub emitHeader { Line 253  sub emitHeader {
253          {          {
254                  my $hn='HeaderTemplate'.$self->{'HeaderTemplateNumber'};                  my $hn='HeaderTemplate'.$self->{'HeaderTemplateNumber'};
255                                    
256                  $header=$::CONF{$hn};                  $header=$self->getConf($hn);
257          }          }
258          $header=$::CONF{'HeaderTemplate'} unless(defined($header));          $header=$self->getConf('HeaderTemplate') unless(defined($header));
259                    
260          $header=~s/~([^~]+)~/          $header=~s/~([^~]*)~/
261                  if(!defined($1) || $1 eq '')                  if(!defined($1) || $1 eq '')
262                  {                  {
263                          '~';                          '~';
# Line 268  sub emitHeader { Line 274  sub emitHeader {
274                  {                  {
275                          time;                          time;
276                  }                  }
277                    elsif($1 eq 'channelinfo')
278                    {
279                            Meteor::Channel->listChannelsUsingTemplate($self->getConf('ChannelInfoTemplate'));
280                    }
281                  else                  else
282                  {                  {
283                          '';                          '';
# Line 277  sub emitHeader { Line 287  sub emitHeader {
287          $self->write($header);          $self->write($header);
288  }  }
289    
290  sub sendMessage {  sub sendMessages {
291          my $self=shift;          my $self=shift;
         my $msg=shift;  
         my $numMsgInThisBatch=shift;  
292                    
293          $numMsgInThisBatch=1 unless(defined($numMsgInThisBatch));          my $numMessages=0;
294            my $msgTemplate=$self->getConf('Messagetemplate');
295            my $msgData='';
296                    
297          $self->write($msg);          foreach my $message (@_)
298            {
299                    $msgData.=$message->messageWithTemplate($msgTemplate);
300                    $numMessages++;
301            }
302            
303            return if($numMessages<1);
304            
305            $self->write($msgData);
306                    
307          $::Statistics->{'messages_served'}+=$numMsgInThisBatch;          $::Statistics->{'messages_served'}+=$numMessages;
308                    
309          my $msgCount=++$self->{'MessageCount'};          my $msgCount=$self->{'MessageCount'};
310            $msgCount+=$numMessages;
311            $self->{'MessageCount'}=$msgCount;
312                    
313          my $maxMsg=$::CONF{'MaxMessages'};          my $maxMsg=$self->getConf('MaxMessages');
314          if(defined($maxMsg) && $maxMsg>0 && $msgCount>=$maxMsg)          if(defined($maxMsg) && $maxMsg>0 && $msgCount>=$maxMsg)
315          {          {
316                  $self->close(1);                  $self->close(1);
# Line 300  sub sendMessage { Line 320  sub sendMessage {
320          {          {
321                  $self->close(1);                  $self->close(1);
322          }          }
323            
324    }
325    
326    sub ping {
327            my $self=shift;
328            my $msg=$self->getConf('PingMessage');
329            
330            $self->write($msg);
331  }  }
332    
333  sub closeChannel {  sub closeChannel {
# Line 338  sub close { Line 366  sub close {
366          #          #
367          unless($noShutdownMsg || $self->{'remoteClosed'} || exists($self->{'headerBuffer'}))          unless($noShutdownMsg || $self->{'remoteClosed'} || exists($self->{'headerBuffer'}))
368          {          {
369                  my $msg=$::CONF{'SubscriberShutdownMsg'};                  my $msg=$self->getConf('SubscriberShutdownMsg');
370                  if(defined($msg) && $msg ne '')                  if(defined($msg) && $msg ne '')
371                  {                  {
372                          $self->write($msg);                          $self->write($msg);
373                  }                  }
374          }          }
375                    
         $::Statistics->{'current_subscribers'}--;  
           
376          $self->SUPER::close();          $self->SUPER::close();
377  }  }
378    
379    sub didClose {
380            
381            $::Statistics->{'current_subscribers'}--;
382    }
383    
384  sub checkForMaxTime {  sub checkForMaxTime {
385          my $self=shift;          my $self=shift;
386          my $time=shift;          my $time=shift;
# Line 357  sub checkForMaxTime { Line 388  sub checkForMaxTime {
388          $self->close(1) if(exists($self->{'ConnectionTimeLimit'}) && $self->{'ConnectionTimeLimit'}<$time);          $self->close(1) if(exists($self->{'ConnectionTimeLimit'}) && $self->{'ConnectionTimeLimit'}<$time);
389  }  }
390    
391    sub getConf {
392            my $self=shift;
393            my $key=shift;
394            
395            if(exists($self->{'mode'}) && $self->{'mode'} ne '')
396            {
397                    my $k=$key.'.'.$self->{'mode'};
398                    
399                    return $::CONF{$k} if(exists($::CONF{$k}));
400            }
401            
402            $::CONF{$key};
403    }
404    
405  1;  1;
406  ############################################################################EOF  ############################################################################EOF

Legend:
Removed from v.32  
changed lines
  Added in v.45

  ViewVC Help
Powered by ViewVC 1.1.26