]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Keep handler registration per-site to fix queue registration in mixed config environment
authorBrion Vibber <brion@pobox.com>
Thu, 14 Jan 2010 08:19:25 +0000 (00:19 -0800)
committerBrion Vibber <brion@status.net>
Thu, 14 Jan 2010 21:22:33 +0000 (13:22 -0800)
lib/stompqueuemanager.php

index 3090e0bfb6f48a45641c142984ad2082c1c4c19a..a7d735d1cf835ec808b6148d8cb7ff95c49caa77 100644 (file)
@@ -66,10 +66,57 @@ class StompQueueManager extends QueueManager
      *
      * @fixme possibly actually do subscription here to save another
      *        loop over all sites later?
+     * @fixme possibly don't assume it's the current site
      */
     public function addSite($server)
     {
         $this->sites[] = $server;
+        $this->initialize();
+    }
+
+
+    /**
+     * Instantiate the appropriate QueueHandler class for the given queue.
+     *
+     * @param string $queue
+     * @return mixed QueueHandler or null
+     */
+    function getHandler($queue)
+    {
+        $handlers = $this->handlers[common_config('site', 'server')];
+        if (isset($handlers[$queue])) {
+            $class = $handlers[$queue];
+            if (class_exists($class)) {
+                return new $class();
+            } else {
+                common_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'");
+            }
+        } else {
+            common_log(LOG_ERR, "Requested handler for unkown queue '$queue'");
+        }
+        return null;
+    }
+
+    /**
+     * Get a list of all registered queue transport names.
+     *
+     * @return array of strings
+     */
+    function getQueues()
+    {
+        return array_keys($this->handlers[common_config('site', 'server')]);
+    }
+
+    /**
+     * Register a queue transport name and handler class for your plugin.
+     * Only registered transports will be reliably picked up!
+     *
+     * @param string $transport
+     * @param string $class
+     */
+    public function connect($transport, $class)
+    {
+        $this->handlers[common_config('site', 'server')][$transport] = $class;
     }
 
     /**