3 abstract class PoolCounter
{
4 public static function factory( $type, $key ) {
5 global $wgPoolCounterConf;
6 if ( !isset( $wgPoolCounterConf[$type] ) ) {
7 return new PoolCounter_Stub
;
9 $conf = $wgPoolCounterConf[$type];
10 $class = $conf['class'];
11 return new $class( $conf, $type, $key );
14 abstract public function acquire();
15 abstract public function release();
16 abstract public function wait();
18 public function executeProtected( $mainCallback, $dirtyCallback = false ) {
19 $status = $this->acquire();
20 if ( !$status->isOK() ) {
23 if ( !empty( $status->value
['overload'] ) ) {
24 # Overloaded. Try a dirty cache entry.
25 if ( $dirtyCallback ) {
26 if ( call_user_func( $dirtyCallback ) ) {
28 return Status
::newGood();
33 $status = $this->wait();
34 if ( !$status->isOK() ) {
39 # Call the main callback
40 call_user_func( $mainCallback );
41 return $this->release();
45 class PoolCounter_Stub
extends PoolCounter
{
46 public function acquire() {
47 return Status
::newGood();
50 public function release() {
51 return Status
::newGood();
54 public function wait() {
55 return Status
::newGood();
58 public function executeProtected( $mainCallback, $dirtyCallback = false ) {
59 call_user_func( $mainCallback );
60 return Status
::newGood();