3 * A helper class for maintaining connection statistics, no instance is
4 * required to use this class.
6 * @author Roland Haeder <webmaster@shipsimu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.shipsimu.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 TCP connection attempts
34 'retry_count' => array(),
36 // Statistics for UDP connections
38 // Tried UDP connection attempts
39 'retry_count' => array(),
44 * Protected constructor
48 protected function __construct () {
49 parent::__construct(__CLASS__);
53 * Checks whether the retry count has reached a configured limit for given
56 * @param $helperInstance An instance of a ConnectionHelper class
57 * @return $isExhausted Whether the retry count has been reached
59 public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) {
60 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
61 // Construct config entry
62 $configEntry = $helperInstance->getProtocol() . '_connect_retry_max';
67 isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])
69 self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] >= $helperInstance->getConfigInstance()->getConfigEntry($configEntry)
74 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!');
79 * Increaes connect-retry count for given connection
81 * @param $helperInstance An instance of a ConnectionHelper class
84 public static function increaseConnectRetry (ConnectionHelper $helperInstance) {
85 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
86 // Is the counter there
87 if (!isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])) {
89 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - FIRST!');
90 self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] = 1;
93 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!');
94 self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count']++;
97 // Create/update 'last_update' for purging
98 // @TODO last_update is not being used at the moment
99 self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['last_update'] = time();