/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $limit = Core\Convert::toInteger($this->policy->getValue('limit')); if ($this->calls < $limit) { $status = BT\Task\Handler::process($this->task, $exchange); $this->calls++; return $status; } return BT\Task\Status::FAILED; }
/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $max_count = Core\Convert::toInteger($this->policy->getValue('max_count')); if ($this->counter < $max_count) { $this->counter++; return BT\Task\Status::ACTIVE; } $this->counter = 0; $status = BT\Task\Handler::process($this->task, $exchange); return $status; }
/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $order = $exchange->getIn()->getBody()->Order; $zip = Core\Convert::toInteger($order->shipToAddress->zip); $begin = Core\Convert::toInteger($this->policy->getValue('begin')); $end = Core\Convert::toInteger($this->policy->getValue('end')); if ($zip >= $begin && $zip <= $end) { return BT\Task\Status::SUCCESS; } return BT\Task\Status::FAILED; }
/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $callable = explode(',', $this->policy->getValue('callable')); $options = Core\Convert::toInteger($this->policy->getValue('options')); $probability = Core\Convert::toDouble($this->policy->hasKey('odds')) * $options; if (call_user_func($callable, array(1, $options)) <= $probability) { $status = BT\Task\Handler::process($this->task, $exchange); return $status; } return BT\Task\Status::ACTIVE; }
/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $shuffle = Core\Convert::toBoolean($this->policy->getValue('shuffle')); if ($shuffle) { $this->tasks->shuffle(); } $index = Core\Convert::toInteger($this->policy->getValue('index')); if ($this->tasks->hasIndex($index)) { return BT\Task\Handler::process($this->tasks->getValue($index), $exchange); } return BT\Task\Status::ERROR; }
/** * This constructor initializes the class with the specified parameters. * * @access public * @param Common\Mutable\IMap $blackboard the blackboard to be used * @param Common\Mutable\IMap $policy the policy associated with the task */ public function __construct(Common\Mutable\IMap $blackboard = null, Common\Mutable\IMap $policy = null) { parent::__construct($blackboard, $policy); if ($this->policy->hasKey('status')) { $status = $this->policy->getValue('status'); if (is_string($status)) { $status = BT\Task\Status::valueOf($status); } $this->policy->putEntry('status', Core\Convert::toInteger($status)); } else { $this->policy->putEntry('status', BT\Task\Status::SUCCESS); } }
/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $delay = Core\Convert::toInteger($this->policy->getValue('delay')) / 1000; // milliseconds => seconds $deltaT = microtime(true) - $this->start_time; if ($deltaT >= $delay) { $duration = Core\Convert::toInteger($this->policy->getValue('duration')) / 1000; // milliseconds => seconds if ($deltaT < $delay + $duration) { return BT\Task\Handler::process($this->task, $exchange); } } return BT\Task\Status::INACTIVE; }
/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $count = $this->tasks->count(); if ($count > 0) { $shuffle = Core\Convert::toBoolean($this->policy->getValue('shuffle')); if ($shuffle) { $this->tasks->shuffle(); } $inactivesCt = 0; $successesCt = 0; $successesMax = min(Core\Convert::toInteger($this->policy->getValue('successes')), $count); $failuresCt = 0; $failuresMax = min(Core\Convert::toInteger($this->policy->getValue('failures')), $count); foreach ($this->tasks as $task) { $status = BT\Task\Handler::process($task, $exchange); switch ($status) { case BT\Task\Status::INACTIVE: $inactivesCt++; break; case BT\Task\Status::ACTIVE: break; case BT\Task\Status::SUCCESS: $successesCt++; if ($successesCt >= $successesMax) { return BT\Task\Status::SUCCESS; } break; case BT\Task\Status::FAILED: $failuresCt++; if ($failuresCt >= $failuresMax) { return BT\Task\Status::FAILED; } break; case BT\Task\Status::ERROR: case BT\Task\Status::QUIT: return $status; } } if ($inactivesCt != $count) { return BT\Task\Status::ACTIVE; } } return BT\Task\Status::INACTIVE; }
/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $steps = Core\Convert::toInteger($this->policy->getValue('steps')); if ($this->policy->getValue('reverse')) { // direction for ($i = $steps - 1; $i >= 0; $i--) { $status = BT\Task\Handler::process($this->task, $exchange); if (!in_array($status, array(BT\Task\Status::SUCCESS, BT\Task\Status::FAILED, BT\Task\Status::ERROR, BT\Task\Status::QUIT))) { return $status; } } } else { for ($i = 0; $i < $steps; $i++) { $status = BT\Task\Handler::process($this->task, $exchange); if (!in_array($status, array(BT\Task\Status::SUCCESS, BT\Task\Status::FAILED, BT\Task\Status::ERROR, BT\Task\Status::QUIT))) { return $status; } } } return BT\Task\Status::SUCCESS; }
/** * This method attempts to resolve the value as an integer in accordance with the schema * definition. * * @access public * @static * @param mixed $value the value to be resolved * @param array $definition the schema definition * @return mixed the resolved value * @throws Throwable\Runtime\Exception indicates that the value failed * to meet a requirement */ public static function resolveIntegerValue($value, $definition) { if (MappingService\Data\ToolKit::isUnset($value)) { if (isset($definition['required']) && $definition['required']) { throw new Throwable\Runtime\Exception('Invalid value defined. Expected a value that is an integer, but got :type.', array(':type' => Core\DataType::info($value)->type)); } return $value; } $value = Core\Convert::toInteger($value); if (isset($definition['exclusiveMinimum']) && $definition['exclusiveMinimum']) { if ($value <= $definition['minimum']) { throw new Throwable\Runtime\Exception('Invalid value defined. Expected a value that is greater than ":minimum", but got :value.', array(':minimum' => $definition['minimum'], ':value' => $value)); } } else { if (isset($definition['minimum'])) { if ($value < $definition['minimum']) { throw new Throwable\Runtime\Exception('Invalid value defined. Expected a value that is greater than or equal to ":minimum", but got :value.', array(':minimum' => $definition['minimum'], ':value' => $value)); } } } if (isset($definition['exclusiveMaximum']) && $definition['exclusiveMaximum']) { if ($value >= $definition['maximum']) { throw new Throwable\Runtime\Exception('Invalid value defined. Expected a value that is less than ":maximum", but got :value.', array(':maximum' => $definition['maximum'], ':value' => $value)); } } else { if (isset($definition['maximum'])) { if ($value > $definition['maximum']) { throw new Throwable\Runtime\Exception('Invalid value defined. Expected a value that is less than or equal to ":maximum", but got :value.', array(':maximum' => $definition['maximum'], ':value' => $value)); } } } if (isset($definition['divisibleBy'])) { if ($value % $definition['divisibleBy'] == 0) { throw new Throwable\Runtime\Exception('Invalid value defined. Expected a value that is divisible by ":divisibleBy", but got :value.', array(':divisibleBy' => $definition['divisibleBy'], ':value' => $value)); } } if (isset($definition['pad']['length'])) { $value = Core\Convert::toString($value); if (strlen($value) < $definition['pad']['length']) { $char = isset($definition['pad']['char']) ? $definition['pad']['char'] : '0'; $value = str_pad($value, $definition['pad']['length'], $char, STR_PAD_LEFT); } } if (isset($definition['enum']) && count($definition['enum']) > 0) { if (!in_array($value, $definition['enum'])) { throw new Throwable\Runtime\Exception('Invalid value defined. Expected a value that is in enumeration, but got :value.', array(':value' => $value)); } } return $value; }
/** * This method resets the task. * * @access public */ public function reset() { $this->start_time = microtime(true) + Core\Convert::toInteger($this->policy->getValue('interval')) / 1000; }
/** * This method parses an "integer" node. * * @access protected * @param \SimpleXMLElement $node a reference to the "integer" node * @return integer the value as an integer * @throws \Unicity\Throwable\Parse\Exception indicates that problem occurred while * parsing */ protected function parseIntegerElement(\SimpleXMLElement $node) { $value = dom_import_simplexml($node)->textContent; $value = trim($value); if (!preg_match('/^[+-]?(0|[1-9][0-9]*)$/', $value)) { throw new Throwable\Parse\Exception('Expected an integer number, but got :value for the value.', array(':value' => $value)); } return Core\Convert::toInteger($value); }
/** * This method parses a "number" node. * * @access protected * @param \DOMElement $node a reference to the "number" node * @return number the value as a number * @throws \Unicity\Throwable\Parse\Exception indicates that problem occurred while * parsing */ protected function parseNumberElement(\DOMElement $node) { $value = $node->textContent; $value = trim($value); if (preg_match('/^[+-]?(0|[1-9][0-9]*)((\\.[0-9]+)|([eE][+-]?(0|[1-9][0-9]*)))$/', $value)) { $value = Core\Convert::toDouble($value); } else { if (filter_var($value, FILTER_VALIDATE_INT) !== false) { $value = Core\Convert::toInteger($value); } else { throw new Throwable\Parse\Exception('Expected an integer number, but got :value for the value.', array(':value' => $value)); } } return $value; }
/** * This method parses a child node. * * @access protected * @param \SimpleXMLElement $node a reference to a child node * @return \Unicity\Common\Mutable\ICollection a collection representing the data * in the soap file * @throws \Unicity\Throwable\Parse\Exception indicates that an unrecognized child * node was encountered */ protected function parseChildElement(\SimpleXMLElement $node) { $children = $node->children(); if (count($children) > 0) { $list = new Common\Mutable\ArrayList(); $map = new Common\Mutable\HashMap(); foreach ($children as $child) { $name = $child->getName(); $value = $this->parseChildElement($child); $temp = new Common\Mutable\HashMap(); $temp->putEntry($name, $value); $list->addValue($temp); $map->putEntry($name, $value); } return $list->count() > $map->count() || $this->directives->hasKey('expandableProperties') && $this->directives->getValue('expandableProperties')->hasValue($node->getName()) ? $list : $map; } else { $value = dom_import_simplexml($node)->textContent; $value = trim($value); if ($value == '') { $value = Core\Data\Undefined::instance(); } else { if (preg_match('/^(true|false)$/i', $value)) { $value = Core\Convert::toBoolean($value); } else { if (preg_match('/^[+-]?(0|[1-9][0-9]*)((\\.[0-9]+)|([eE][+-]?(0|[1-9][0-9]*)))$/', $value)) { $value = Core\Convert::toDouble($value); } else { if (filter_var($value, FILTER_VALIDATE_INT) !== false) { $value = Core\Convert::toInteger($value); } else { $value = Core\Convert::toString($value); } } } } return $value; } }
/** * This method parses a custom node. * * @access protected * @param \SimpleXMLElement $node a reference to a custom node * @return \Unicity\Common\Mutable\ICollection a collection representing the data * in the soap file * @throws \Unicity\Throwable\Parse\Exception indicates that an unrecognized child * node was encountered */ protected function parseCustomElement(\SimpleXMLElement $node) { $children = $this->getElementChildren($node, null); if (count($children) > 0) { $list = new Common\Mutable\ArrayList(); $map = new Common\Mutable\HashMap(); foreach ($children as $child) { $name = $child->getName(); $value = $this->parseCustomElement($child); $temp = new Common\Mutable\HashMap(); $temp->putEntry($name, $value); $list->addValue($temp); $map->putEntry($name, $value); } return $list->count() > $map->count() || $this->directives->hasKey('expandableProperties') && $this->directives->getValue('expandableProperties')->hasValue($node->getName()) ? $list : $map; } else { $value = dom_import_simplexml($node)->textContent; $value = trim($value); if ($value == '') { $attributes = $node->attributes('xsi', true); if (isset($attributes['nil'])) { $nil = SOAP\Data\XML::valueOf($attributes['nil']); if (!SOAP\Data\XML\Syntax::isBoolean($nil)) { throw new Throwable\Parse\Exception('Unable to process SOAP XML. Expected a valid boolean token, but got ":token".', array(':token' => $nil)); } $value = strtolower($nil) != 'false' ? null : Core\Data\Undefined::instance(); } else { $value = Core\Data\Undefined::instance(); } } else { if (preg_match('/^(true|false)$/i', $value)) { $value = Core\Convert::toBoolean($value); } else { if (preg_match('/^[+-]?(0|[1-9][0-9]*)((\\.[0-9]+)|([eE][+-]?(0|[1-9][0-9]*)))$/', $value)) { $value = Core\Convert::toDouble($value); } else { if (filter_var($value, FILTER_VALIDATE_INT) !== false) { $value = Core\Convert::toInteger($value); } else { $value = Core\Convert::toString($value); } } } } return $value; } }