26use InvalidArgumentException;
59 parent::__construct( $conf );
61 $this->mainServers = $conf[
'servers'] ?? [];
62 foreach ( ( $conf[
'externalClusters'] ?? [] ) as $cluster => $servers ) {
63 foreach ( $servers as $index => $server ) {
64 $this->externalServersByCluster[$cluster][$index] = $server;
68 if ( isset( $conf[
'loadMonitor'] ) ) {
69 $this->loadMonitorConfig = $conf[
'loadMonitor'];
70 } elseif ( isset( $conf[
'loadMonitorClass'] ) ) {
71 $this->loadMonitorConfig = [
'class' => $conf[
'loadMonitorClass'] ];
73 $this->loadMonitorConfig = [
'class' => LoadMonitor::class ];
77 public function newMainLB( $domain =
false, $owner =
null ) {
82 if ( $this->mainLB ===
null ) {
90 if ( !isset( $this->externalServersByCluster[$cluster] ) ) {
91 throw new InvalidArgumentException(
"Unknown cluster '$cluster'." );
94 return $this->
newLoadBalancer( $this->externalServersByCluster[$cluster], $owner );
98 if ( !isset( $this->externalLBs[$cluster] ) ) {
102 return $this->externalLBs[$cluster];
106 return [ self::CLUSTER_MAIN_DEFAULT => $this->
getMainLB() ];
111 foreach ( array_keys( $this->externalServersByCluster ) as $cluster ) {
122 'servers' => $servers,
123 'loadMonitor' => $this->loadMonitorConfig,
131 public function forEachLB( $callback, array $params = [] ) {
132 if ( $this->mainLB !==
null ) {
133 $callback( $this->mainLB, ...$params );
135 foreach ( $this->externalLBs as $lb ) {
136 $callback( $lb, ...$params );