* 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]