Skip to content

Commit

Permalink
Merge aa37f0c into e56040b
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnert committed Jul 4, 2018
2 parents e56040b + aa37f0c commit 53d64f6
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 45 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: php
php:
- 7.0
- 5.6
- 5.5

matrix:
allow_failures:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Version 4.0.0

## Bugfixes

* None

## Features

* Add addtional methods to AbstractMethod to improve message handling

# Version 3.0.0

## Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion build.default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
#--------------------------------------------------------------------------------

# ---- Module Release Settings --------------------------------------------------
release.version = 3.0.0
release.version = 4.0.0
79 changes: 40 additions & 39 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
{
"name" : "appserver-io/messaging",
"description" : "Messaging components implementing the PMS PSR",
"homepage" : "https://github.com/appserver-io/messaging",
"license" : "OSL-3.0",
"authors" : [{
"name" : "Tim Wagner",
"email" : "tw@appserver.io",
"homepage" : "https://github.com/wagnert",
"role" : "Developer"
}
],
"require" : {
"php" : ">=5.4.0",
"rhumsaa/uuid" : "~2.4",
"guzzle/guzzle" : "3.9.*",
"appserver-io/properties" : "~2.0",
"appserver-io-psr/pms" : "~1.0",
"appserver-io-psr/socket" : "~1.0",
"appserver-io-psr/application" : "~1.0"
},
"require-dev" : {
"appserver-io/build" : "~1.0"
},
"autoload" : {
"psr-0" : {
"AppserverIo\\Messaging" : [
"src/",
"tests/"
]
}
},
"support" : {
"email" : "t.wagner@techdivision.com",
"issues" : "https://github.com/appserver-io/messaging/issues",
"source" : "https://github.com/appserver-io/messaging"
},
"keywords" : [
"messaging pms components"
]
"name": "appserver-io/messaging",
"description": "Messaging components implementing the PMS PSR",
"homepage": "https://github.com/appserver-io/messaging",
"license": "OSL-3.0",
"authors": [
{
"name": "Tim Wagner",
"email": "tw@appserver.io",
"homepage": "https://github.com/wagnert",
"role": "Developer"
}
],
"require": {
"php": ">=5.4.0",
"rhumsaa/uuid": "~2.4",
"guzzle/guzzle": "3.9.*",
"appserver-io/properties": "~2.0",
"appserver-io-psr/pms": "~2.0",
"appserver-io-psr/socket": "~1.0",
"appserver-io-psr/application": "~1.0"
},
"require-dev": {
"appserver-io/build": "~1.0"
},
"autoload": {
"psr-0": {
"AppserverIo\\Messaging": [
"src/",
"tests/"
]
}
},
"support": {
"email": "t.wagner@techdivision.com",
"issues": "https://github.com/appserver-io/messaging/issues",
"source": "https://github.com/appserver-io/messaging"
},
"keywords": [
"messaging pms components"
]
}
140 changes: 140 additions & 0 deletions src/AppserverIo/Messaging/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
use AppserverIo\Messaging\Utils\PriorityLow;
use AppserverIo\Messaging\Utils\StateKeys;
use AppserverIo\Messaging\Utils\StateActive;
use AppserverIo\Messaging\Utils\StateFailed;
use AppserverIo\Messaging\Utils\StateProcessed;
use AppserverIo\Messaging\Utils\StatePaused;
use AppserverIo\Lang\Reflection\ReflectionObject;

/**
* The abstract superclass for all messages.
Expand Down Expand Up @@ -91,6 +95,20 @@ abstract class AbstractMessage implements MessageInterface, \Serializable
*/
protected $locked = null;

/**
* The array with the timeouts for the retries.
*
* @var array
*/
protected $retryTimeouts = array();

/**
* The array with the callbacks.
*
* @var array
*/
protected $callbacks = array();

/**
* Initializes the message with the array
* to send to the queue.
Expand Down Expand Up @@ -293,4 +311,126 @@ public function unserialize($data)
$this->$propertyName = $propertyValue;
}
}

/**
* Set's the array with the retry timeouts which is also responsible
* for the the number of retries.
*
* @param array $retryTimeouts The number of retries with their timeouts
*
* @return void
*/
public function setRetryTimeouts(array $retryTimeouts)
{
$this->retryTimeouts = $retryTimeouts;
}

