transport cleanups: final, init, pkg private

This commit is contained in:
zzz
2011-01-19 17:18:39 +00:00
parent 8da1e90226
commit 653abbcc7e
8 changed files with 32 additions and 37 deletions

View File

@@ -36,15 +36,14 @@ import net.i2p.util.SimpleTimer;
import net.i2p.util.Translate;
public class CommSystemFacadeImpl extends CommSystemFacade {
private Log _log;
private RouterContext _context;
private final Log _log;
private final RouterContext _context;
private TransportManager _manager;
private GeoIP _geoIP;
public CommSystemFacadeImpl(RouterContext context) {
_context = context;
_log = _context.logManager().getLog(CommSystemFacadeImpl.class);
_manager = null;
_context.statManager().createRateStat("transport.getBidsJobTime", "How long does it take?", "Transport", new long[] { 10*60*1000l });
startGeoIP();
}

View File

@@ -31,18 +31,18 @@ import net.i2p.util.Log;
*
*/
public class FIFOBandwidthLimiter {
private Log _log;
private I2PAppContext _context;
private final Log _log;
private final I2PAppContext _context;
private final List<Request> _pendingInboundRequests;
private final List<Request> _pendingOutboundRequests;
/** how many bytes we can consume for inbound transmission immediately */
private AtomicInteger _availableInbound = new AtomicInteger();
private final AtomicInteger _availableInbound = new AtomicInteger();
/** how many bytes we can consume for outbound transmission immediately */
private AtomicInteger _availableOutbound = new AtomicInteger();
private final AtomicInteger _availableOutbound = new AtomicInteger();
/** how many bytes we can queue up for bursting */
private AtomicInteger _unavailableInboundBurst = new AtomicInteger();
private final AtomicInteger _unavailableInboundBurst = new AtomicInteger();
/** how many bytes we can queue up for bursting */
private AtomicInteger _unavailableOutboundBurst = new AtomicInteger();
private final AtomicInteger _unavailableOutboundBurst = new AtomicInteger();
/** how large _unavailableInbound can get */
private int _maxInboundBurst;
/** how large _unavailableInbound can get */
@@ -56,14 +56,14 @@ public class FIFOBandwidthLimiter {
/** shortcut of whether our inbound rate is unlimited */
private boolean _inboundUnlimited;
/** lifetime counter of bytes received */
private AtomicLong _totalAllocatedInboundBytes = new AtomicLong();
private final AtomicLong _totalAllocatedInboundBytes = new AtomicLong();
/** lifetime counter of bytes sent */
private AtomicLong _totalAllocatedOutboundBytes = new AtomicLong();
private final AtomicLong _totalAllocatedOutboundBytes = new AtomicLong();
/** lifetime counter of tokens available for use but exceeded our maxInboundBurst size */
private AtomicLong _totalWastedInboundBytes = new AtomicLong();
private final AtomicLong _totalWastedInboundBytes = new AtomicLong();
/** lifetime counter of tokens available for use but exceeded our maxOutboundBurst size */
private AtomicLong _totalWastedOutboundBytes = new AtomicLong();
private FIFOBandwidthRefiller _refiller;
private final AtomicLong _totalWastedOutboundBytes = new AtomicLong();
private final FIFOBandwidthRefiller _refiller;
private long _lastTotalSent;
private long _lastTotalReceived;
@@ -73,8 +73,6 @@ public class FIFOBandwidthLimiter {
private float _sendBps15s;
private float _recvBps15s;
private static int __id = 0;
public /* static */ long now() {
// dont use the clock().now(), since that may jump
return System.currentTimeMillis();
@@ -98,13 +96,9 @@ public class FIFOBandwidthLimiter {
_pendingOutboundRequests = new ArrayList(16);
_lastTotalSent = _totalAllocatedOutboundBytes.get();
_lastTotalReceived = _totalAllocatedInboundBytes.get();
_sendBps = 0;
_recvBps = 0;
_lastStatsUpdated = now();
_refiller = new FIFOBandwidthRefiller(_context, this);
I2PThread t = new I2PThread(_refiller);
t.setName("BWRefiller" + (++__id));
t.setDaemon(true);
I2PThread t = new I2PThread(_refiller, "BWRefiller", true);
t.setPriority(I2PThread.NORM_PRIORITY-1);
t.start();
}
@@ -753,7 +747,7 @@ public class FIFOBandwidthLimiter {
private int _allocationsSinceWait;
private boolean _aborted;
private boolean _waited;
List<Request> satisfiedBuffer;
final List<Request> satisfiedBuffer;
private CompleteListener _lsnr;
private Object _attachment;

View File

@@ -7,9 +7,9 @@ import net.i2p.I2PAppContext;
import net.i2p.util.Log;
public class FIFOBandwidthRefiller implements Runnable {
private Log _log;
private I2PAppContext _context;
private FIFOBandwidthLimiter _limiter;
private final Log _log;
private final I2PAppContext _context;
private final FIFOBandwidthLimiter _limiter;
/** how many KBps do we want to allow? */
private int _inboundKBytesPerSecond;
/** how many KBps do we want to allow? */

View File

@@ -35,7 +35,7 @@ import net.i2p.util.Log;
*
* @author zzz
*/
public class GeoIP {
class GeoIP {
private Log _log;
private RouterContext _context;
private final Map<String, String> _codeToName;

View File

@@ -21,10 +21,10 @@ import net.i2p.util.Log;
* pass it on to the transport for processing
*
*/
public class GetBidsJob extends JobImpl {
private Log _log;
private CommSystemFacadeImpl _facade;
private OutNetMessage _msg;
class GetBidsJob extends JobImpl {
private final Log _log;
private final CommSystemFacadeImpl _facade;
private final OutNetMessage _msg;
public GetBidsJob(RouterContext ctx, CommSystemFacadeImpl facade, OutNetMessage msg) {
super(ctx);

View File

@@ -37,14 +37,14 @@ import net.i2p.util.Log;
import net.i2p.util.Translate;
public class TransportManager implements TransportEventListener {
private Log _log;
private final Log _log;
/**
* Converted from List to prevent concurrent modification exceptions.
* If we want more than one transport with the same style we will have to change this.
*/
private Map<String, Transport> _transports;
private RouterContext _context;
private UPnPManager _upnpManager;
private final Map<String, Transport> _transports;
private final RouterContext _context;
private final UPnPManager _upnpManager;
/** default true */
public final static String PROP_ENABLE_UDP = "i2np.udp.enable";
@@ -63,8 +63,10 @@ public class TransportManager implements TransportEventListener {
_context.statManager().createRateStat("transport.bidFailNoTransports", "Could not attempt to bid on message, as none of the transports could attempt it", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("transport.bidFailAllTransports", "Could not attempt to bid on message, as all of the transports had failed", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
_transports = new ConcurrentHashMap(2);
if (Boolean.valueOf(_context.getProperty(PROP_ENABLE_UPNP, "true")).booleanValue())
if (_context.getBooleanPropertyDefaultTrue(PROP_ENABLE_UPNP))
_upnpManager = new UPnPManager(context, this);
else
_upnpManager = null;
}
public void addTransport(Transport transport) {

View File

@@ -52,7 +52,7 @@ import org.freenetproject.ForwardPortStatus;
* TODO: Advertise the node like the MDNS plugin does
* TODO: Implement EventListener and react on ip-change
*/
public class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
private Log _log;
private I2PAppContext _context;

View File

@@ -24,7 +24,7 @@ import org.freenetproject.ForwardPortStatus;
*
* @author zzz
*/
public class UPnPManager {
class UPnPManager {
private Log _log;
private RouterContext _context;
private UPnP _upnp;