Allow for instances as well as class names to be passed as queue handlers and iomanagers.

This commit is contained in:
Craig Andrews 2010-01-23 01:03:41 -05:00
parent 845f051c2f
commit 23c0d663d6
2 changed files with 11 additions and 5 deletions

View File

@ -102,7 +102,7 @@ abstract class IoMaster
*/ */
protected function instantiate($class) protected function instantiate($class)
{ {
if (isset($this->singletons[$class])) { if (is_string($class) && isset($this->singletons[$class])) {
// Already instantiated a multi-site-capable handler. // Already instantiated a multi-site-capable handler.
// Just let it know it should listen to this site too! // Just let it know it should listen to this site too!
$this->singletons[$class]->addSite(common_config('site', 'server')); $this->singletons[$class]->addSite(common_config('site', 'server'));
@ -129,8 +129,12 @@ abstract class IoMaster
protected function getManager($class) protected function getManager($class)
{ {
if(is_object($class)){
return $class;
} else {
return call_user_func(array($class, 'get')); return call_user_func(array($class, 'get'));
} }
}
/** /**
* Basic run loop... * Basic run loop...
@ -347,7 +351,7 @@ abstract class IoMaster
* for per-queue and per-site records. * for per-queue and per-site records.
* *
* @param string $key counter name * @param string $key counter name
* @param array $owners list of owner keys like 'queue:jabber' or 'site:stat01' * @param array $owners list of owner keys like 'queue:xmpp' or 'site:stat01'
*/ */
public function stats($key, $owners=array()) public function stats($key, $owners=array())
{ {

View File

@ -181,7 +181,9 @@ abstract class QueueManager extends IoManager
{ {
if (isset($this->handlers[$queue])) { if (isset($this->handlers[$queue])) {
$class = $this->handlers[$queue]; $class = $this->handlers[$queue];
if (class_exists($class)) { if(is_object($class)) {
return $class;
} else if (class_exists($class)) {
return new $class(); return new $class();
} else { } else {
common_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'"); common_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'");
@ -242,7 +244,7 @@ abstract class QueueManager extends IoManager
* Only registered transports will be reliably picked up! * Only registered transports will be reliably picked up!
* *
* @param string $transport * @param string $transport
* @param string $class * @param string $class class name or object instance
* @param string $group * @param string $group
*/ */
public function connect($transport, $class, $group='queuedaemon') public function connect($transport, $class, $group='queuedaemon')