Merge branch '0.8.x' of git@gitorious.org:statusnet/mainline into 0.8.x

This commit is contained in:
Zach Copley 2009-09-15 14:40:57 -07:00
commit 44af6a9bb4
7 changed files with 100 additions and 131 deletions

View File

@ -47,11 +47,6 @@ class Profile extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */ /* the code above is auto generated do not remove the tag below */
###END_AUTOCODE ###END_AUTOCODE
function &pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Profile', $kv);
}
function getAvatar($width, $height=null) function getAvatar($width, $height=null)
{ {
if (is_null($height)) { if (is_null($height)) {

View File

@ -44,14 +44,14 @@ class Stomp
* *
* @var int * @var int
*/ */
public $prefetchSize = 1; public $prefetchSize = 1;
/** /**
* Client id used for durable subscriptions * Client id used for durable subscriptions
* *
* @var string * @var string
*/ */
public $clientId = null; public $clientId = null;
protected $_brokerUri = null; protected $_brokerUri = null;
protected $_socket = null; protected $_socket = null;
@ -190,11 +190,11 @@ class Stomp
if ($password != '') { if ($password != '') {
$this->_password = $password; $this->_password = $password;
} }
$headers = array('login' => $this->_username , 'passcode' => $this->_password); $headers = array('login' => $this->_username , 'passcode' => $this->_password);
if ($this->clientId != null) { if ($this->clientId != null) {
$headers["client-id"] = $this->clientId; $headers["client-id"] = $this->clientId;
} }
$frame = new Stomp_Frame("CONNECT", $headers); $frame = new Stomp_Frame("CONNECT", $headers);
$this->_writeFrame($frame); $this->_writeFrame($frame);
$frame = $this->readFrame(); $frame = $this->readFrame();
if ($frame instanceof Stomp_Frame && $frame->command == 'CONNECTED') { if ($frame instanceof Stomp_Frame && $frame->command == 'CONNECTED') {
@ -237,7 +237,7 @@ class Stomp
* @param boolean $sync Perform request synchronously * @param boolean $sync Perform request synchronously
* @return boolean * @return boolean
*/ */
public function send ($destination, $msg, $properties = array(), $sync = null) public function send ($destination, $msg, $properties = null, $sync = null)
{ {
if ($msg instanceof Stomp_Frame) { if ($msg instanceof Stomp_Frame) {
$msg->headers['destination'] = $destination; $msg->headers['destination'] = $destination;
@ -319,12 +319,10 @@ class Stomp
public function subscribe ($destination, $properties = null, $sync = null) public function subscribe ($destination, $properties = null, $sync = null)
{ {
$headers = array('ack' => 'client'); $headers = array('ack' => 'client');
// FIXME: this seems to be activemq specific, but not hurting rabbitmq? $headers['activemq.prefetchSize'] = $this->prefetchSize;
$headers['activemq.prefetchSize'] = $this->prefetchSize; if ($this->clientId != null) {
if ($this->clientId != null) { $headers["activemq.subcriptionName"] = $this->clientId;
// FIXME: this seems to be activemq specific, but not hurting rabbitmq? }
$headers["activemq.subcriptionName"] = $this->clientId;
}
if (isset($properties)) { if (isset($properties)) {
foreach ($properties as $name => $value) { foreach ($properties as $name => $value) {
$headers[$name] = $value; $headers[$name] = $value;
@ -426,7 +424,7 @@ class Stomp
} }
/** /**
* Acknowledge consumption of a message from a subscription * Acknowledge consumption of a message from a subscription
* Note: This operation is always asynchronous * Note: This operation is always asynchronous
* *
* @param string|Stomp_Frame $messageMessage ID * @param string|Stomp_Frame $messageMessage ID
* @param string $transactionId * @param string $transactionId
@ -435,26 +433,20 @@ class Stomp
*/ */
public function ack ($message, $transactionId = null) public function ack ($message, $transactionId = null)
{ {
// Handle the headers,
$headers = array();
if ($message instanceof Stomp_Frame) { if ($message instanceof Stomp_Frame) {
// Copy headers from the object $frame = new Stomp_Frame('ACK', $message->headers);
// FIXME: at least content-length can be wrong here (set to 3 sometimes). $this->_writeFrame($frame);
$headers = $message->headers; return true;
} else { } else {
$headers = array();
if (isset($transactionId)) { if (isset($transactionId)) {
$headers['transaction'] = $transactionId; $headers['transaction'] = $transactionId;
} }
$headers['message-id'] = $message; $headers['message-id'] = $message;
$frame = new Stomp_Frame('ACK', $headers);
$this->_writeFrame($frame);
return true;
} }
// An ACK has no content
$headers['content-length'] = 0;
// Create it and write it out
$frame = new Stomp_Frame('ACK', $headers);
$this->_writeFrame($frame);
return true;
} }
/** /**
* Graceful disconnect from the server * Graceful disconnect from the server
@ -462,11 +454,11 @@ class Stomp
*/ */
public function disconnect () public function disconnect ()
{ {
$headers = array(); $headers = array();
if ($this->clientId != null) { if ($this->clientId != null) {
$headers["client-id"] = $this->clientId; $headers["client-id"] = $this->clientId;
} }
if (is_resource($this->_socket)) { if (is_resource($this->_socket)) {
$this->_writeFrame(new Stomp_Frame('DISCONNECT', $headers)); $this->_writeFrame(new Stomp_Frame('DISCONNECT', $headers));
@ -524,26 +516,16 @@ class Stomp
$rb = 1024; $rb = 1024;
$data = ''; $data = '';
do { do {
$read = fread($this->_socket, $rb); $read = fgets($this->_socket, $rb);
if ($read === false) { if ($read === false) {
$this->_reconnect(); $this->_reconnect();
return $this->readFrame(); return $this->readFrame();
} }
$data .= $read; $data .= $read;
$len = strlen($data); $len = strlen($data);
} while (($len < 2 || ! ($data[$len - 2] == "\x00" && $data[$len - 1] == "\n")));
$continue = true;
// ActiveMq apparently add \n after 0 char
if($data[$len - 2] == "\x00" && $data[$len - 1] == "\n") {
$continue = false;
}
// RabbitMq does not
if($data[$len - 1] == "\x00") {
$continue = false;
}
} while ( $continue );
list ($header, $body) = explode("\n\n", $data, 2); list ($header, $body) = explode("\n\n", $data, 2);
$header = explode("\n", $header); $header = explode("\n", $header);
$headers = array(); $headers = array();

View File

@ -74,8 +74,7 @@ class Stomp_Frame
$data .= "\n"; $data .= "\n";
$data .= $this->body; $data .= $this->body;
$data .= "\x00\n"; // Should there really be a linefeed here? return $data .= "\x00\n";
return $data;
} }
} }
?> ?>

View File

@ -29,12 +29,8 @@ require_once 'Stomp/Frame.php';
*/ */
class Stomp_Message extends Stomp_Frame class Stomp_Message extends Stomp_Frame
{ {
public function __construct ($body, $headers = array()) public function __construct ($body, $headers = null)
{ {
if(!isset($headers['content-length'])) {
// TODO: log this, to see if this is correct
$headers['content-length'] = strlen($body);
}
$this->_init("SEND", $headers, $body); $this->_init("SEND", $headers, $body);
} }
} }

View File

@ -900,7 +900,6 @@ class Action extends HTMLOutputter // lawsuit
!$etag || !$etag ||
$this->_hasEtag($etag, $if_none_match)) { $this->_hasEtag($etag, $if_none_match)) {
header('HTTP/1.1 304 Not Modified'); header('HTTP/1.1 304 Not Modified');
header('Content-Length: 0');
// Better way to do this? // Better way to do this?
exit(0); exit(0);
} }
@ -919,7 +918,6 @@ class Action extends HTMLOutputter // lawsuit
header('ETag: ' . $etag); header('ETag: ' . $etag);
if($if_none_match && $this->_hasEtag($etag, $if_none_match)) { if($if_none_match && $this->_hasEtag($etag, $if_none_match)) {
header('HTTP/1.1 304 Not Modified'); header('HTTP/1.1 304 Not Modified');
header('Content-Length: 0');
// Better way to do this? // Better way to do this?
exit(0); exit(0);
} }

View File

@ -141,11 +141,10 @@ class StompQueueManager
$this->con->ack($frame); $this->con->ack($frame);
} else { } else {
if ($handler->handle_notice($notice)) { if ($handler->handle_notice($notice)) {
$this->_log(LOG_INFO, 'Successfully handled notice '. $notice->id .' originally posted at ' . $notice->created . ' in queue '. $queue); $this->_log(LOG_INFO, 'Successfully handled notice '. $notice->id .' posted at ' . $frame->headers['created'] . ' in queue '. $queue);
$this->con->ack($frame); $this->con->ack($frame);
} else { } else {
$this->_log(LOG_WARNING, 'Failed handling notice '. $notice->id .' originally posted at ' . $notice->created . ' in queue '. $queue); $this->_log(LOG_WARNING, 'Failed handling notice '. $notice->id .' posted at ' . $frame->headers['created'] . ' in queue '. $queue);
// FIXME we probably shouldn't have to do // FIXME we probably shouldn't have to do
// this kind of queue management ourselves // this kind of queue management ourselves
$this->con->ack($frame); $this->con->ack($frame);

View File

@ -62,7 +62,7 @@ class AutocompleteAction extends Action
$user->whereAdd('nickname like \'' . trim($user->escape($q), '\'') . '%\''); $user->whereAdd('nickname like \'' . trim($user->escape($q), '\'') . '%\'');
$user->find(); $user->find();
while($user->fetch()) { while($user->fetch()) {
$profile = Profile::pkeyGet(array('id' => $user->id)); $profile = Profile::staticGet($user->id);
$this->results[]=array('nickname' => $user->nickname, 'fullname'=> $profile->fullname, 'type'=>'user'); $this->results[]=array('nickname' => $user->nickname, 'fullname'=> $profile->fullname, 'type'=>'user');
} }
} }