Changeset bc54908


Ignore:
Timestamp:
Jan 10, 2009 10:34:07 PM (12 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e3abea1a
Parents:
60bd980
Message:

cleanups using getProperty(String, int)

Location:
router/java/src/net/i2p/router
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/LoadTestManager.java

    r60bd980 rbc54908  
    118118        if (!isEnabled(_context)) return 0;
    119119       
    120         int rv = CONCURRENT_PEERS;
    121         try {
    122             rv = Integer.parseInt(_context.getProperty("router.loadTestConcurrency", CONCURRENT_PEERS+""));
    123         } catch (NumberFormatException nfe) {
    124             rv = CONCURRENT_PEERS;
    125         }
     120        int rv = _context.getProperty("router.loadTestConcurrency", CONCURRENT_PEERS);
    126121        if (rv < 0)
    127122            rv = 0;
     
    132127   
    133128    private int getPeerMessages() {
    134         String msgsPerPeer = _context.getProperty("router.loadTestMessagesPerPeer");
    135         int rv = CONCURRENT_MESSAGES;
    136         if (msgsPerPeer != null) {
    137             try {
    138                 rv = Integer.parseInt(msgsPerPeer);
    139             } catch (NumberFormatException nfe) {
    140                 rv = CONCURRENT_MESSAGES;
    141             }
    142         }
     129        int rv = _context.getProperty("router.loadTestMessagesPerPeer", CONCURRENT_MESSAGES);
    143130        if (rv < 1)
    144131            rv = 1;
  • router/java/src/net/i2p/router/RouterThrottleImpl.java

    r60bd980 rbc54908  
    191191        }
    192192       
    193         int max = DEFAULT_MAX_TUNNELS;
    194         String maxTunnels = _context.getProperty(PROP_MAX_TUNNELS);
    195         if (maxTunnels != null) {
    196             try {
    197                 max = Integer.parseInt(maxTunnels);
    198             } catch (NumberFormatException nfe) {
    199             }
    200         }
     193        int max = _context.getProperty(PROP_MAX_TUNNELS, DEFAULT_MAX_TUNNELS);
    201194        if (numTunnels >= max) {
    202195            if (_log.shouldLog(Log.WARN))
     
    388381    /** dont ever probabalistically throttle tunnels if we have less than this many */
    389382    private int getMinThrottleTunnels() {
    390         try {
    391             return Integer.parseInt(_context.getProperty("router.minThrottleTunnels", "1000"));
    392         } catch (NumberFormatException nfe) {
    393             return 1000;
    394         }
     383        return _context.getProperty("router.minThrottleTunnels", 1000);
    395384    }
    396385   
  • router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java

    r60bd980 rbc54908  
    11021102     */
    11031103    protected int getMinimumFastPeers() {
    1104         String val = _context.getProperty(PROP_MINIMUM_FAST_PEERS, ""+DEFAULT_MINIMUM_FAST_PEERS);
    1105         if (val != null) {
    1106             try {
    1107                 int rv = Integer.parseInt(val);
    1108                 if (_log.shouldLog(Log.DEBUG))
    1109                     _log.debug("router context said " + PROP_MINIMUM_FAST_PEERS + '=' + val);
    1110                 return rv;
    1111             } catch (NumberFormatException nfe) {
    1112                 if (_log.shouldLog(Log.WARN))
    1113                     _log.warn("Minimum fast peers improperly set in the router environment [" + val + "]", nfe);
    1114             }
    1115         }
    1116        
    1117         if (_log.shouldLog(Log.DEBUG))
    1118             _log.debug("no config for " + PROP_MINIMUM_FAST_PEERS + ", using " + DEFAULT_MINIMUM_FAST_PEERS);
    1119         return DEFAULT_MINIMUM_FAST_PEERS;
     1104        return _context.getProperty(PROP_MINIMUM_FAST_PEERS, DEFAULT_MINIMUM_FAST_PEERS);
    11201105    }
    11211106   
     
    11311116     */
    11321117    protected int getMinimumHighCapacityPeers() {
    1133         String val = _context.getProperty(PROP_MINIMUM_HIGH_CAPACITY_PEERS, ""+DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS);
    1134         if (val != null) {
    1135             try {
    1136                 int rv = Integer.parseInt(val);
    1137                 if (_log.shouldLog(Log.DEBUG))
    1138                     _log.debug("router context said " + PROP_MINIMUM_HIGH_CAPACITY_PEERS + '=' + val);
    1139                 return rv;
    1140             } catch (NumberFormatException nfe) {
    1141                 if (_log.shouldLog(Log.WARN))
    1142                     _log.warn("Minimum high capacity peers improperly set in the router environment [" + val + "]", nfe);
    1143             }
    1144         }
    1145        
    1146         if (_log.shouldLog(Log.DEBUG))
    1147             _log.debug("no config for " + PROP_MINIMUM_HIGH_CAPACITY_PEERS + ", using " + DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS);
    1148         return DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS;
     1118        return _context.getProperty(PROP_MINIMUM_HIGH_CAPACITY_PEERS, DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS);
    11491119    }
    11501120   
  • router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java

    r60bd980 rbc54908  
    155155   
    156156    private void updateInboundRate() {
    157         String inBwStr = _context.getProperty(PROP_INBOUND_BANDWIDTH);
    158         if ( (inBwStr != null) &&
    159              (inBwStr.trim().length() > 0) &&
    160              (!(inBwStr.equals(String.valueOf(_inboundKBytesPerSecond)))) ) {
    161             // bandwidth was specified *and* changed
    162             try {
    163                 int in = Integer.parseInt(inBwStr);
     157        int in = _context.getProperty(PROP_INBOUND_BANDWIDTH, DEFAULT_INBOUND_BANDWIDTH);
     158        if (in != _inboundKBytesPerSecond) {
     159            // bandwidth was specified *and* changed
    164160                if ( (in <= 0) || (in > MIN_INBOUND_BANDWIDTH) )
    165161                    _inboundKBytesPerSecond = in;
     
    168164                if (_log.shouldLog(Log.DEBUG))
    169165                    _log.debug("Updating inbound rate to " + _inboundKBytesPerSecond);
    170             } catch (NumberFormatException nfe) {
    171                 if (_log.shouldLog(Log.WARN))
    172                     _log.warn("Invalid inbound bandwidth limit [" + inBwStr
    173                               + "], keeping as " + _inboundKBytesPerSecond);
    174             }
    175         } else {
    176             if ( (inBwStr == null) && (_log.shouldLog(Log.DEBUG)) )
    177                 _log.debug("Inbound bandwidth limits not specified in the config via " + PROP_INBOUND_BANDWIDTH);
    178166        }
    179167       
     
    182170    }
    183171    private void updateOutboundRate() {
    184         String outBwStr = _context.getProperty(PROP_OUTBOUND_BANDWIDTH);
    185        
    186         if ( (outBwStr != null) &&
    187              (outBwStr.trim().length() > 0) &&
    188              (!(outBwStr.equals(String.valueOf(_outboundKBytesPerSecond)))) ) {
    189             // bandwidth was specified *and* changed
    190             try {
    191                 int out = Integer.parseInt(outBwStr);
     172        int out = _context.getProperty(PROP_OUTBOUND_BANDWIDTH, DEFAULT_OUTBOUND_BANDWIDTH);
     173        if (out != _outboundKBytesPerSecond) {
     174            // bandwidth was specified *and* changed
    192175                if ( (out <= 0) || (out >= MIN_OUTBOUND_BANDWIDTH) )
    193176                    _outboundKBytesPerSecond = out;
     
    196179                if (_log.shouldLog(Log.DEBUG))
    197180                    _log.debug("Updating outbound rate to " + _outboundKBytesPerSecond);
    198             } catch (NumberFormatException nfe) {
    199                 if (_log.shouldLog(Log.WARN))
    200                     _log.warn("Invalid outbound bandwidth limit [" + outBwStr
    201                               + "], keeping as " + _outboundKBytesPerSecond);
    202             }
    203         } else {
    204             if ( (outBwStr == null) && (_log.shouldLog(Log.DEBUG)) )
    205                 _log.debug("Outbound bandwidth limits not specified in the config via " + PROP_OUTBOUND_BANDWIDTH);
    206181        }
    207182       
     
    211186   
    212187    private void updateInboundBurstRate() {
    213         String inBwStr = _context.getProperty(PROP_INBOUND_BURST_BANDWIDTH);
    214         if ( (inBwStr != null) &&
    215              (inBwStr.trim().length() > 0) &&
    216              (!(inBwStr.equals(String.valueOf(_inboundBurstKBytesPerSecond)))) ) {
    217             // bandwidth was specified *and* changed
    218             try {
    219                 int in = Integer.parseInt(inBwStr);
     188        int in = _context.getProperty(PROP_INBOUND_BURST_BANDWIDTH, DEFAULT_INBOUND_BURST_BANDWIDTH);
     189        if (in != _inboundBurstKBytesPerSecond) {
     190            // bandwidth was specified *and* changed
    220191                if ( (in <= 0) || (in >= _inboundKBytesPerSecond) )
    221192                    _inboundBurstKBytesPerSecond = in;
     
    224195                if (_log.shouldLog(Log.DEBUG))
    225196                    _log.debug("Updating inbound burst rate to " + _inboundBurstKBytesPerSecond);
    226             } catch (NumberFormatException nfe) {
    227                 if (_log.shouldLog(Log.WARN))
    228                     _log.warn("Invalid inbound bandwidth burst limit [" + inBwStr
    229                               + "], keeping as " + _inboundBurstKBytesPerSecond);
    230             }
    231         } else {
    232             if ( (inBwStr == null) && (_log.shouldLog(Log.DEBUG)) )
    233                 _log.debug("Inbound bandwidth burst limits not specified in the config via " + PROP_INBOUND_BURST_BANDWIDTH);
    234197        }
    235198       
     
    240203   
    241204    private void updateOutboundBurstRate() {
    242         String outBwStr = _context.getProperty(PROP_OUTBOUND_BURST_BANDWIDTH);
    243        
    244         if ( (outBwStr != null) &&
    245              (outBwStr.trim().length() > 0) &&
    246              (!(outBwStr.equals(String.valueOf(_outboundBurstKBytesPerSecond)))) ) {
    247             // bandwidth was specified *and* changed
    248             try {
    249                 int out = Integer.parseInt(outBwStr);
     205        int out = _context.getProperty(PROP_OUTBOUND_BURST_BANDWIDTH, DEFAULT_OUTBOUND_BURST_BANDWIDTH);
     206        if (out != _outboundBurstKBytesPerSecond) {
     207            // bandwidth was specified *and* changed
    250208                if ( (out <= 0) || (out >= _outboundKBytesPerSecond) )
    251209                    _outboundBurstKBytesPerSecond = out;
     
    254212                if (_log.shouldLog(Log.DEBUG))
    255213                    _log.debug("Updating outbound burst rate to " + _outboundBurstKBytesPerSecond);
    256             } catch (NumberFormatException nfe) {
    257                 if (_log.shouldLog(Log.WARN))
    258                     _log.warn("Invalid outbound bandwidth burst limit [" + outBwStr
    259                               + "], keeping as " + _outboundBurstKBytesPerSecond);
    260             }
    261         } else {
    262             if ( (outBwStr == null) && (_log.shouldLog(Log.DEBUG)) )
    263                 _log.debug("Outbound bandwidth burst limits not specified in the config via " + PROP_OUTBOUND_BURST_BANDWIDTH);
    264214        }
    265215       
     
    270220   
    271221    private void updateInboundPeak() {
    272         String inBwStr = _context.getProperty(PROP_INBOUND_BANDWIDTH_PEAK);
    273         if ( (inBwStr != null) &&
    274              (inBwStr.trim().length() > 0) &&
    275              (!(inBwStr.equals(String.valueOf(_limiter.getInboundBurstBytes())))) ) {
     222        int in = _context.getProperty(PROP_INBOUND_BANDWIDTH_PEAK,
     223                                      DEFAULT_BURST_SECONDS * _inboundBurstKBytesPerSecond);
     224        if (in != _limiter.getInboundBurstBytes()) {
    276225            // peak bw was specified *and* changed
    277             try {
    278                 int in = Integer.parseInt(inBwStr);
    279226                if (in >= MIN_INBOUND_BANDWIDTH_PEAK) {
    280227                    if (in < _inboundBurstKBytesPerSecond)
     
    288235                        _limiter.setInboundBurstBytes(MIN_INBOUND_BANDWIDTH_PEAK * 1024);
    289236                }
    290             } catch (NumberFormatException nfe) {
    291                 if (_log.shouldLog(Log.WARN))
    292                     _log.warn("Invalid inbound bandwidth burst limit [" + inBwStr
    293                               + "]");
    294                 _limiter.setInboundBurstBytes(DEFAULT_BURST_SECONDS * _inboundBurstKBytesPerSecond * 1024);
    295             }
    296         } else {
    297             if (_log.shouldLog(Log.DEBUG))
    298                 _log.debug("Inbound bandwidth burst limits not specified in the config via "
    299                            + PROP_INBOUND_BANDWIDTH_PEAK);
    300             _limiter.setInboundBurstBytes(DEFAULT_BURST_SECONDS * _inboundBurstKBytesPerSecond * 1024);
    301237        }
    302238    }
    303239    private void updateOutboundPeak() {
    304         String inBwStr = _context.getProperty(PROP_OUTBOUND_BANDWIDTH_PEAK);
    305         if ( (inBwStr != null) &&
    306              (inBwStr.trim().length() > 0) &&
    307              (!(inBwStr.equals(String.valueOf(_limiter.getOutboundBurstBytes())))) ) {
     240        int in = _context.getProperty(PROP_OUTBOUND_BANDWIDTH_PEAK,
     241                                      DEFAULT_BURST_SECONDS * _outboundBurstKBytesPerSecond);
     242        if (in != _limiter.getOutboundBurstBytes()) {
    308243            // peak bw was specified *and* changed
    309             try {
    310                 int in = Integer.parseInt(inBwStr);
    311244                if (in >= MIN_OUTBOUND_BANDWIDTH_PEAK) {
    312245                    if (in < _outboundBurstKBytesPerSecond)
     
    320253                        _limiter.setOutboundBurstBytes(MIN_OUTBOUND_BANDWIDTH_PEAK * 1024);
    321254                }
    322             } catch (NumberFormatException nfe) {
    323                 if (_log.shouldLog(Log.WARN))
    324                     _log.warn("Invalid outbound bandwidth burst limit [" + inBwStr
    325                               + "]");
    326                 _limiter.setOutboundBurstBytes(DEFAULT_BURST_SECONDS * _outboundBurstKBytesPerSecond * 1024);
    327             }
    328         } else {
    329             if (_log.shouldLog(Log.DEBUG))
    330                 _log.debug("Outbound bandwidth burst limits not specified in the config via "
    331                            + PROP_OUTBOUND_BANDWIDTH_PEAK);
    332             _limiter.setOutboundBurstBytes(DEFAULT_BURST_SECONDS * _outboundBurstKBytesPerSecond * 1024);
    333255        }
    334256    }
  • router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java

    r60bd980 rbc54908  
    4040        _context.statManager().createRateStat("tunnel.buildExploratoryExpire", "How often an exploratory tunnel times out during creation", "Tunnels", new long[] { 60*1000, 10*60*1000 });
    4141        _context.statManager().createRateStat("tunnel.buildClientExpire", "How often a client tunnel times out during creation", "Tunnels", new long[] { 60*1000, 10*60*1000 });
    42         _context.statManager().createRateStat("tunnel.buildExploratorySuccess", "How often an exploratory tunnel is fully built", "Tunnels", new long[] { 60*1000, 10*60*1000 });
    43         _context.statManager().createRateStat("tunnel.buildClientSuccess", "How often a client tunnel is fully built", "Tunnels", new long[] { 60*1000, 10*60*1000 });
    44         _context.statManager().createRateStat("tunnel.buildExploratoryReject", "How often an exploratory tunnel is rejected", "Tunnels", new long[] { 60*1000, 10*60*1000 });
    45         _context.statManager().createRateStat("tunnel.buildClientReject", "How often a client tunnel is rejected", "Tunnels", new long[] { 60*1000, 10*60*1000 });
     42        _context.statManager().createRateStat("tunnel.buildExploratorySuccess", "Response time for success", "Tunnels", new long[] { 60*1000, 10*60*1000 });
     43        _context.statManager().createRateStat("tunnel.buildClientSuccess", "Response time for success", "Tunnels", new long[] { 60*1000, 10*60*1000 });
     44        _context.statManager().createRateStat("tunnel.buildExploratoryReject", "Response time for rejection", "Tunnels", new long[] { 60*1000, 10*60*1000 });
     45        _context.statManager().createRateStat("tunnel.buildClientReject", "Response time for rejection", "Tunnels", new long[] { 60*1000, 10*60*1000 });
    4646        _context.statManager().createRateStat("tunnel.buildRequestTime", "How long it takes to build a tunnel request", "Tunnels", new long[] { 60*1000, 10*60*1000 });
    4747        _context.statManager().createRateStat("tunnel.buildRequestZeroHopTime", "How long it takes to build a zero hop tunnel", "Tunnels", new long[] { 60*1000, 10*60*1000 });
     
    7272        if (allowed < 2) allowed = 2; // Never choke below 2 builds (but congestion may)
    7373        if (allowed > 10) allowed = 10; // Never go beyond 10, that is uncharted territory (old limit was 5)
    74 
    75         String prop = _context.getProperty("router.tunnelConcurrentBuilds");
    76         if (prop != null)
    77             try { allowed = Integer.valueOf(prop).intValue(); } catch (NumberFormatException nfe) {}
     74        allowed = _context.getProperty("router.tunnelConcurrentBuilds", allowed);
    7875
    7976        List expired = null;
Note: See TracChangeset for help on using the changeset viewer.