/**
* The super constructor for all exceptions
*
- * @param $streamInstance An instance of a InputStreamable class
- * @param $data The actual data
+ * @param $messageArray Error message array
+ * @param $code Error code
* @return void
*/
- public function __construct (InputStreamable $streamInstance, $data) {
+ public function __construct (array $messageArray, $code) {
// Construct the message
$message = sprintf('[%s:%d] Cannot handle multiple messages. Please split them before calling this method.',
- $streamInstance->__toString(),
+ $messageArray[0]->__toString(),
$this->getLine()
);
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class PackageAssembler extends BaseHubSystem implements Assembler, Registerable {
+class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, Visitable {
+ /**
+ * Name for stacker holding raw data of multiple messages
+ */
+ const STACKER_NAME_MULTIPLE_MESSAGE = 'multiple_message';
+
/**
* Pending data
*/
// Get stacker instance
$stackerInstance = ObjectFactory::createObjectByConfiguredName('multiple_message_stacker_class');
+ // Initialize the only one stack
+ $stackerInstance->initStack(self::STACKER_NAME_MULTIPLE_MESSAGE);
+
// And add it
$assemblerInstance->setStackerInstance($stackerInstance);
* Multiple messages found, so split off first message as the input
* stream can only handle one message per time.
*/
+ foreach (explode(BaseRawDataHandler::STREAM_START_MARKER, $this->pendingData) as $message) {
+ // Prepend start marker again as it is needed to decode the message.
+ $message = BaseRawDataHandler::STREAM_START_MARKER . $message;
+
+ // Push it on stack
+ $this->getStackerInstance()->pushNamed(self::STACKER_NAME_MULTIPLE_MESSAGE, $message);
+ } // END - foreach
+
+ // Clear pending data
+ $this->clearPendingData();
+
+ // ... and exit here
+ return;
}
// Init fake array
);
// Clear pending data
- $this->pendingData = '';
+ $this->clearPendingData();
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ': Last block of partial data received. A total of ' . strlen($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes has been received.');
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ': Going to add ' . count($chunks) . ' to chunk handler ...');
$this->getHandlerInstance()->addAllChunksWithFinal($chunks);
}
+
+ /**
+ * Accepts the visitor to process the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit the assembler
+ $visitorInstance->visitAssembler($this);
+ }
+
+ /**
+ * Clears pending data
+ *
+ * @return void
+ */
+ public function clearPendingData () {
+ // Clear it
+ $this->pendingData = '';
+ }
}
// [EOF]
*/
public function accept (Visitor $visitorInstance) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - START');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - START');
// Visit the package
$visitorInstance->visitNetworkPackage($this);
+ // Then visit the assembler to handle multiple packages
+ $this->getAssemblerInstance()->accept($visitorInstance);
+
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
}
/**