MediaWiki REL1_35
LBFactorySingle.php
Go to the documentation of this file.
1<?php
24namespace Wikimedia\Rdbms;
25
26use BadMethodCallException;
27use InvalidArgumentException;
28
34 private $lb;
35
40 public function __construct( array $conf ) {
41 parent::__construct( $conf );
42
43 if ( !isset( $conf['connection'] ) ) {
44 throw new InvalidArgumentException( "Missing 'connection' argument." );
45 }
46
47 $lb = new LoadBalancerSingle( array_merge(
48 $this->baseLoadBalancerParams( $this->getOwnershipId() ),
49 $conf
50 ) );
51 $this->initLoadBalancer( $lb );
52
53 $this->lb = $lb;
54 }
55
62 public static function newFromConnection( IDatabase $db, array $params = [] ) {
63 return new static( array_merge(
64 [ 'localDomain' => $db->getDomainID() ],
65 $params,
66 [ 'connection' => $db ]
67 ) );
68 }
69
70 public function newMainLB( $domain = false, $owner = null ) {
71 throw new BadMethodCallException( "Method is not supported." );
72 }
73
74 public function getMainLB( $domain = false ) {
75 return $this->lb;
76 }
77
78 public function newExternalLB( $cluster, $owner = null ) {
79 throw new BadMethodCallException( "Method is not supported." );
80 }
81
82 public function getExternalLB( $cluster ) {
83 throw new BadMethodCallException( "Method is not supported." );
84 }
85
86 public function getAllMainLBs() {
87 return [ 'DEFAULT' => $this->lb ];
88 }
89
90 public function getAllExternalLBs() {
91 return [];
92 }
93
94 public function forEachLB( $callback, array $params = [] ) {
95 if ( isset( $this->lb ) ) { // may not be set during _destruct()
96 $callback( $this->lb, ...$params );
97 }
98 }
99}
An LBFactory class that always returns a single database object.
getAllMainLBs()
Get cached (tracked) load balancers for all main database clusters.
getMainLB( $domain=false)
Get a cached (tracked) load balancer object.
forEachLB( $callback, array $params=[])
Execute a function for each currently tracked (instantiated) load balancer.
newExternalLB( $cluster, $owner=null)
Create a new load balancer for external storage.
newMainLB( $domain=false, $owner=null)
Create a new load balancer object.
getExternalLB( $cluster)
Get a cached (tracked) load balancer for external storage.
getAllExternalLBs()
Get cached (tracked) load balancers for all external database clusters.
static newFromConnection(IDatabase $db, array $params=[])
An interface for generating database load balancers.
Definition LBFactory.php:41
baseLoadBalancerParams( $owner)
Get parameters to ILoadBalancer::__construct()
initLoadBalancer(ILoadBalancer $lb)
Trivial LoadBalancer that always returns an injected connection handle.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
getDomainID()
Return the currently selected domain ID.