3 * A helper class for maintaining connection statistics, no instance is
4 * required to use this class.
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
11 * @todo Find an interface for hub helper
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 class ConnectionStatisticsHelper extends BaseHubSystem {
30 private static $connectionStatistics = array(
31 // Statistics for TCP connections
33 // Tried connection attempts
34 'retry_count' => array(),
36 // Statistics for UDP connections
38 'retry_count' => array(),
43 * Protected constructor
47 protected function __construct () {
48 parent::__construct(__CLASS__);
52 * Checks wether the retry count has reached a configured limit for given
55 * @param $helperInstance An instance of a ConnectionHelper class
56 * @return $isExhausted Wether the retry count has been reached
58 public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) {
59 //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
60 // Construct config entry
61 $configEntry = $helperInstance->getProtocol() . '_connect_retry_max';
66 isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])
68 self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] >= $helperInstance->getConfigInstance()->getConfigEntry($configEntry)
73 //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!');
78 * Increaes connect-retry count for given connection
80 * @param $helperInstance An instance of a ConnectionHelper class
83 public static function increaseConnectRetry (ConnectionHelper $helperInstance) {
84 //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
85 // Is the counter there
86 if (!isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])) {
88 //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - FIRST!');
89 self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] = 1;
92 //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!');
93 self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count']++;
96 // Create/update 'last_update' for later purging
97 self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['last_update'] = time();