]> git.mxchange.org Git - hub.git/blob - application/hub/main/package/class_NetworkPackage.php
Debug line added, inline comment improved
[hub.git] / application / hub / main / package / class_NetworkPackage.php
1 <?php
2 /**
3  * A NetworkPackage class. This class implements Deliverable and Receivable
4  * because all network packages should be deliverable to other nodes and
5  * receivable from other nodes. It further provides methods for reading raw
6  * content from template engines and feeding it to the stacker for undeclared
7  * packages.
8  *
9  * The factory method requires you to provide a compressor class (which must
10  * implement the Compressor interface). If you don't want any compression (not
11  * adviceable due to increased network load), please use the NullCompressor
12  * class and encode it with BASE64 for a more error-free transfer over the
13  * Internet.
14  *
15  * For performance reasons, this class should only be instanciated once and then
16  * used as a "pipe-through" class.
17  *
18  * @author              Roland Haeder <webmaster@ship-simu.org>
19  * @version             0.0.0
20  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
21  * @license             GNU GPL 3.0 or any newer version
22  * @link                http://www.ship-simu.org
23  * @todo                Needs to add functionality for handling the object's type
24  *
25  * This program is free software: you can redistribute it and/or modify
26  * it under the terms of the GNU General Public License as published by
27  * the Free Software Foundation, either version 3 of the License, or
28  * (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License
36  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
37  */
38 class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receivable, Registerable, Visitable {
39         /**
40          * Package mask for compressing package data:
41          * 0: Compressor extension
42          * 1: Raw package data
43          * 2: Tags, seperated by semicolons, no semicolon is required if only one tag is needed
44          * 3: Checksum
45          *                     0  1  2  3
46          */
47         const PACKAGE_MASK = '%s:%s:%s:%s';
48
49         /**
50          * Seperator for the above mask
51          */
52         const PACKAGE_MASK_SEPERATOR = ':';
53
54         /**
55          * Seperator for checksum
56          */
57         const PACKAGE_CHECKSUM_SEPERATOR = ':';
58
59         /**
60          * Array indexes for above mask, start with zero
61          */
62         const INDEX_COMPRESSOR_EXTENSION = 0;
63         const INDEX_PACKAGE_DATA         = 1;
64         const INDEX_TAGS                 = 2;
65         const INDEX_CHECKSUM             = 3;
66
67         /**
68          * Array indexes for raw package array
69          */
70         const INDEX_PACKAGE_SENDER    = 0;
71         const INDEX_PACKAGE_RECIPIENT = 1;
72         const INDEX_PACKAGE_CONTENT   = 2;
73
74         /**
75          * Named array elements for package data
76          */
77         const PACKAGE_DATA_SENDER    = 'sender';
78         const PACKAGE_DATA_RECIPIENT = 'recipient';
79         const PACKAGE_DATA_CONTENT   = 'content';
80
81         /**
82          * Tags seperator
83          */
84         const PACKAGE_TAGS_SEPERATOR = ';';
85
86         /**
87          * Raw package data seperator
88          */
89         const PACKAGE_DATA_SEPERATOR = '#';
90
91         /**
92          * Stacker name for "undeclared" packages
93          */
94         const STACKER_NAME_UNDECLARED = 'package_undeclared';
95
96         /**
97          * Stacker name for "declared" packages (which are ready to send out)
98          */
99         const STACKER_NAME_DECLARED = 'package_declared';
100
101         /**
102          * Stacker name for "out-going" packages
103          */
104         const STACKER_NAME_OUTGOING = 'package_outgoing';
105
106         /**
107          * Stacker name for "incoming" decoded raw data
108          */
109         const STACKER_NAME_DECODED_INCOMING = 'package_decoded_data';
110
111         /**
112          * Stacker name for handled decoded raw data
113          */
114         const STACKER_NAME_DECODED_HANDLED = 'package_handled_decoded';
115
116         /**
117          * Stacker name for "back-buffered" packages
118          */
119         const STACKER_NAME_BACK_BUFFER = 'package_backbuffer';
120
121         /**
122          * Network target (alias): 'upper hubs'
123          */
124         const NETWORK_TARGET_UPPER_HUBS = 'upper';
125
126         /**
127          * Network target (alias): 'self'
128          */
129         const NETWORK_TARGET_SELF = 'self';
130
131         /**
132          * TCP package size in bytes
133          */
134         const TCP_PACKAGE_SIZE = 512;
135
136         /**
137          * Protected constructor
138          *
139          * @return      void
140          */
141         protected function __construct () {
142                 // Call parent constructor
143                 parent::__construct(__CLASS__);
144         }
145
146         /**
147          * Creates an instance of this class
148          *
149          * @param       $compressorInstance             A Compressor instance for compressing the content
150          * @return      $packageInstance                An instance of a Deliverable class
151          */
152         public static final function createNetworkPackage (Compressor $compressorInstance) {
153                 // Get new instance
154                 $packageInstance = new NetworkPackage();
155
156                 // Now set the compressor instance
157                 $packageInstance->setCompressorInstance($compressorInstance);
158
159                 /*
160                  * We need to initialize a stack here for our packages even for those
161                  * which have no recipient address and stamp... ;-) This stacker will
162                  * also be used for incoming raw data to handle it.
163                  */
164                 $stackerInstance = ObjectFactory::createObjectByConfiguredName('network_package_stacker_class');
165
166                 // At last, set it in this class
167                 $packageInstance->setStackerInstance($stackerInstance);
168
169                 // Init all stacker
170                 $packageInstance->initStackers();
171
172                 // Get a visitor instance for speeding up things
173                 $visitorInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_monitor_visitor_class', array($packageInstance));
174
175                 // Set it in this package
176                 $packageInstance->setVisitorInstance($visitorInstance);
177
178                 // Return the prepared instance
179                 return $packageInstance;
180         }
181
182         /**
183          * Initialize all stackers
184          *
185          * @return      void
186          */
187         protected function initStackers () {
188                 // Initialize all
189                 foreach (
190                         array(
191                                 self::STACKER_NAME_UNDECLARED,
192                                 self::STACKER_NAME_DECLARED,
193                                 self::STACKER_NAME_OUTGOING,
194                                 self::STACKER_NAME_DECODED_INCOMING,
195                                 self::STACKER_NAME_DECODED_HANDLED,
196                                 self::STACKER_NAME_BACK_BUFFER
197                         ) as $stackerName) {
198                                 // Init this stacker
199                                 $this->getStackerInstance()->initStacker($stackerName);
200                 } // END - foreach
201         }
202
203         /**
204          * "Getter" for hash from given content and helper instance
205          *
206          * @param       $content                        Raw package content
207          * @param       $helperInstance         An instance of a HelpableHub class
208          * @param       $nodeInstance           An instance of a NodeHelper class
209          * @return      $hash                           Hash for given package content
210          * @todo        $helperInstance is unused
211          */
212         private function getHashFromContent ($content, HelpableHub $helperInstance, NodeHelper $nodeInstance) {
213                 // Create the hash
214                 // @TODO crc32() is not very strong, but it needs to be fast
215                 $hash = crc32(
216                         $content .
217                         self::PACKAGE_CHECKSUM_SEPERATOR .
218                         $nodeInstance->getSessionId() .
219                         self::PACKAGE_CHECKSUM_SEPERATOR .
220                         $this->getCompressorInstance()->getCompressorExtension()
221                 );
222
223                 // And return it
224                 return $hash;
225         }
226
227         ///////////////////////////////////////////////////////////////////////////
228         //                   Delivering packages / raw data
229         ///////////////////////////////////////////////////////////////////////////
230
231         /**
232          * Delivers the given raw package data.
233          *
234          * @param       $packageData    Raw package data in an array
235          * @return      void
236          */
237         private function declareRawPackageData (array $packageData) {
238                 /*
239                  * We need to disover every recipient, just in case we have a
240                  * multi-recipient entry like 'upper' is. 'all' may be a not so good
241                  * target because it causes an overload on the network and may be
242                  * abused for attacking the network with large packages.
243                  */
244                 $discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
245
246                 // Discover all recipients, this may throw an exception
247                 $discoveryInstance->discoverRecipients($packageData);
248
249                 // Now get an iterator
250                 $iteratorInstance = $discoveryInstance->getIterator();
251
252                 // ... and begin iteration
253                 while ($iteratorInstance->valid()) {
254                         // Get current entry
255                         $currentRecipient = $iteratorInstance->current();
256
257                         // Debug message
258                         $this->debugOutput('PACKAGE: Package declared for recipient ' . $currentRecipient);
259
260                         // Set the recipient
261                         $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
262
263                         // And enqueue it to the writer class
264                         $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
265
266                         // Skip to next entry
267                         $iteratorInstance->next();
268                 } // END - while
269
270                 /*
271                  * The recipient list can be cleaned up here because the package which
272                  * shall be delivered has been added for all entries from the list.
273                  */
274                 $discoveryInstance->clearRecipients();
275         }
276
277         /**
278          * Delivers raw package data. In short, this will discover the raw socket
279          * resource through a discovery class (which will analyse the receipient of
280          * the package), register the socket with the connection (handler/helper?)
281          * instance and finally push the raw data on our outgoing queue.
282          *
283          * @param       $packageData    Raw package data in an array
284          * @return      void
285          */
286         private function deliverRawPackageData (array $packageData) {
287                 /*
288                  * This package may become big, depending on the shared object size or
289                  * delivered message size which shouldn't be so long (to save
290                  * bandwidth). Because of the nature of the used protocol (TCP) we need
291                  * to split it up into smaller pieces to fit it into a TCP frame.
292                  *
293                  * So first we need (again) a discovery class but now a protocol
294                  * discovery to choose the right socket resource. The discovery class
295                  * should take a look at the raw package data itself and then decide
296                  * which (configurable!) protocol should be used for that type of
297                  * package.
298                  */
299                 $discoveryInstance = SocketDiscoveryFactory::createSocketDiscoveryInstance();
300
301                 // Now discover the right protocol
302                 $socketResource = $discoveryInstance->discoverSocket($packageData);
303
304                 // Debug message
305                 //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after discoverSocket() has been called.');
306
307                 // We have to put this socket in our registry, so get an instance
308                 $registryInstance = SocketRegistry::createSocketRegistry();
309
310                 // Get the listener from registry
311                 $helperInstance = Registry::getRegistry()->getInstance('connection');
312
313                 // Debug message
314                 //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.');
315
316                 // Is it not there?
317                 if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) {
318                         // Then register it
319                         $registryInstance->registerSocket($helperInstance, $socketResource, $packageData);
320                 } // END - if
321
322                 // Debug message
323                 //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.');
324
325                 // Make sure the connection is up
326                 $helperInstance->getStateInstance()->validatePeerStateConnected();
327
328                 // Debug message
329                 //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.');
330
331                 // We enqueue it again, but now in the out-going queue
332                 $this->getStackerInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageData);
333         }
334
335         /**
336          * Sends waiting packages
337          *
338          * @param       $packageData    Raw package data
339          * @return      void
340          */
341         private function sendOutgoingRawPackageData (array $packageData) {
342                 // Init sent bytes
343                 $sentBytes = 0;
344
345                 // Get the right connection instance
346                 $helperInstance = SocketRegistry::createSocketRegistry()->getHandlerInstanceFromPackageData($packageData);
347
348                 // Is this connection still alive?
349                 if ($helperInstance->isShuttedDown()) {
350                         // This connection is shutting down
351                         // @TODO We may want to do somthing more here?
352                         return;
353                 } // END - if
354
355                 // Sent out package data
356                 $sentBytes = $helperInstance->sendRawPackageData($packageData);
357
358                 // Remember unsent raw bytes in back-buffer, if any
359                 $this->storeUnsentBytesInBackBuffer($packageData, $sentBytes);
360         }
361
362         /**
363          * "Enqueues" raw content into this delivery class by reading the raw content
364          * from given template instance and pushing it on the 'undeclared' stack.
365          *
366          * @param       $helperInstance         An instance of a HelpableHub class
367          * @param       $nodeInstance           An instance of a NodeHelper class
368          * @return      void
369          */
370         public function enqueueRawDataFromTemplate (HelpableHub $helperInstance, NodeHelper $nodeInstance) {
371                 // Get the raw content ...
372                 $content = $helperInstance->getTemplateInstance()->getRawTemplateData();
373
374                 // ... and compress it
375                 $content = $this->getCompressorInstance()->compressStream($content);
376
377                 // Add magic in front of it and hash behind it, including BASE64 encoding
378                 $content = sprintf(self::PACKAGE_MASK,
379                         // 1.) Compressor's extension
380                         $this->getCompressorInstance()->getCompressorExtension(),
381                         // 2.) Raw package content, encoded with BASE64
382                         base64_encode($content),
383                         // 3.) Tags
384                         implode(self::PACKAGE_TAGS_SEPERATOR, $helperInstance->getPackageTags()),
385                         // 4.) Checksum
386                         $this->getHashFromContent($content, $helperInstance, $nodeInstance)
387                 );
388
389                 // Now prepare the temporary array and push it on the 'undeclared' stack
390                 $this->getStackerInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
391                         self::PACKAGE_DATA_SENDER    => $nodeInstance->getSessionId(),
392                         self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(),
393                         self::PACKAGE_DATA_CONTENT   => $content,
394                 ));
395         }
396
397         /**
398          * Checks wether a package has been enqueued for delivery.
399          *
400          * @return      $isEnqueued             Wether a package is enqueued
401          */
402         public function isPackageEnqueued () {
403                 // Check wether the stacker is not empty
404                 $isEnqueued = (($this->getStackerInstance()->isStackInitialized(self::STACKER_NAME_UNDECLARED)) && (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_UNDECLARED)));
405
406                 // Return the result
407                 return $isEnqueued;
408         }
409
410         /**
411          * Checks wether a package has been declared
412          *
413          * @return      $isDeclared             Wether a package is declared
414          */
415         public function isPackageDeclared () {
416                 // Check wether the stacker is not empty
417                 $isDeclared = (($this->getStackerInstance()->isStackInitialized(self::STACKER_NAME_DECLARED)) && (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECLARED)));
418
419                 // Return the result
420                 return $isDeclared;
421         }
422
423         /**
424          * Checks wether a package should be sent out
425          *
426          * @return      $isWaitingDelivery      Wether a package is waiting for delivery
427          */
428         public function isPackageWaitingForDelivery () {
429                 // Check wether the stacker is not empty
430                 $isWaitingDelivery = (($this->getStackerInstance()->isStackInitialized(self::STACKER_NAME_OUTGOING)) && (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_OUTGOING)));
431
432                 // Return the result
433                 return $isWaitingDelivery;
434         }
435
436         /**
437          * Delivers an enqueued package to the stated destination. If a non-session
438          * id is provided, recipient resolver is being asked (and instanced once).
439          * This allows that a single package is being delivered to multiple targets
440          * without enqueueing it for every target. If no target is provided or it
441          * can't be determined a NoTargetException is being thrown.
442          *
443          * @return      void
444          * @throws      NoTargetException       If no target can't be determined
445          */
446         public function declareEnqueuedPackage () {
447                 // Make sure this method isn't working if there is no package enqueued
448                 if (!$this->isPackageEnqueued()) {
449                         // This is not fatal but should be avoided
450                         // @TODO Add some logging here
451                         return;
452                 } // END - if
453
454                 // Now we know for sure there are packages to deliver, we can start
455                 // with the first one.
456                 $packageData = $this->getStackerInstance()->getNamed(self::STACKER_NAME_UNDECLARED);
457
458                 // Declare the raw package data for delivery
459                 $this->declareRawPackageData($packageData);
460
461                 // And remove it finally
462                 $this->getStackerInstance()->popNamed(self::STACKER_NAME_UNDECLARED);
463         }
464
465         /**
466          * Delivers the next declared package. Only one package per time will be sent
467          * because this may take time and slows down the whole delivery
468          * infrastructure.
469          *
470          * @return      void
471          */
472         public function deliverDeclaredPackage () {
473                 // Sanity check if we have packages declared
474                 if (!$this->isPackageDeclared()) {
475                         // This is not fatal but should be avoided
476                         // @TODO Add some logging here
477                         return;
478                 } // END - if
479
480                 // Get the package again
481                 $packageData = $this->getStackerInstance()->getNamed(self::STACKER_NAME_DECLARED);
482
483                 try {
484                         // And try to send it
485                         $this->deliverRawPackageData($packageData);
486
487                         // And remove it finally
488                         $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECLARED);
489                 } catch (InvalidStateException $e) {
490                         // The state is not excepected (shall be 'connected')
491                         $this->debugOutput('PACKAGE: Caught exception ' . $e->__toString() . ' with message=' . $e->getMessage());
492                 }
493         }
494
495         /**
496          * Sends waiting packages out for delivery
497          *
498          * @return      void
499          */
500         public function sendWaitingPackage () {
501                 // Send any waiting bytes in the back-buffer before sending a new package
502                 $this->sendBackBufferBytes();
503
504                 // Sanity check if we have packages waiting for delivery
505                 if (!$this->isPackageWaitingForDelivery()) {
506                         // This is not fatal but should be avoided
507                         $this->debugOutput('PACKAGE: No package is waiting for delivery, but ' . __METHOD__ . ' was called.');
508                         return;
509                 } // END - if
510
511                 // Get the package again
512                 $packageData = $this->getStackerInstance()->getNamed(self::STACKER_NAME_OUTGOING);
513
514                 try {
515                         // Now try to send it
516                         $this->sendOutgoingRawPackageData($packageData);
517
518                         // And remove it finally
519                         $this->getStackerInstance()->popNamed(self::STACKER_NAME_OUTGOING);
520                 } catch (InvalidSocketException $e) {
521                         // Output exception message
522                         $this->debugOutput('PACKAGE: Package was not delivered: ' . $e->getMessage());
523                 }
524         }
525
526         ///////////////////////////////////////////////////////////////////////////
527         //                   Receiving packages / raw data
528         ///////////////////////////////////////////////////////////////////////////
529
530         /**
531          * Checks wether decoded raw data is pending
532          *
533          * @return      $isPending      Wether decoded raw data is pending
534          */
535         private function isDecodedDataPending () {
536                 // Just return wether the stack is not empty
537                 $isPending = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_INCOMING));
538
539                 // Return the status
540                 return $isPending;
541         }
542
543         /**
544          * Checks wether new raw package data has arrived at a socket
545          *
546          * @param       $poolInstance   An instance of a PoolableListener class
547          * @return      $hasArrived             Wether new raw package data has arrived for processing
548          */
549         public function isNewRawDataPending (PoolableListener $poolInstance) {
550                 // Visit the pool. This monitors the pool for incoming raw data.
551                 $poolInstance->accept($this->getVisitorInstance());
552
553                 // Check for new data arrival
554                 $hasArrived = $this->isDecodedDataPending();
555
556                 // Return the status
557                 return $hasArrived;
558         }
559
560         /**
561          * Handles the incoming decoded raw data. This method does not "convert" the
562          * decoded data back into a package array, it just "handles" it and pushs it
563          * on the next stack.
564          *
565          * @return      void
566          */
567         public function handleIncomingDecodedData () {
568                 /*
569                  * This method should only be called if decoded raw data is pending,
570                  * so check it again.
571                  */
572                 if (!$this->isDecodedDataPending()) {
573                         // This is not fatal but should be avoided
574                         // @TODO Add some logging here
575                         return;
576                 } // END - if
577
578                 // Very noisy debug message:
579                 /* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Stacker size is ' . $this->getStackerInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.');
580
581                 // "Pop" the next entry (the same array again) from the stack
582                 $decodedData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECODED_INCOMING);
583
584                 // Make sure both array elements are there
585                 assert((is_array($decodedData)) && (isset($decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA])) && (isset($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE])));
586
587                 /*
588                  * Also make sure the error code is SOCKET_ERROR_UNHANDLED because we
589                  * only want to handle unhandled packages here.
590                  */
591                 assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED);
592
593                 // Remove the last chunk seperator (because it is being added and we don't need it)
594                 if (substr($decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPERATOR) {
595                         // It is there and should be removed
596                         $decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA] = substr($decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA], 0, -1);
597                 } // END - if
598
599                 // This package is "handled" and can be pushed on the next stack
600                 $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECODED_HANDLED, $decodedData);
601         }
602
603         /**
604          * Adds raw decoded data from the given handler instance to this receiver
605          *
606          * @param       $handlerInstance        An instance of a Networkable class
607          * @return      void
608          */
609         public function addDecodedDataToIncomingStack (Networkable $handlerInstance) {
610                 /*
611                  * Get the decoded data from the handler, this is an array with
612                  * 'decoded_data' and 'error_code' as elements.
613                  */
614                 $decodedData = $handlerInstance->getNextDecodedData();
615
616                 // Very noisy debug message:
617                 //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, true));
618
619                 // And push it on our stack
620                 $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECODED_INCOMING, $decodedData);
621         }
622
623         /**
624          * Checks wether incoming decoded data is handled.
625          *
626          * @return      $isHandled      Wether incoming decoded data is handled
627          */
628         public function isIncomingDecodedDataHandled () {
629                 // Determine if the stack is not empty
630                 $isHandled = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_HANDLED));
631
632                 // Return it
633                 return $isHandled;
634         }
635
636         /**
637          * Assembles incoming decoded data so it will become an abstract network
638          * package again.
639          *
640          * @return      void
641          */
642         public function assembleDecodedDataToPackage () {
643                 $this->partialStub('Please implement this method.');
644         }
645
646         /**
647          * Checks wether a new package has arrived
648          *
649          * @return      $hasArrived             Wether a new package has arrived for processing
650          */
651         public function isNewPackageArrived () {
652                 // @TODO Add some content here
653         }
654
655         /**
656          * Accepts the visitor to process the visit "request"
657          *
658          * @param       $visitorInstance        An instance of a Visitor class
659          * @return      void
660          */
661         public function accept (Visitor $visitorInstance) {
662                 // Debug message
663                 //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: ' . $visitorInstance->__toString() . ' has visited - START');
664
665                 // Visit the package
666                 $visitorInstance->visitNetworkPackage($this);
667
668                 // Debug message
669                 //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
670         }
671
672         /**
673          * Clears all stacker
674          *
675          * @return      void
676          */
677         public function clearAllStacker () {
678                 // Do the cleanup (no flushing)
679                 foreach (
680                         array(
681                                 self::STACKER_NAME_UNDECLARED,
682                                 self::STACKER_NAME_DECLARED,
683                                 self::STACKER_NAME_OUTGOING,
684                                 self::STACKER_NAME_DECODED_INCOMING,
685                                 self::STACKER_NAME_DECODED_HANDLED,
686                                 self::STACKER_NAME_BACK_BUFFER
687                         ) as $stackerName) {
688                                 // Clear this stacker by forcing an init
689                                 $this->getStackerInstance()->initStacker($stackerName, true);
690                 } // END - foreach
691
692                 // Debug message
693                 /* DEBUG: */ $this->debugOutput('PACKAGE: All stacker have been re-initialized.');
694         }
695 }
696
697 // [EOF]
698 ?>