*/
abstract class LBFactory {
/** @var LBFactory */
- protected static $instance;
+ private static $instance;
/**
* Disables all access to the load balancer, will cause all database access
*
* @return LBFactory
*/
- static function &singleton() {
+ public static function singleton() {
global $wgLBFactoryConf;
if ( is_null( self::$instance ) ) {
/**
* Shut down, close connections and destroy the cached instance.
*/
- static function destroyInstance() {
+ public static function destroyInstance() {
if ( self::$instance ) {
self::$instance->shutdown();
self::$instance->forEachLBCallMethod( 'closeAll' );
*
* @param LBFactory $instance
*/
- static function setInstance( $instance ) {
+ public static function setInstance( $instance ) {
self::destroyInstance();
self::$instance = $instance;
}
* Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
* @param array $conf
*/
- abstract function __construct( array $conf );
+ abstract public function __construct( array $conf );
/**
* Create a new load balancer object. The resulting object will be untracked,
* @param bool|string $wiki Wiki ID, or false for the current wiki
* @return LoadBalancer
*/
- abstract function newMainLB( $wiki = false );
+ abstract public function newMainLB( $wiki = false );
/**
* Get a cached (tracked) load balancer object.
* @param bool|string $wiki Wiki ID, or false for the current wiki
* @return LoadBalancer
*/
- abstract function getMainLB( $wiki = false );
+ abstract public function getMainLB( $wiki = false );
/**
* Create a new load balancer for external storage. The resulting object will be
* @param bool|string $wiki Wiki ID, or false for the current wiki
* @return LoadBalancer
*/
- abstract function newExternalLB( $cluster, $wiki = false );
+ abstract protected function newExternalLB( $cluster, $wiki = false );
/**
* Get a cached (tracked) load balancer for external storage
* @param bool|string $wiki Wiki ID, or false for the current wiki
* @return LoadBalancer
*/
- abstract function &getExternalLB( $cluster, $wiki = false );
+ abstract public function &getExternalLB( $cluster, $wiki = false );
/**
* Execute a function for each tracked load balancer
* @param callable $callback
* @param array $params
*/
- abstract function forEachLB( $callback, array $params = array() );
+ abstract public function forEachLB( $callback, array $params = array() );
/**
* Prepare all tracked load balancers for shutdown
* STUB
*/
- function shutdown() {
+ public function shutdown() {
}
/**
* @param string $methodName
* @param array $args
*/
- function forEachLBCallMethod( $methodName, array $args = array() ) {
- $this->forEachLB( array( $this, 'callMethod' ), array( $methodName, $args ) );
+ private function forEachLBCallMethod( $methodName, array $args = array() ) {
+ $this->forEachLB( function ( LoadBalancer $loadBalancer, $methodName, array $args ) {
+ call_user_func_array( array( $loadBalancer, $methodName ), $args );
+ }, array( $methodName, $args ) );
}
/**
- * Private helper for forEachLBCallMethod
- * @param LoadBalancer $loadBalancer
- * @param string $methodName
- * @param array $args
+ * Commit on all connections. Done for two reasons:
+ * 1. To commit changes to the masters.
+ * 2. To release the snapshot on all connections, master and slave.
*/
- function callMethod( $loadBalancer, $methodName, $args ) {
- call_user_func_array( array( $loadBalancer, $methodName ), $args );
+ public function commitAll() {
+ $this->forEachLBCallMethod( 'commitAll' );
}
/**
* Commit changes on all master connections
*/
- function commitMasterChanges() {
+ public function commitMasterChanges() {
$this->forEachLBCallMethod( 'commitMasterChanges' );
}
* Rollback changes on all master connections
* @since 1.23
*/
- function rollbackMasterChanges() {
+ public function rollbackMasterChanges() {
$this->forEachLBCallMethod( 'rollbackMasterChanges' );
}
* @since 1.23
* @return bool
*/
- function hasMasterChanges() {
+ public function hasMasterChanges() {
$ret = false;
$this->forEachLB( function ( $lb ) use ( &$ret ) {
$ret = $ret || $lb->hasMasterChanges();
*/
class LBFactorySimple extends LBFactory {
/** @var LoadBalancer */
- protected $mainLB;
+ private $mainLB;
/** @var LoadBalancer[] */
- protected $extLBs = array();
+ private $extLBs = array();
/** @var ChronologyProtector */
- protected $chronProt;
+ private $chronProt;
- function __construct( array $conf ) {
+ public function __construct( array $conf ) {
$this->chronProt = new ChronologyProtector;
}
* @param bool|string $wiki
* @return LoadBalancer
*/
- function newMainLB( $wiki = false ) {
+ public function newMainLB( $wiki = false ) {
global $wgDBservers;
if ( $wgDBservers ) {
$servers = $wgDBservers;
* @param bool|string $wiki
* @return LoadBalancer
*/
- function getMainLB( $wiki = false ) {
+ public function getMainLB( $wiki = false ) {
if ( !isset( $this->mainLB ) ) {
$this->mainLB = $this->newMainLB( $wiki );
$this->mainLB->parentInfo( array( 'id' => 'main' ) );
* @param bool|string $wiki
* @return LoadBalancer
*/
- function newExternalLB( $cluster, $wiki = false ) {
+ protected function newExternalLB( $cluster, $wiki = false ) {
global $wgExternalServers;
if ( !isset( $wgExternalServers[$cluster] ) ) {
throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
* @param bool|string $wiki
* @return array
*/
- function &getExternalLB( $cluster, $wiki = false ) {
+ public function &getExternalLB( $cluster, $wiki = false ) {
if ( !isset( $this->extLBs[$cluster] ) ) {
$this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki );
$this->extLBs[$cluster]->parentInfo( array( 'id' => "ext-$cluster" ) );
* @param callable $callback
* @param array $params
*/
- function forEachLB( $callback, array $params = array() ) {
+ public function forEachLB( $callback, array $params = array() ) {
if ( isset( $this->mainLB ) ) {
call_user_func_array( $callback, array_merge( array( $this->mainLB ), $params ) );
}
}
}
- function shutdown() {
+ public function shutdown() {
if ( $this->mainLB ) {
$this->chronProt->shutdownLB( $this->mainLB );
}
* LBFactory::enableBackend() to return to normal behavior
*/
class LBFactoryFake extends LBFactory {
- function __construct( array $conf ) {
+ public function __construct( array $conf ) {
}
- function newMainLB( $wiki = false ) {
+ public function newMainLB( $wiki = false ) {
throw new DBAccessError;
}
- function getMainLB( $wiki = false ) {
+ public function getMainLB( $wiki = false ) {
throw new DBAccessError;
}
- function newExternalLB( $cluster, $wiki = false ) {
+ protected function newExternalLB( $cluster, $wiki = false ) {
throw new DBAccessError;
}
- function &getExternalLB( $cluster, $wiki = false ) {
+ public function &getExternalLB( $cluster, $wiki = false ) {
throw new DBAccessError;
}
- function forEachLB( $callback, array $params = array() ) {
+ public function forEachLB( $callback, array $params = array() ) {
}
}
* Exception class for attempted DB access
*/
class DBAccessError extends MWException {
- function __construct() {
+ public function __construct() {
parent::__construct( "Mediawiki tried to access the database via wfGetDB(). " .
"This is not allowed." );
}