QueueManager.php

Summary
QueueManager.php
QueueManagerBase class for Queue managers
QueueManagerCompleted child classes must implement the enqueue() method.
__constructConstructor procedure
_logLog a string to the common log
initializeInitialize the list of queue handlers for the current site.
getFactory function to pull the appropriate QueueManager object for this site’s configuration.
multiSitewouldn’t necessarily work with other class types.
sendControlSignalOptional; ping any running queue handler daemons with a notification such as announcing a new site to handle or requesting clean shutdown.
enqueueStore an object (usually/always a Notice) into the given queue for later processing.
logrepBuild a string representation of an object for logging purpose
encodeEncode an object for queued storage.
decodeDecode an object from queued storage.
getIgnoredTransports
ignoreTransport
connectRegister a queue transport name and handler class for your plugin.
setActiveGroupSet the active group which will be used for listening.
setActiveGroupsSet the active group(s) which will be used for listening.
queueGroup
statsSend a statistic ping to the queue monitoring system, optionally with a per-queue id.

QueueManager

Base class for Queue managers

postActiv

the micro-blogging software

Copyright

Copyright © 2016-2017, Maiyannah Bishop

Derived from code copyright various sources

  • GNU Social © 2013-2016, Free Software Foundation, Inc
  • StatusNet © 2008-2012, StatusNet, Inc

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses/.

https://www.gnu.org/licenses/agpl.html

About

Abstract class for queue managers

PHP version

Tested with PHP 7

File Authors

Web

QueueManager

Completed child classes must implement the enqueue() method.

For background processing, classes should implement either socket-based input (handleInput(), getSockets()) or idle-loop polling (idle()).

Inherits from: IoManager

Variables

  • static $qm = null;
  • protected $master = null;
  • protected $handlers = array();
  • protected $groups = array();
  • protected $activeGroups = array();
  • protected $ignoredTransports = array();
Summary
__constructConstructor procedure
_logLog a string to the common log
initializeInitialize the list of queue handlers for the current site.
getFactory function to pull the appropriate QueueManager object for this site’s configuration.
multiSitewouldn’t necessarily work with other class types.
sendControlSignalOptional; ping any running queue handler daemons with a notification such as announcing a new site to handle or requesting clean shutdown.
enqueueStore an object (usually/always a Notice) into the given queue for later processing.
logrepBuild a string representation of an object for logging purpose
encodeEncode an object for queued storage.
decodeDecode an object from queued storage.
getIgnoredTransports
ignoreTransport
connectRegister a queue transport name and handler class for your plugin.
setActiveGroupSet the active group which will be used for listening.
setActiveGroupsSet the active group(s) which will be used for listening.
queueGroup
statsSend a statistic ping to the queue monitoring system, optionally with a per-queue id.

__construct

function __construct()

Constructor procedure

_log

protected function _log($level,
$msg)

Log a string to the common log

Parameters

  • level - log level to log at
  • msg - message to log

initialize

function initialize()

Initialize the list of queue handlers for the current site.

Events

  • StartInitializeQueueManager
  • EndInitializeQueueManager

get

public static function get()

Factory function to pull the appropriate QueueManager object for this site’s configuration.  It can then be used to queue events for later processing or to spawn a processing loop.

Plugins can add to the built-in types by hooking StartNewQueueManager.

Returns

$qmQueueManager object

multiSite

public static function multiSite()

Fixme

wouldn’t necessarily work with other class types.  Better to change the interface...?

sendControlSignal

public function sendControlSignal($event,  
$param = '')

Optional; ping any running queue handler daemons with a notification such as announcing a new site to handle or requesting clean shutdown.  This avoids having to restart all the daemons manually to update configs and such.

Called from scripts/queuectl.php controller utility.

Parameters

  • string $event - event key
  • string $param - optional parameter to append to key

Returns

  • boolean success

enqueue

abstract function enqueue($object,
$queue)

Store an object (usually/always a Notice) into the given queue for later processing.  No guarantee is made on when it will be processed; it could be immediately or at some unspecified point in the future.

Must be implemented by any queue manager.

Parameters

  • Notice $object
  • string $queue

logrep

function logrep($object)

Build a string representation of an object for logging purpose

Parameters

  • Object - object to build the representation for.

Returns

  • string $object

encode

protected function encode($item)

Encode an object for queued storage.

Parameters

  • mixed $item

Returns

  • string $item

decode

protected function decode($frame)

Decode an object from queued storage.  Accepts notice reference entries and serialized items.

Parameters

  • string $frame

Returns

  • deserialized object

getIgnoredTransports

function getIgnoredTransports()

ignoreTransport

function ignoreTransport($transport)

connect

public function connect($transport,  
$class,  
$group = 'main')

Register a queue transport name and handler class for your plugin.  Only registered transports will be reliably picked up!

Parameters

  • string $transport
  • string $class class name or object instance
  • string $group

setActiveGroup

function setActiveGroup($group)

Set the active group which will be used for listening.  @param string $group

setActiveGroups

function setActiveGroups($groups)

Set the active group(s) which will be used for listening.

Parameters

  • array $groups

queueGroup

function queueGroup($queue)

Returns

  • string - queue group for this queue

stats

function stats($key,  
$queue = false)

Send a statistic ping to the queue monitoring system, optionally with a per-queue id.

Parameters

  • string $key
  • string $queue (default false)
function __construct()
Constructor procedure
protected function _log($level,
$msg)
Log a string to the common log
function initialize()
Initialize the list of queue handlers for the current site.
public static function get()
Factory function to pull the appropriate QueueManager object for this site’s configuration.
public static function multiSite()
wouldn’t necessarily work with other class types.
public function sendControlSignal($event,  
$param = '')
Optional; ping any running queue handler daemons with a notification such as announcing a new site to handle or requesting clean shutdown.
abstract function enqueue($object,
$queue)
Store an object (usually/always a Notice) into the given queue for later processing.
function logrep($object)
Build a string representation of an object for logging purpose
protected function encode($item)
Encode an object for queued storage.
protected function decode($frame)
Decode an object from queued storage.
function getIgnoredTransports()
function ignoreTransport($transport)
public function connect($transport,  
$class,  
$group = 'main')
Register a queue transport name and handler class for your plugin.
function setActiveGroup($group)
Set the active group which will be used for listening.
function setActiveGroups($groups)
Set the active group(s) which will be used for listening.
function queueGroup($queue)
function stats($key,  
$queue = false)
Send a statistic ping to the queue monitoring system, optionally with a per-queue id.