Chad has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/86718


Change subject: Refactor ElasticaConnection
......................................................................

Refactor ElasticaConnection

- Make it abstract like I wanted to
- Introduced forceConnectionPersistence() for subclasses to
  force connection persistence if you're behind LVS or something

Change-Id: I805086242e2b3fb97ef9533e846fa863e0bb8309
---
M ElasticaConnection.php
1 file changed, 29 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Elastica 
refs/changes/18/86718/1

diff --git a/ElasticaConnection.php b/ElasticaConnection.php
index 6533a47..57ecdb8 100644
--- a/ElasticaConnection.php
+++ b/ElasticaConnection.php
@@ -18,7 +18,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  */
-class ElasticaConnection {
+abstract class ElasticaConnection {
        /**
         * Singleton instance of the client
         * @var \Elastica\Client
@@ -28,15 +28,22 @@
        /**
         * @return array(string) server ips or hostnames
         */
-       public static function getServerList() {
-               throw new MWException( 'Must be overridden. ');
-       }
+       public abstract function getServerList();
 
        /**
         * @return string base name for index
         */
-       public static function getIndexBaseName() {
-               throw new MWException( 'Must be overridden. ');
+       public abstract function getIndexBaseName();
+
+       /**
+        * Should we force Elastica\Client to persist connections
+        * even if they seem to fail? Override this and return
+        * true if you're behind something like LVS.
+        *
+        * @return bool
+        */
+       public function forceConnectionPersistence() {
+               return false;
        }
 
        /**
@@ -44,18 +51,24 @@
         * @return \Elastica\Client
         */
        public static function getClient() {
-               if ( self::$client != null ) {
-                       return self::$client;
+               if ( self::$client === null ) {
+                       // Setup the Elastica servers
+                       $servers = array();
+                       $me = new static();
+                       foreach ( $me->getServerList() as $server ) {
+                               $servers[] = array( 'host' => $server );
+                       }
+
+                       // Optionally force connection persistance
+                       $connectionCallback = 
!$me->forceConnectionPersistence() ?
+                               null : function( $connection, $e ) {
+                                       $connection->setEnabled( true );
+                               };
+
+                       self::$client = new \Elastica\Client(
+                               array( 'servers' => $servers ), 
$connectionCallback );
                }
 
-               // Setup the Elastica endpoints
-               $servers = array();
-               foreach ( static::getServerList() as $server ) {
-                       $servers[] = array('host' => $server);
-               }
-               self::$client = new \Elastica\Client( array(
-                       'servers' => $servers
-               ) );
                return self::$client;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/86718
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I805086242e2b3fb97ef9533e846fa863e0bb8309
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Elastica
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to