]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'master' into testing
authorBrion Vibber <brion@pobox.com>
Tue, 16 Feb 2010 17:22:02 +0000 (09:22 -0800)
committerBrion Vibber <brion@pobox.com>
Tue, 16 Feb 2010 17:22:02 +0000 (09:22 -0800)
Conflicts:
lib/stompqueuemanager.php

1  2 
classes/Memcached_DataObject.php
lib/cache.php
lib/default.php
lib/statusnet.php
plugins/MemcachePlugin.php

index dfd06b57e50366f4fb60b86578c2f3ddaecb510d,16c3d906ce30688997572a20e5c9895b3ec42585..40576dc71783aedda343e8ea25414b11f777e70e
  
  if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
  
- class Memcached_DataObject extends DB_DataObject
+ class Memcached_DataObject extends Safe_DataObject
  {
-     /**
-      * Destructor to free global memory resources associated with
-      * this data object when it's unset or goes out of scope.
-      * DB_DataObject doesn't do this yet by itself.
-      */
-     function __destruct()
-     {
-         $this->free();
-         if (method_exists('DB_DataObject', '__destruct')) {
-             parent::__destruct();
-         }
-     }
-     /**
-      * Magic function called at serialize() time.
-      *
-      * We use this to drop a couple process-specific references
-      * from DB_DataObject which can cause trouble in future
-      * processes.
-      *
-      * @return array of variable names to include in serialization.
-      */
-     function __sleep()
-     {
-         $vars = array_keys(get_object_vars($this));
-         $skip = array('_DB_resultid', '_link_loaded');
-         return array_diff($vars, $skip);
-     }
-     /**
-      * Magic function called at unserialize() time.
-      *
-      * Clean out some process-specific variables which might
-      * be floating around from a previous process's cached
-      * objects.
-      *
-      * Old cached objects may still have them.
-      */
-     function __wakeup()
-     {
-         // Refers to global state info from a previous process.
-         // Clear this out so we don't accidentally break global
-         // state in *this* process.
-         $this->_DB_resultid = null;
-         // We don't have any local DBO refs, so clear these out.
-         $this->_link_loaded = false;
-     }
      /**
       * Wrapper for DB_DataObject's static lookup using memcached
       * as backing instead of an in-process cache array.
              $cached[] = clone($inst);
          }
          $inst->free();
 -        $c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry);
 +        $c->set($ckey, $cached, Cache::COMPRESSED, $expiry);
          return new ArrayWrapper($cached);
      }
  
          return $c->set($cacheKey, $value);
      }
  }
diff --combined lib/cache.php
index df6fc364931fb2f7b0734523e76724b8c8b675d5,b3ec7534f5f0c92bf1d01a24ead2ead603b4ebed..c09a1dd9f27c75676eb24f634f6c0378547c798d
@@@ -47,8 -47,6 +47,8 @@@ class Cach
      var $_items   = array();
      static $_inst = null;
  
 +    const COMPRESSED = 1;
 +
      /**
       * Singleton constructor
       *
       *
       * @param string  $key    The key to use for lookups
       * @param string  $value  The value to store
 -     * @param integer $flag   Flags to use, mostly ignored
 +     * @param integer $flag   Flags to use, may include Cache::COMPRESSED
       * @param integer $expiry Expiry value, mostly ignored
       *
       * @return boolean success flag
          return $success;
      }
  
+     /**
+      * Atomically increment an existing numeric value.
+      * Existing expiration time should remain unchanged, if any.
+      *
+      * @param string  $key    The key to use for lookups
+      * @param int     $step   Amount to increment (default 1)
+      *
+      * @return mixed incremented value, or false if not set.
+      */
+     function increment($key, $step=1)
+     {
+         $value = false;
+         if (Event::handle('StartCacheIncrement', array(&$key, &$step, &$value))) {
+             // Fallback is not guaranteed to be atomic,
+             // and may original expiry value.
+             $value = $this->get($key);
+             if ($value !== false) {
+                 $value += $step;
+                 $ok = $this->set($key, $value);
+                 $got = $this->get($key);
+             }
+             Event::handle('EndCacheIncrement', array($key, $step, $value));
+         }
+         return $value;
+     }
      /**
       * Delete the value associated with a key
       *
diff --combined lib/default.php
index 8b1fe27694f938e84b801fafede1e5fd84c59b4d,a74cccae12fb29fa76053a84bbff58be440d31ea..3f53edf1457e8c7d9d90ad51b70ccf4885a566a6
@@@ -81,7 -81,7 +81,7 @@@ $default 
                'subsystem' => 'db', # default to database, or 'stomp'
                'stomp_server' => null,
                'queue_basename' => '/queue/statusnet/',
-               'control_channel' => '/topic/statusnet-control', // broadcasts to all queue daemons
+               'control_channel' => '/topic/statusnet/control', // broadcasts to all queue daemons
                'stomp_username' => null,
                'stomp_password' => null,
                'stomp_persistent' => true, // keep items across queue server restart, if persistence is enabled
                'spawndelay' => 1, // Wait at least N seconds between (re)spawns of child processes to avoid slamming the queue server with subscription startup
                'debug_memory' => false, // true to spit memory usage to log
                'inboxes' => true, // true to do inbox distribution & output queueing from in background via 'distrib' queue
+               'breakout' => array('*' => 'shared'), // set global or per-handler queue breakout
+                                       // 'shared': use a shared queue for all sites
+                                       // 'handler': share each/this handler over multiple sites
+                                       // 'site': break out for each/this handler on this site
+               'max_retries' => 10, // drop messages after N failed attempts to process (Stomp)
+               'dead_letter_dir' => false, // set to directory to save dropped messages into (Stomp)
                ),
          'license' =>
          array('type' => 'cc', # can be 'cc', 'allrightsreserved', 'private'
          'avatar' =>
          array('server' => null,
                'dir' => INSTALLDIR . '/avatar/',
 -              'path' => $_path . '/avatar/'),
 +              'path' => $_path . '/avatar/',
 +              'ssl' => null),
          'background' =>
          array('server' => null,
                'dir' => INSTALLDIR . '/background/',
 -              'path' => $_path . '/background/'),
 +              'path' => $_path . '/background/',
 +              'ssl' => null),
          'public' =>
          array('localonly' => true,
                'blacklist' => array(),
          'theme' =>
          array('server' => null,
                'dir' => null,
 -              'path'=> null),
 +              'path'=> null,
 +              'ssl' => null),
          'javascript' =>
          array('server' => null,
 -              'path'=> null),
 +              'path'=> null,
 +              'ssl' => null),
          'throttle' =>
          array('enabled' => false, // whether to throttle edits; false by default
                'count' => 20, // number of allowed messages in timespan
          array('server' => null,
                'dir' => INSTALLDIR . '/file/',
                'path' => $_path . '/file/',
 +              'ssl' => null,
                'supported' => array('image/png',
                                     'image/jpeg',
                                     'image/gif',
diff --combined lib/statusnet.php
index 4f82fdaa6cb64ee22372393124c002d5536f63fd,9c7ede5a5d4fe50164ab533d03862c1fe98c3041..7c4df84b4a7692ed59c5b770d5a044dbcdcfcc55
@@@ -30,7 -30,6 +30,7 @@@ global $config, $_server, $_path
  class StatusNet
  {
      protected static $have_config;
 +    protected static $is_api;
  
      /**
       * Configure and instantiate a plugin into the current configuration.
@@@ -64,7 -63,7 +64,7 @@@
                  }
              }
              if (!class_exists($pluginclass)) {
 -                throw new ServerException(500, "Plugin $name not found.");
 +                throw new ServerException("Plugin $name not found.", 500);
              }
          }
  
          self::initPlugins();
      }
  
+     /**
+      * Get identifier of the currently active site configuration
+      * @return string
+      */
+     public static function currentSite()
+     {
+         return common_config('site', 'nickname');
+     }
+     /**
+      * Change site configuration to site specified by nickname,
+      * if set up via Status_network. If not, sites other than
+      * the current will fail horribly.
+      *
+      * May throw exception or trigger a fatal error if the given
+      * site is missing or configured incorrectly.
+      *
+      * @param string $nickname
+      */
+     public static function switchSite($nickname)
+     {
+         if ($nickname == StatusNet::currentSite()) {
+             return true;
+         }
+         $sn = Status_network::staticGet($nickname);
+         if (empty($sn)) {
+             return false;
+             throw new Exception("No such site nickname '$nickname'");
+         }
+         $server = $sn->getServerName();
+         StatusNet::init($server);
+     }
+     /**
+      * Pull all local sites from status_network table.
+      *
+      * Behavior undefined if site is not configured via Status_network.
+      *
+      * @return array of nicknames
+      */
+     public static function findAllSites()
+     {
+         $sites = array();
+         $sn = new Status_network();
+         $sn->find();
+         while ($sn->fetch()) {
+             $sites[] = $sn->nickname;
+         }
+         return $sites;
+     }
      /**
       * Fire initialization events for all instantiated plugins.
       */
          return self::$have_config;
      }
  
 +    public function isApi()
 +    {
 +        return self::$is_api;
 +    }
 +    
 +    public function setApi($mode)
 +    {
 +        self::$is_api = $mode;
 +    }
 +
      /**
       * Build default configuration array
       * @return array
index c5e74fb4162a38efb35a2b37354caf63d32b4287,93a0583fe8e703527bc715066ffbf5c4c891a214..c3ca5c135928e52e9c4d5a897f2b030f227a84f1
@@@ -51,6 -51,8 +51,8 @@@ if (!defined('STATUSNET')) 
  
  class MemcachePlugin extends Plugin
  {
+     static $cacheInitialized = false;
      private $_conn  = null;
      public $servers = array('127.0.0.1;11211');
  
  
      function onInitializePlugin()
      {
-         if (is_null($this->persistent)) {
+         if (self::$cacheInitialized) {
+             $this->persistent = true;
+         } else {
+             // If we're a parent command-line process we need
+             // to be able to close out the connection after
+             // forking, so disable persistence.
+             //
+             // We'll turn it back on again the second time
+             // through which will either be in a child process,
+             // or a single-process script which is switching
+             // configurations.
              $this->persistent = (php_sapi_name() == 'cli') ? false : true;
          }
          $this->_ensureConn();
+         self::$cacheInitialized = true;
          return true;
      }
  
       *
       * @param string  &$key     in; Key to use for lookups
       * @param mixed   &$value   in; Value to associate
 -     * @param integer &$flag    in; Flag (passed through to Memcache)
 +     * @param integer &$flag    in; Flag empty or Cache::COMPRESSED
       * @param integer &$expiry  in; Expiry (passed through to Memcache)
       * @param boolean &$success out; Whether the set was successful
       *
          if ($expiry === null) {
              $expiry = $this->defaultExpiry;
          }
 -        $success = $this->_conn->set($key, $value, $flag, $expiry);
 +        $success = $this->_conn->set($key, $value, $this->flag(intval($flag)), $expiry);
          Event::handle('EndCacheSet', array($key, $value, $flag,
                                             $expiry));
          return false;
      }
  
+     /**
+      * Atomically increment an existing numeric key value.
+      * Existing expiration time will not be changed.
+      *
+      * @param string &$key    in; Key to use for lookups
+      * @param int    &$step   in; Amount to increment (default 1)
+      * @param mixed  &$value  out; Incremented value, or false if key not set.
+      *
+      * @return boolean hook success
+      */
+     function onStartCacheIncrement(&$key, &$step, &$value)
+     {
+         $this->_ensureConn();
+         $value = $this->_conn->increment($key, $step);
+         Event::handle('EndCacheIncrement', array($key, $step, $value));
+         return false;
+     }
      /**
       * Delete a value associated with a key
       *
          }
      }
  
 +    /**
 +     * Translate general flags to Memcached-specific flags
 +     * @param int $flag
 +     * @return int
 +     */
 +    protected function flag($flag)
 +    {
 +        $out = 0;
 +        if ($flag & Cache::COMPRESSED == Cache::COMPRESSED) {
 +            $out |= MEMCACHE_COMPRESSED;
 +        }
 +        return $out;
 +    }
 +
      function onPluginVersion(&$versions)
      {
          $versions[] = array('name' => 'Memcache',