Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions lib/storm.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function __construct($debug = false)
$this->pid = getmypid();
$this->sendCommand(array( "pid" => $this->pid ));

$this->_debug = $debug;
$this->_DEBUG = $debug;

if ($this->_DEBUG)
{
$this->stormInc = fopen('/tmp/' . $this->pid . "_" . strtolower($_SERVER['argv'][0]) . '.txt', 'w+');
$this->stormInc = fopen('/tmp/' . $this->pid . "_" . strtolower(basename($_SERVER['argv'][0])) . '.txt', 'w+');
}

$handshake = $this->parseMessage( $this->waitForMessage() );
Expand Down Expand Up @@ -155,8 +155,12 @@ public function run()
$command);

$tuple = new Tuple($tupleMap['id'], $tupleMap['comp'], $tupleMap['stream'], $tupleMap['task'], $tupleMap['tuple']);

$this->process($tuple);

if ($tuple->task == -1 && $tuple->stream === '__heartbeat') {
$this->sync();
} else {
$this->process($tuple);
}
}
}
}
Expand Down Expand Up @@ -233,6 +237,15 @@ protected function fail(Tuple $tuple)

$this->sendCommand($command);
}

protected function sync()
{
$command = array(
'command' => 'sync'
);

$this->sendCommand($command);
}
}

abstract class BasicBolt extends ShellBolt
Expand Down Expand Up @@ -264,9 +277,13 @@ public function run()

try
{
$processed = $this->process($tuple);
if ($tuple->task == -1 && $tuple->stream === '__heartbeat') {
$this->sync();
} else {
$processed = $this->process($tuple);

$this->ack($tuple);
$this->ack($tuple);
}
}
catch (BoltProcessException $e)
{
Expand Down Expand Up @@ -299,7 +316,7 @@ public function __construct()
abstract protected function nextTuple();
abstract protected function ack($tuple_id);
abstract protected function fail($tuple_id);

public function run()
{
while (true)
Expand Down