]> git.mxchange.org Git - hub.git/blob - application/hub/main/cruncher/class_BaseHubCruncher.php
Generator/helper class for generating test units introduced:
[hub.git] / application / hub / main / cruncher / class_BaseHubCruncher.php
1 <?php
2 /**
3  * A general hub cruncher class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class BaseHubCruncher extends BaseHubSystem implements Updateable {
25         /**
26          * Version information
27          */
28         private $version = 'x.x';
29
30         /**
31          * By default no cruncher is active
32          */
33         private $isActive = false;
34
35         /**
36          * All buffer queue instances (a FIFO)
37          */
38         private $bufferInstance = null;
39
40         /**
41          * Protected constructor
42          *
43          * @param       $className      Name of the class
44          * @return      void
45          */
46         protected function __construct ($className) {
47                 // Call parent constructor
48                 parent::__construct($className);
49         }
50
51         /**
52          * Getter for version
53          *
54          * @return      $version        Version number of this cruncher
55          */
56         protected final function getVersion () {
57                 return $this->version;
58         }
59
60         /**
61          * Setter for version
62          *
63          * @param       $version        Version number of this cruncher
64          * @return      void
65          */
66         protected final function setVersion ($version) {
67                 $this->version = (string) $version;
68         }
69
70         /**
71          * Checks wether the in-buffer queue is filled by comparing it's current
72          * amount of entries against a threshold.
73          *
74          * @return      $isFilled       Wether the in-buffer is filled
75          */
76         protected function isInBufferQueueFilled () {
77                 // Determine it
78                 $isFilled = ($this->bufferInstance->getStackCount('in_queue') > $this->getConfigInstance()->getConfigEntry('cruncher_in_buffer_min_threshold'));
79
80                 // And return the result
81                 return $isFilled;
82         }
83
84         /**
85          * Enables/disables the cruncher (just sets a flag)
86          *
87          * @param       $version        Version number of this cruncher
88          * @return      void
89          */
90         public final function enableIsActive ($isActive = true) {
91                 $this->isActive = (bool) $isActive;
92         }
93
94         /**
95          * Determines wether the cruncher is active
96          *
97          * @return      $isActive       Wether the cruncher is active
98          */
99         public final function isActive () {
100                 return $this->isActive;
101         }
102
103         /**
104          * Initializes all buffer queues (mostly in/out). This method is demanded
105          * by the CruncherHelper interface.
106          *
107          * @return      void
108          */
109         public function initBufferQueues () {
110                 /*
111                  * Initialize both buffer queues, we can use the FIFO class here
112                  * directly and encapsulate its method calls with protected methods.
113                  */
114                 $this->bufferInstance = ObjectFactory::createObjectByConfiguredName('cruncher_buffer_stacker_class');
115
116                 // Initialize common stackers, like in/out
117                 $this->bufferInstance->initStacker('in_queue');
118                 $this->bufferInstance->initStacker('out_queue');
119
120                 // Output debug message
121                 $this->debugOutput('CRUNCHER: All buffers are now initialized.');
122         }
123
124         /**
125          * This method determines if the in-buffer is going to depleted and if so,
126          * it fetches more WUs from the network. If no WU can be fetched from the
127          * network and if enabled, a random test WU is being generated.
128          *
129          * This method is demanded from the CruncherHelper interface.
130          *
131          * @return      void
132          */
133         public function doFetchWorkUnits () {
134                 // Simply check if we have enough WUs left in the in-buffer queue (a FIFO)
135                 if (!$this->isInBufferQueueFilled()) {
136                         // The in-buffer queue needs filling, so head out and get some work
137                         $this->fillInBufferQueueWithWorkUnits();
138
139                         // Is the buffer still not filled and are test-packages allowed?
140                         if ((!$this->isInBufferQueueFilled()) && ($this->getConfigInstance()->getConfigEntry('cruncher_test_units_enabled') == 'Y')) {
141                                 // Then fill the in-buffer with (one) test-unit(s)
142                                 $this->fillInBufferQueueWithTestUnits();
143                         } // END - if
144                 } // END - if
145         }
146
147         /**
148          * Updates a given field with new value
149          *
150          * @param       $fieldName              Field to update
151          * @param       $fieldValue             New value to store
152          * @return      void
153          * @throws      DatabaseUpdateSupportException  If this class does not support database updates
154          * @todo        Try to make this method more generic so we can move it in BaseFrameworkSystem
155          */
156         public function updateDatabaseField ($fieldName, $fieldValue) {
157                 // Unfinished
158                 $this->partialStub('Unfinished!');
159                 return;
160         }
161 }
162
163 // [EOF]
164 ?>