MediaWiki  REL1_23
PoolCounter.php
Go to the documentation of this file.
00001 <?php
00042 abstract class PoolCounter {
00043     /* Return codes */
00044     const LOCKED = 1; /* Lock acquired */
00045     const RELEASED = 2; /* Lock released */
00046     const DONE = 3; /* Another worker did the work for you */
00047 
00048     const ERROR = -1; /* Indeterminate error */
00049     const NOT_LOCKED = -2; /* Called release() with no lock held */
00050     const QUEUE_FULL = -3; /* There are already maxqueue workers on this lock */
00051     const TIMEOUT = -4; /* Timeout exceeded */
00052     const LOCK_HELD = -5; /* Cannot acquire another lock while you have one lock held */
00053 
00055     protected $key;
00057     protected $workers;
00059     protected $maxqueue;
00061     protected $timeout;
00062 
00068     protected function __construct( $conf, $type, $key ) {
00069         $this->key = $key;
00070         $this->workers = $conf['workers'];
00071         $this->maxqueue = $conf['maxqueue'];
00072         $this->timeout = $conf['timeout'];
00073     }
00074 
00083     public static function factory( $type, $key ) {
00084         global $wgPoolCounterConf;
00085         if ( !isset( $wgPoolCounterConf[$type] ) ) {
00086             return new PoolCounter_Stub;
00087         }
00088         $conf = $wgPoolCounterConf[$type];
00089         $class = $conf['class'];
00090 
00091         return new $class( $conf, $type, $key );
00092     }
00093 
00097     public function getKey() {
00098         return $this->key;
00099     }
00100 
00106     abstract public function acquireForMe();
00107 
00114     abstract public function acquireForAnyone();
00115 
00123     abstract public function release();
00124 }
00125 
00126 class PoolCounter_Stub extends PoolCounter {
00127     public function __construct() {
00128         /* No parameters needed */
00129     }
00130 
00131     public function acquireForMe() {
00132         return Status::newGood( PoolCounter::LOCKED );
00133     }
00134 
00135     public function acquireForAnyone() {
00136         return Status::newGood( PoolCounter::LOCKED );
00137     }
00138 
00139     public function release() {
00140         return Status::newGood( PoolCounter::RELEASED );
00141     }
00142 }