From 8a7171fde610246e5820ee04441955bd8dd463bf Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 13 Jan 2010 23:38:51 -0800 Subject: Don't barf on io loop if xmpp connection failed --- lib/xmppmanager.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/xmppmanager.php b/lib/xmppmanager.php index 0839cda57..dfff63a30 100644 --- a/lib/xmppmanager.php +++ b/lib/xmppmanager.php @@ -118,7 +118,11 @@ class XmppManager extends IoManager */ public function getSockets() { - return array($this->conn->getSocket()); + if ($this->conn) { + return array($this->conn->getSocket()); + } else { + return array(); + } } /** -- cgit v1.2.3-54-g00ecf From 2f32181c930afbbfad7986f84df908cac4ef182d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 14 Jan 2010 00:19:25 -0800 Subject: Keep handler registration per-site to fix queue registration in mixed config environment --- lib/stompqueuemanager.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'lib') diff --git a/lib/stompqueuemanager.php b/lib/stompqueuemanager.php index 3090e0bfb..a7d735d1c 100644 --- a/lib/stompqueuemanager.php +++ b/lib/stompqueuemanager.php @@ -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; } /** -- cgit v1.2.3-54-g00ecf From 58bc33850ab615f21b4364aac8b8b7f74a95111d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 14 Jan 2010 15:32:37 -0800 Subject: temporary --skip-xmpp flag on queuedaemon.php, allows to run queue daemons but skip subscription to xmpp-based queues (still working on making these behave gracefully when server is down) --- lib/queuemanager.php | 2 +- scripts/queuedaemon.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/queuemanager.php b/lib/queuemanager.php index a98c0efff..b98e57a1f 100644 --- a/lib/queuemanager.php +++ b/lib/queuemanager.php @@ -157,7 +157,7 @@ abstract class QueueManager extends IoManager } // XMPP output handlers... - if (common_config('xmpp', 'enabled')) { + if (common_config('xmpp', 'enabled') && !defined('XMPP_EMERGENCY_FLAG')) { $this->connect('jabber', 'JabberQueueHandler'); $this->connect('public', 'PublicQueueHandler'); diff --git a/scripts/queuedaemon.php b/scripts/queuedaemon.php index 8ef364fe7..f8bade39d 100755 --- a/scripts/queuedaemon.php +++ b/scripts/queuedaemon.php @@ -21,7 +21,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); $shortoptions = 'fi:at:'; -$longoptions = array('id=', 'foreground', 'all', 'threads='); +$longoptions = array('id=', 'foreground', 'all', 'threads=', 'skip-xmpp'); /** * Attempts to get a count of the processors available on the current system @@ -260,6 +260,10 @@ if (!$threads) { $daemonize = !(have_option('f') || have_option('--foreground')); $all = have_option('a') || have_option('--all'); +if (have_option('--skip-xmpp')) { + define('XMPP_EMERGENCY_FLAG', true); +} + $daemon = new QueueDaemon($id, $daemonize, $threads, $all); $daemon->runOnce(); -- cgit v1.2.3-54-g00ecf From 038287c1ffb71207f8028014f20005483364956d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 14 Jan 2010 17:14:41 -0800 Subject: fix for --skip-xmpp hack -- forgot to do it on the ping & confirm handlers --- lib/iomaster.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/iomaster.php b/lib/iomaster.php index 5d1071a39..ce77b53b2 100644 --- a/lib/iomaster.php +++ b/lib/iomaster.php @@ -70,7 +70,7 @@ class IoMaster $classes = array(); if (Event::handle('StartIoManagerClasses', array(&$classes))) { $classes[] = 'QueueManager'; - if (common_config('xmpp', 'enabled')) { + if (common_config('xmpp', 'enabled') && !defined('XMPP_EMERGENCY_FLAG')) { $classes[] = 'XmppManager'; // handles pings/reconnects $classes[] = 'XmppConfirmManager'; // polls for outgoing confirmations } -- cgit v1.2.3-54-g00ecf From 598072468c9fdb07df2cda9da207f123b14566ae Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 15 Jan 2010 11:13:06 -0800 Subject: --xmpp-only hack for queuedaemon.php to run separate queue daemon with only xmpp threads --- lib/queuemanager.php | 22 ++++++++++++++-------- lib/stompqueuemanager.php | 7 ++++++- scripts/queuedaemon.php | 5 ++++- 3 files changed, 24 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/queuemanager.php b/lib/queuemanager.php index b98e57a1f..291174d3c 100644 --- a/lib/queuemanager.php +++ b/lib/queuemanager.php @@ -149,11 +149,13 @@ abstract class QueueManager extends IoManager function initialize() { if (Event::handle('StartInitializeQueueManager', array($this))) { - $this->connect('plugin', 'PluginQueueHandler'); - $this->connect('omb', 'OmbQueueHandler'); - $this->connect('ping', 'PingQueueHandler'); - if (common_config('sms', 'enabled')) { - $this->connect('sms', 'SmsQueueHandler'); + if (!defined('XMPP_ONLY_FLAG')) { // hack! + $this->connect('plugin', 'PluginQueueHandler'); + $this->connect('omb', 'OmbQueueHandler'); + $this->connect('ping', 'PingQueueHandler'); + if (common_config('sms', 'enabled')) { + $this->connect('sms', 'SmsQueueHandler'); + } } // XMPP output handlers... @@ -165,10 +167,14 @@ abstract class QueueManager extends IoManager $this->connect('confirm', 'XmppConfirmHandler'); } - // For compat with old plugins not registering their own handlers. - $this->connect('plugin', 'PluginQueueHandler'); + if (!defined('XMPP_ONLY_FLAG')) { // hack! + // For compat with old plugins not registering their own handlers. + $this->connect('plugin', 'PluginQueueHandler'); + } + } + if (!defined('XMPP_ONLY_FLAG')) { // hack! + Event::handle('EndInitializeQueueManager', array($this)); } - Event::handle('EndInitializeQueueManager', array($this)); } /** diff --git a/lib/stompqueuemanager.php b/lib/stompqueuemanager.php index a7d735d1c..00590fdb6 100644 --- a/lib/stompqueuemanager.php +++ b/lib/stompqueuemanager.php @@ -104,7 +104,12 @@ class StompQueueManager extends QueueManager */ function getQueues() { - return array_keys($this->handlers[common_config('site', 'server')]); + $site = common_config('site', 'server'); + if (empty($this->handlers[$site])) { + return array(); + } else { + return array_keys($this->handlers[$site]); + } } /** diff --git a/scripts/queuedaemon.php b/scripts/queuedaemon.php index f8bade39d..162f617e0 100755 --- a/scripts/queuedaemon.php +++ b/scripts/queuedaemon.php @@ -21,7 +21,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); $shortoptions = 'fi:at:'; -$longoptions = array('id=', 'foreground', 'all', 'threads=', 'skip-xmpp'); +$longoptions = array('id=', 'foreground', 'all', 'threads=', 'skip-xmpp', 'xmpp-only'); /** * Attempts to get a count of the processors available on the current system @@ -263,6 +263,9 @@ $all = have_option('a') || have_option('--all'); if (have_option('--skip-xmpp')) { define('XMPP_EMERGENCY_FLAG', true); } +if (have_option('--xmpp-only')) { + define('XMPP_ONLY_FLAG', true); +} $daemon = new QueueDaemon($id, $daemonize, $threads, $all); $daemon->runOnce(); -- cgit v1.2.3-54-g00ecf