/**
* Return's the array with the retry timeouts.
*
* @return array The retry timeouts
*/
public function getRetryTimeouts()
{
return $this->retryTimeouts;
}

/**
* Return's the timeout for the given retry.
*
* @param integer $retry The retry to return the timeout for
*
* @return integer The timeout in seconds for the passed retry
* @throws \InvalidArgumentException Is thrown if the timeout for the passed retry is NOT available
*/
public function getRetryTimeout($retry)
{

// try to find the timeout for the passed retry
if (isset($this->retryTimeouts[$retry])) {
return $this->retryTimeouts[$retry];
}

// throw an exception if the timeout is NOT available
throw new \InvalidArgumentException(sprintf('Can\t find timeout information for retry %d', $retry));
}

/**
* Return's the number of retries for this message.
*
* @return integer The number of retries
*/
public function getRetryCounter()
{
return sizeof($this->getRetryTimeouts());
}

/**
* Add's the callback for the given state.
*
* @param \AppserverIo\Psr\Pms\StateKeyInterface $state The state to register the callback for
* @param array $callback The array with the bean's lookup and method name that has to be invoked
*
* @return void
* @throws \Exception Is thrown if the passed state doesn't support callbacks
*/
public function addCallback(StateKeyInterface $state, array $callback)
{

// query whether or not the state supports callbacks
if (in_array($state->getState(), array(StateFailed::KEY, StateProcessed::KEY, StatePaused::KEY))) {
// initialize the array with the state callbacks, if not already done
if (!isset($this->callbacks[$state->getState()])) {
$this->callbacks[$state->getState()] = array();
}

// add the callback to the state
array_push($this->callbacks[$state->getState()], $callback);

// return immediately
return;
}

// throw an exception, if the passed state doesn't support callbacks
throw new \Exception(
sprintf(
'Callbacks for state %s is not supported, state has to be either one of StateFailed, StateProcessed or StatePaused',
(new ReflectionObject($state))->getShortName()
)
);
}

/**
* Return's the callback information for the given state.
*
* @param \AppserverIo\Psr\Pms\StateKeyInterface $state The state to register the callback for
*
* @return array The array with the callback information
*/
public function getCallbacks(StateKeyInterface $state)
{

// initialize the array with the callbacks
$callbacks = array();

// try to find the callback for the passed state
if (isset($this->callbacks[$state->getState()])) {
$callbacks = $this->callbacks[$state->getState()];
}

// return the array with the callbacks
return $callbacks;
}

/**
* Return's whether or not callbacks for the passed state has been registered.
*
* @param \AppserverIo\Psr\Pms\StateKeyInterface $state The state to register the callback for
*
* @return boolean TRUE if callbacks has been registered, else FALSE
*/
public function hasCallbacks(StateKeyInterface $state)
{
return isset($this->callbacks[$state->getState()]);
}
}
1 change: 0 additions & 1 deletion src/AppserverIo/Messaging/AbstractMessageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use AppserverIo\Psr\Pms\MessageInterface;
use AppserverIo\Psr\Pms\MessageListenerInterface;
use AppserverIo\Psr\Pms\MessageQueueException;
use AppserverIo\Psr\Application\ApplicationInterface;
use AppserverIo\Psr\Pms\QueueContextInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/AppserverIo/Messaging/MessageQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MessageQueueTest extends \PHPUnit_Framework_TestCase
* Initializes the method we wan to test.
*
* @return void
* @see PHPUnit_Framework_TestCase::setUp()
* @see \PHPUnit_Framework_TestCase::setUp()
*/
protected function setUp()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/AppserverIo/Messaging/QueueResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class QueueResponseTest extends \PHPUnit_Framework_TestCase
* Initializes the method we wan to test.
*
* @return void
* @see PHPUnit_Framework_TestCase::setUp()
* @see \PHPUnit_Framework_TestCase::setUp()
*/
protected function setUp()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/AppserverIo/Messaging/StringMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class StringMessageTest extends \PHPUnit_Framework_TestCase
* Initializes the instance we want to run the testcases for.
*
* @return void
* @see PHPUnit_Framework_TestCase::setUp()
* @see \PHPUnit_Framework_TestCase::setUp()
*/
public function setUp()
{
Expand Down

0 comments on commit 53d64f6

Please sign in to comment.