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 - 2014 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 {
29 * @TODO Add more protocols to use
31 private static $connectionStatistics = array(
32 // Statistics for TCP connections
34 // Tried TCP connection attempts
35 'retry_count' => array(),
37 // Statistics for UDP connections
39 // Tried UDP connection attempts
40 'retry_count' => array(),
45 * Protected constructor
49 protected function __construct () {
50 parent::__construct(__CLASS__);
54 * Checks whether the retry count has reached a configured limit for given
57 * @param $helperInstance An instance of a ConnectionHelper class
58 * @return $isExhausted Whether the retry count has been reached
60 public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) {
61 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - CALLED!');
62 // Construct config entry
63 $configEntry = $helperInstance->getProtocolName() . '_connect_retry_max';
68 isset(self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'])
70 self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'] >= $helperInstance->getConfigInstance()->getConfigEntry($configEntry)
75 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!');
80 * Increaes connect-retry count for given connection
82 * @param $helperInstance An instance of a ConnectionHelper class
85 public static function increaseConnectRetry (ConnectionHelper $helperInstance) {
86 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - CALLED!');
87 // Is the counter there
88 if (!isset(self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'])) {
90 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - FIRST!');
91 self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'] = 1;
94 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!');
95 self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count']++;
98 // Create/update 'last_update' for purging
99 // @TODO last_update is not being used at the moment
100 self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['last_update'] = time();