import v2.0.0.0_RC3 | 2012-07-01
https://github.com/lucanos/CommunityID -> http://www.itadmins.net/archives/357
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Activemq.php 17241 2009-07-28 13:01:20Z matthew $
|
||||
* @version $Id: Activemq.php 18951 2009-11-12 16:26:19Z alexander $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -95,7 +95,7 @@ class Zend_Queue_Adapter_Activemq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
|
||||
$response = $this->_client->send($connect)->receive();
|
||||
|
||||
if ((false !== $response)
|
||||
if ((false !== $response)
|
||||
&& ($response->getCommand() != 'CONNECTED')
|
||||
) {
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
@ -196,6 +196,9 @@ class Zend_Queue_Adapter_Activemq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
$queue = $this->_queue;
|
||||
}
|
||||
|
||||
// read
|
||||
$data = array();
|
||||
|
||||
// signal that we are reading
|
||||
$frame = $this->_client->createFrame();
|
||||
$frame->setCommand('SUBSCRIBE');
|
||||
@ -203,26 +206,26 @@ class Zend_Queue_Adapter_Activemq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
$frame->setHeader('ack','client');
|
||||
$this->_client->send($frame);
|
||||
|
||||
// read
|
||||
$data = array();
|
||||
if ($this->_client->canRead()) {
|
||||
for ($i = 0; $i < $maxMessages; $i++) {
|
||||
$response = $this->_client->receive();
|
||||
if ($maxMessages > 0) {
|
||||
if ($this->_client->canRead()) {
|
||||
for ($i = 0; $i < $maxMessages; $i++) {
|
||||
$response = $this->_client->receive();
|
||||
|
||||
switch ($response->getCommand()) {
|
||||
case 'MESSAGE':
|
||||
$datum = array(
|
||||
'message_id' => $response->getHeader('message-id'),
|
||||
'handle' => $response->getHeader('message-id'),
|
||||
'body' => $response->getBody(),
|
||||
'md5' => md5($response->getBody())
|
||||
);
|
||||
$data[] = $datum;
|
||||
break;
|
||||
default:
|
||||
$block = print_r($response, true);
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Invalid response received: ' . $block);
|
||||
switch ($response->getCommand()) {
|
||||
case 'MESSAGE':
|
||||
$datum = array(
|
||||
'message_id' => $response->getHeader('message-id'),
|
||||
'handle' => $response->getHeader('message-id'),
|
||||
'body' => $response->getBody(),
|
||||
'md5' => md5($response->getBody())
|
||||
);
|
||||
$data[] = $datum;
|
||||
break;
|
||||
default:
|
||||
$block = print_r($response, true);
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Invalid response received: ' . $block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: AdapterInterface.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: AdapterInterface.php 18951 2009-11-12 16:26:19Z alexander $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -33,24 +33,24 @@ interface Zend_Queue_Adapter_AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
* @param Zend_Queue $queue
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
* @param Zend_Queue $queue
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options, Zend_Queue $queue = null);
|
||||
|
||||
/**
|
||||
* Retrieve queue instance
|
||||
*
|
||||
*
|
||||
* @return Zend_Queue
|
||||
*/
|
||||
public function getQueue();
|
||||
|
||||
/**
|
||||
* Set queue instnace
|
||||
*
|
||||
* @param Zend_Queue $queue
|
||||
*
|
||||
* @param Zend_Queue $queue
|
||||
* @return Zend_Queue_Adapter_AdapterInterface
|
||||
*/
|
||||
public function setQueue(Zend_Queue $queue);
|
||||
@ -69,10 +69,10 @@ interface Zend_Queue_Adapter_AdapterInterface
|
||||
/**
|
||||
* Create a new queue
|
||||
*
|
||||
* Visibility timeout is how long a message is left in the queue
|
||||
* "invisible" to other readers. If the message is acknowleged (deleted)
|
||||
* before the timeout, then the message is deleted. However, if the
|
||||
* timeout expires then the message will be made available to other queue
|
||||
* Visibility timeout is how long a message is left in the queue
|
||||
* "invisible" to other readers. If the message is acknowleged (deleted)
|
||||
* before the timeout, then the message is deleted. However, if the
|
||||
* timeout expires then the message will be made available to other queue
|
||||
* readers.
|
||||
*
|
||||
* @param string $name Queue name
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Array.php 16881 2009-07-20 13:24:19Z mikaelkael $
|
||||
* @version $Id: Array.php 18701 2009-10-26 13:03:47Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -223,22 +223,26 @@ class Zend_Queue_Adapter_Array extends Zend_Queue_Adapter_AdapterAbstract
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$start_time = microtime(true);
|
||||
if ($maxMessages > 0) {
|
||||
$start_time = microtime(true);
|
||||
|
||||
$count = 0;
|
||||
$temp = &$this->_data[$queue->getName()];
|
||||
foreach ($temp as $key=>&$msg) {
|
||||
if (($msg['handle'] === null)
|
||||
|| ($msg['timeout'] + $timeout < $start_time)
|
||||
) {
|
||||
$msg['handle'] = md5(uniqid(rand(), true));
|
||||
$msg['timeout'] = microtime(true);
|
||||
$data[] = $msg;
|
||||
$count++;
|
||||
}
|
||||
$count = 0;
|
||||
$temp = &$this->_data[$queue->getName()];
|
||||
foreach ($temp as $key=>&$msg) {
|
||||
// count check has to be first, as someone can ask for 0 messages
|
||||
// ZF-7650
|
||||
if ($count >= $maxMessages) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($count >= $maxMessages) {
|
||||
break;
|
||||
if (($msg['handle'] === null)
|
||||
|| ($msg['timeout'] + $timeout < $start_time)
|
||||
) {
|
||||
$msg['handle'] = md5(uniqid(rand(), true));
|
||||
$msg['timeout'] = microtime(true);
|
||||
$data[] = $msg;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Db.php 17217 2009-07-28 02:02:37Z matthew $
|
||||
* @version $Id: Db.php 18705 2009-10-26 13:05:13Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -66,6 +66,11 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
*/
|
||||
protected $_messageTable = null;
|
||||
|
||||
/**
|
||||
* @var Zend_Db_Table_Row_Abstract
|
||||
*/
|
||||
protected $_messageRow = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -87,6 +92,33 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
throw new Zend_Queue_Exception('Options array item: Zend_Db_Select::FOR_UPDATE must be boolean');
|
||||
}
|
||||
|
||||
if (isset($this->_options['dbAdapter'])
|
||||
&& $this->_options['dbAdapter'] instanceof Zend_Db_Adapter_Abstract) {
|
||||
$db = $this->_options['dbAdapter'];
|
||||
} else {
|
||||
$db = $this->_initDbAdapter();
|
||||
}
|
||||
|
||||
$this->_queueTable = new Zend_Queue_Adapter_Db_Queue(array(
|
||||
'db' => $db,
|
||||
));
|
||||
|
||||
$this->_messageTable = new Zend_Queue_Adapter_Db_Message(array(
|
||||
'db' => $db,
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Db adapter using 'driverOptions' section of the _options array
|
||||
*
|
||||
* Throws an exception if the adapter cannot connect to DB.
|
||||
*
|
||||
* @return Zend_Db_Adapter_Abstract
|
||||
* @throws Zend_Queue_Exception
|
||||
*/
|
||||
protected function _initDbAdapter()
|
||||
{
|
||||
$options = &$this->_options['driverOptions'];
|
||||
if (!array_key_exists('type', $options)) {
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
@ -113,20 +145,17 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
throw new Zend_Queue_Exception("Configuration array must have a key for 'dbname' for the database to use");
|
||||
}
|
||||
|
||||
$type = $options['type'];
|
||||
unset($options['type']);
|
||||
|
||||
try {
|
||||
$db = Zend_Db::factory($options['type'], $options);
|
||||
|
||||
$this->_queueTable = new Zend_Queue_Adapter_Db_Queue(array(
|
||||
'db' => $db,
|
||||
));
|
||||
|
||||
$this->_messageTable = new Zend_Queue_Adapter_Db_Message(array(
|
||||
'db' => $db,
|
||||
));
|
||||
$db = Zend_Db::factory($type, $options);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Error connecting to database: ' . $e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@ -146,7 +175,15 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
*/
|
||||
public function isExists($name)
|
||||
{
|
||||
return in_array($name, $this->getQueues());
|
||||
$id = 0;
|
||||
|
||||
try {
|
||||
$id = $this->getQueueId($name);
|
||||
} catch (Zend_Queue_Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ($id > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,10 +207,10 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
|
||||
$queue = $this->_queueTable->createRow();
|
||||
$queue->queue_name = $name;
|
||||
$queue->timeout = ($timeout === null) ? self::CREATE_TIMEOUT_DEFAULT : (int)$timeout;
|
||||
$queue->timeout = ($timeout === null) ? self::CREATE_TIMEOUT_DEFAULT : (int)$timeout;
|
||||
|
||||
try {
|
||||
if ($id = $queue->save()) {
|
||||
if ($queue->save()) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
@ -213,6 +250,10 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists($name, $this->_queues)) {
|
||||
unset($this->_queues[$name]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -230,11 +271,13 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
$query = $this->_queueTable->select();
|
||||
$query->from($this->_queueTable, array('queue_id', 'queue_name'));
|
||||
|
||||
$list = array();
|
||||
$this->_queues = array();
|
||||
foreach ($this->_queueTable->fetchAll($query) as $queue) {
|
||||
$list[] = $queue->queue_name;
|
||||
$this->_queues[$queue->queue_name] = (int)$queue->queue_id;
|
||||
}
|
||||
|
||||
$list = array_keys($this->_queues);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
@ -275,6 +318,10 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
*/
|
||||
public function send($message, Zend_Queue $queue = null)
|
||||
{
|
||||
if ($this->_messageRow === null) {
|
||||
$this->_messageRow = $this->_messageTable->createRow();
|
||||
}
|
||||
|
||||
if ($queue === null) {
|
||||
$queue = $this->_queue;
|
||||
}
|
||||
@ -291,7 +338,7 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
throw new Zend_Queue_Exception('Queue does not exist:' . $queue->getName());
|
||||
}
|
||||
|
||||
$msg = $this->_messageTable->createRow();
|
||||
$msg = clone $this->_messageRow;
|
||||
$msg->queue_id = $this->getQueueId($queue->getName());
|
||||
$msg->created = time();
|
||||
$msg->body = $message;
|
||||
@ -346,41 +393,43 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
|
||||
// start transaction handling
|
||||
try {
|
||||
$db->beginTransaction();
|
||||
if ( $maxMessages > 0 ) { // ZF-7666 LIMIT 0 clause not included.
|
||||
$db->beginTransaction();
|
||||
|
||||
$query = $db->select();
|
||||
if ($this->_config['options'][Zend_Db_Select::FOR_UPDATE]) {
|
||||
// turn on forUpdate
|
||||
$query->forUpdate();
|
||||
}
|
||||
$query->from($info['name'], array('*'))
|
||||
->where('queue_id=?', $this->getQueueId($queue->getName()))
|
||||
->where('handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime)
|
||||
->limit($maxMessages);
|
||||
|
||||
foreach ($db->fetchAll($query) as $data) {
|
||||
// setup our changes to the message
|
||||
$data['handle'] = md5(uniqid(rand(), true));
|
||||
|
||||
$update = array(
|
||||
'handle' => $data['handle'],
|
||||
'timeout' => $microtime,
|
||||
);
|
||||
|
||||
// update the database
|
||||
$where = array();
|
||||
$where[] = $db->quoteInto('message_id=?', $data['message_id']);
|
||||
$where[] = 'handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime;
|
||||
|
||||
$count = $db->update($info['name'], $update, $where);
|
||||
|
||||
// we check count to make sure no other thread has gotten
|
||||
// the rows after our select, but before our update.
|
||||
if ($count > 0) {
|
||||
$msgs[] = $data;
|
||||
$query = $db->select();
|
||||
if ($this->_options['options'][Zend_Db_Select::FOR_UPDATE]) {
|
||||
// turn on forUpdate
|
||||
$query->forUpdate();
|
||||
}
|
||||
$query->from($info['name'], array('*'))
|
||||
->where('queue_id=?', $this->getQueueId($queue->getName()))
|
||||
->where('handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime)
|
||||
->limit($maxMessages);
|
||||
|
||||
foreach ($db->fetchAll($query) as $data) {
|
||||
// setup our changes to the message
|
||||
$data['handle'] = md5(uniqid(rand(), true));
|
||||
|
||||
$update = array(
|
||||
'handle' => $data['handle'],
|
||||
'timeout' => $microtime,
|
||||
);
|
||||
|
||||
// update the database
|
||||
$where = array();
|
||||
$where[] = $db->quoteInto('message_id=?', $data['message_id']);
|
||||
$where[] = 'handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime;
|
||||
|
||||
$count = $db->update($info['name'], $update, $where);
|
||||
|
||||
// we check count to make sure no other thread has gotten
|
||||
// the rows after our select, but before our update.
|
||||
if ($count > 0) {
|
||||
$msgs[] = $data;
|
||||
}
|
||||
}
|
||||
$db->commit();
|
||||
}
|
||||
$db->commit();
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
|
||||
@ -465,6 +514,10 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
*/
|
||||
protected function getQueueId($name)
|
||||
{
|
||||
if (array_key_exists($name, $this->_queues)) {
|
||||
return $this->_queues[$name];
|
||||
}
|
||||
|
||||
$query = $this->_queueTable->select();
|
||||
$query->from($this->_queueTable, array('queue_id'))
|
||||
->where('queue_name=?', $name);
|
||||
@ -476,6 +529,8 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
|
||||
throw new Zend_Queue_Exception('Queue does not exist: ' . $name);
|
||||
}
|
||||
|
||||
return (int)$queue->queue_id;
|
||||
$this->_queues[$name] = (int)$queue->queue_id;
|
||||
|
||||
return $this->_queues[$name];
|
||||
}
|
||||
}
|
||||
|
49
libs/Zend/Queue/Adapter/Db/postgresql.sql
Normal file
49
libs/Zend/Queue/Adapter/Db/postgresql.sql
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Sample grant for PostgreSQL
|
||||
|
||||
CREATE ROLE queue LOGIN
|
||||
PASSWORD '[CHANGE ME]'
|
||||
NOSUPERUSER NOINHERIT NOCREATEDB NOCREATEROLE;
|
||||
|
||||
*/
|
||||
|
||||
--
|
||||
-- Table structure for table `queue`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS queue;
|
||||
|
||||
CREATE TABLE queue
|
||||
(
|
||||
queue_id serial NOT NULL,
|
||||
queue_name character varying(100) NOT NULL,
|
||||
timeout smallint NOT NULL DEFAULT 30,
|
||||
CONSTRAINT queue_pk PRIMARY KEY (queue_id)
|
||||
)
|
||||
WITH (OIDS=FALSE);
|
||||
ALTER TABLE queue OWNER TO queue;
|
||||
|
||||
|
||||
-- --------------------------------------------------------
|
||||
--
|
||||
-- Table structure for table `message`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS message;
|
||||
|
||||
CREATE TABLE message
|
||||
(
|
||||
message_id bigserial NOT NULL,
|
||||
queue_id integer,
|
||||
handle character(32),
|
||||
body character varying(8192) NOT NULL,
|
||||
md5 character(32) NOT NULL,
|
||||
timeout real,
|
||||
created integer,
|
||||
CONSTRAINT message_pk PRIMARY KEY (message_id),
|
||||
CONSTRAINT message_ibfk_1 FOREIGN KEY (queue_id)
|
||||
REFERENCES queue (queue_id) MATCH SIMPLE
|
||||
ON UPDATE CASCADE ON DELETE CASCADE
|
||||
)
|
||||
WITH (OIDS=FALSE);
|
||||
ALTER TABLE message OWNER TO queue;
|
40
libs/Zend/Queue/Adapter/Db/queue_sqlite.php
Normal file
40
libs/Zend/Queue/Adapter/Db/queue_sqlite.php
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Sample grant for SQLite
|
||||
|
||||
CREATE ROLE queue LOGIN
|
||||
PASSWORD '[CHANGE ME]'
|
||||
NOSUPERUSER NOINHERIT NOCREATEDB NOCREATEROLE;
|
||||
|
||||
*/
|
||||
|
||||
--
|
||||
-- Table structure for table `queue`
|
||||
--
|
||||
|
||||
CREATE TABLE queue
|
||||
(
|
||||
queue_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
queue_name VARCHAR(100) NOT NULL,
|
||||
timeout INTEGER NOT NULL DEFAULT 30
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
-- --------------------------------------------------------
|
||||
--
|
||||
-- Table structure for table `message`
|
||||
--
|
||||
|
||||
CREATE TABLE message
|
||||
(
|
||||
message_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
queue_id INTEGER PRIMARY KEY,
|
||||
handle CHAR(32),
|
||||
body VARCHAR(8192) NOT NULL,
|
||||
md5 CHAR(32) NOT NULL,
|
||||
timeout REAL,
|
||||
created INTEGER,
|
||||
FOREIGN KEY (queue_id) REFERENCES queue(queue_id)
|
||||
);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Memcacheq.php 17241 2009-07-28 13:01:20Z matthew $
|
||||
* @version $Id: Memcacheq.php 18951 2009-11-12 16:26:19Z alexander $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -55,6 +55,11 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
*/
|
||||
protected $_port = null;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $_socket = null;
|
||||
|
||||
/********************************************************************
|
||||
* Constructor / Destructor
|
||||
*********************************************************************/
|
||||
@ -107,6 +112,11 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
if ($this->_cache instanceof Memcache) {
|
||||
$this->_cache->close();
|
||||
}
|
||||
if (is_resource($this->_socket)) {
|
||||
$cmd = 'quit' . self::EOL;
|
||||
fwrite($this->_socket, $cmd);
|
||||
fclose($this->_socket);
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@ -126,7 +136,11 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
*/
|
||||
public function isExists($name)
|
||||
{
|
||||
return in_array($name, $this->getQueues());
|
||||
if (empty($this->_queues)) {
|
||||
$this->getQueues();
|
||||
}
|
||||
|
||||
return in_array($name, $this->_queues);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,6 +172,8 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
$result = $this->_cache->set($name, 'creating queue', 0, 15);
|
||||
$result = $this->_cache->get($name);
|
||||
|
||||
$this->_queues[] = $name;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -175,6 +191,11 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
$response = $this->_sendCommand('delete ' . $name, array('DELETED', 'NOT_FOUND'), true);
|
||||
|
||||
if (in_array('DELETED', $response)) {
|
||||
$key = array_search($name, $this->_queues);
|
||||
|
||||
if ($key !== false) {
|
||||
unset($this->_queues[$key]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -192,14 +213,15 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
*/
|
||||
public function getQueues()
|
||||
{
|
||||
$this->_queues = array();
|
||||
|
||||
$response = $this->_sendCommand('stats queue', array('END'));
|
||||
$list = array();
|
||||
|
||||
foreach ($response as $i => $line) {
|
||||
$list[] = str_replace('STAT ', '', $line);
|
||||
$this->_queues[] = str_replace('STAT ', '', $line);
|
||||
}
|
||||
|
||||
return $list;
|
||||
return $this->_queues;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,6 +301,7 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
if ($maxMessages === null) {
|
||||
$maxMessages = 1;
|
||||
}
|
||||
|
||||
if ($timeout === null) {
|
||||
$timeout = self::RECEIVE_TIMEOUT_DEFAULT;
|
||||
}
|
||||
@ -287,13 +310,15 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
}
|
||||
|
||||
$msgs = array();
|
||||
for ($i = 0; $i < $maxMessages; $i++) {
|
||||
$data = array(
|
||||
'handle' => md5(uniqid(rand(), true)),
|
||||
'body' => $this->_cache->get($queue->getName()),
|
||||
);
|
||||
if ($maxMessages > 0 ) {
|
||||
for ($i = 0; $i < $maxMessages; $i++) {
|
||||
$data = array(
|
||||
'handle' => md5(uniqid(rand(), true)),
|
||||
'body' => $this->_cache->get($queue->getName()),
|
||||
);
|
||||
|
||||
$msgs[] = $data;
|
||||
$msgs[] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
$options = array(
|
||||
@ -372,8 +397,10 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
*/
|
||||
protected function _sendCommand($command, array $terminator, $include_term=false)
|
||||
{
|
||||
$fp = fsockopen($this->_host, $this->_port, $errno, $errstr, 10);
|
||||
if ($fp === false) {
|
||||
if (!is_resource($this->_socket)) {
|
||||
$this->_socket = fsockopen($this->_host, $this->_port, $errno, $errstr, 10);
|
||||
}
|
||||
if ($this->_socket === false) {
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception("Could not open a connection to $this->_host:$this->_port errno=$errno : $errstr");
|
||||
}
|
||||
@ -381,11 +408,11 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
$response = array();
|
||||
|
||||
$cmd = $command . self::EOL;
|
||||
fwrite($fp, $cmd);
|
||||
fwrite($this->_socket, $cmd);
|
||||
|
||||
$continue_reading = true;
|
||||
while (!feof($fp) && $continue_reading) {
|
||||
$resp = trim(fgets($fp, 1024));
|
||||
while (!feof($this->_socket) && $continue_reading) {
|
||||
$resp = trim(fgets($this->_socket, 1024));
|
||||
if (in_array($resp, $terminator)) {
|
||||
if ($include_term) {
|
||||
$response[] = $resp;
|
||||
@ -396,10 +423,6 @@ class Zend_Queue_Adapter_Memcacheq extends Zend_Queue_Adapter_AdapterAbstract
|
||||
}
|
||||
}
|
||||
|
||||
$cmd = 'quit' . self::EOL;
|
||||
fwrite($fp, $cmd);
|
||||
fclose($fp);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -51,17 +51,17 @@ class Zend_Queue_Adapter_PlatformJobQueue extends Zend_Queue_Adapter_AdapterAbst
|
||||
public function __construct($options, Zend_Queue $queue = null)
|
||||
{
|
||||
parent::__construct($options, $queue);
|
||||
|
||||
|
||||
if (!extension_loaded("jobqueue_client")) {
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Platform Job Queue extension does not appear to be loaded');
|
||||
}
|
||||
|
||||
|
||||
if (! isset($this->_options['daemonOptions'])) {
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Job Queue host and password should be provided');
|
||||
throw new Zend_Queue_Exception('Job Queue host and password should be provided');
|
||||
}
|
||||
|
||||
|
||||
$options = $this->_options['daemonOptions'];
|
||||
|
||||
if (!array_key_exists('host', $options)) {
|
||||
@ -72,7 +72,7 @@ class Zend_Queue_Adapter_PlatformJobQueue extends Zend_Queue_Adapter_AdapterAbst
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Platform Job Queue password should be provided');
|
||||
}
|
||||
|
||||
|
||||
$this->_zendQueue = new ZendApi_Queue($options['host']);
|
||||
|
||||
if (!$this->_zendQueue) {
|
||||
@ -83,12 +83,12 @@ class Zend_Queue_Adapter_PlatformJobQueue extends Zend_Queue_Adapter_AdapterAbst
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Job Queue login failed');
|
||||
}
|
||||
|
||||
|
||||
if ($this->_queue) {
|
||||
$this->_queue->setMessageClass('Zend_Queue_Message_PlatformJob');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* Queue management functions
|
||||
********************************************************************/
|
||||
@ -186,21 +186,21 @@ class Zend_Queue_Adapter_PlatformJobQueue extends Zend_Queue_Adapter_AdapterAbst
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($classname);
|
||||
}
|
||||
|
||||
|
||||
if ($message instanceof ZendAPI_Job) {
|
||||
$message = array('data' => $message);
|
||||
}
|
||||
|
||||
|
||||
$zendApiJob = new $classname($message);
|
||||
|
||||
// Unfortunately, the Platform JQ API is PHP4-style...
|
||||
$platformJob = $zendApiJob->getJob();
|
||||
|
||||
|
||||
$jobId = $this->_zendQueue->addJob($platformJob);
|
||||
|
||||
|
||||
if (!$jobId) {
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Failed to add a job to queue: '
|
||||
throw new Zend_Queue_Exception('Failed to add a job to queue: '
|
||||
. $this->_zendQueue->getLastError());
|
||||
}
|
||||
|
||||
@ -222,20 +222,20 @@ class Zend_Queue_Adapter_PlatformJobQueue extends Zend_Queue_Adapter_AdapterAbst
|
||||
if ($maxMessages === null) {
|
||||
$maxMessages = 1;
|
||||
}
|
||||
|
||||
|
||||
if ($queue !== null) {
|
||||
require_once 'Zend/Queue/Exception.php';
|
||||
throw new Zend_Queue_Exception('Queue shouldn\'t be set');
|
||||
throw new Zend_Queue_Exception('Queue shouldn\'t be set');
|
||||
}
|
||||
|
||||
$jobs = $this->_zendQueue->getJobsInQueue(null, $maxMessages, true);
|
||||
|
||||
|
||||
$classname = $this->_queue->getMessageClass();
|
||||
if (!class_exists($classname)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($classname);
|
||||
}
|
||||
|
||||
|
||||
$options = array(
|
||||
'queue' => $this->_queue,
|
||||
'data' => $jobs,
|
||||
@ -270,10 +270,10 @@ class Zend_Queue_Adapter_PlatformJobQueue extends Zend_Queue_Adapter_AdapterAbst
|
||||
. 'Zend_Queue_Message_PlatformJob may be used'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return $this->_zendQueue->removeJob($message->getJobId());
|
||||
}
|
||||
|
||||
|
||||
public function isJobIdExist($id)
|
||||
{
|
||||
return (($this->_zendQueue->getJob($id))? true : false);
|
||||
@ -319,7 +319,7 @@ class Zend_Queue_Adapter_PlatformJobQueue extends Zend_Queue_Adapter_AdapterAbst
|
||||
{
|
||||
return array('_options');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unserialize
|
||||
*
|
||||
|
Reference in New Issue
Block a user