forked from I2P_Developers/i2p.i2p
* Shutdown:
- Implement and call shutdown for BandwidthRefiller - Implement and register shutdown hook for Timestamper - Implement and register shutdown hook for Jetty console server - Fix UPnP-SSDPNotifySocket thread not stopping - Fix all but one UDP PacketHandler threads not stopping
This commit is contained in:
@ -967,6 +967,7 @@ public class Router {
|
||||
try { _context.tunnelDispatcher().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the tunnel dispatcher", t); }
|
||||
try { _context.netDb().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the networkDb", t); }
|
||||
try { _context.commSystem().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the comm system", t); }
|
||||
try { _context.bandwidthLimiter().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the comm system", t); }
|
||||
try { _context.peerManager().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the peer manager", t); }
|
||||
try { _context.messageRegistry().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the message registry", t); }
|
||||
try { _context.messageValidator().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the message validator", t); }
|
||||
|
@ -64,6 +64,7 @@ public class FIFOBandwidthLimiter {
|
||||
/** lifetime counter of tokens available for use but exceeded our maxOutboundBurst size */
|
||||
private final AtomicLong _totalWastedOutboundBytes = new AtomicLong();
|
||||
private final FIFOBandwidthRefiller _refiller;
|
||||
private final Thread _refillerThread;
|
||||
|
||||
private long _lastTotalSent;
|
||||
private long _lastTotalReceived;
|
||||
@ -91,9 +92,9 @@ public class FIFOBandwidthLimiter {
|
||||
_lastTotalReceived = _totalAllocatedInboundBytes.get();
|
||||
_lastStatsUpdated = now();
|
||||
_refiller = new FIFOBandwidthRefiller(_context, this);
|
||||
I2PThread t = new I2PThread(_refiller, "BWRefiller", true);
|
||||
t.setPriority(I2PThread.NORM_PRIORITY-1);
|
||||
t.start();
|
||||
_refillerThread = new I2PThread(_refiller, "BWRefiller", true);
|
||||
_refillerThread.setPriority(I2PThread.NORM_PRIORITY-1);
|
||||
_refillerThread.start();
|
||||
}
|
||||
|
||||
//public long getAvailableInboundBytes() { return _availableInboundBytes; }
|
||||
@ -122,6 +123,19 @@ public class FIFOBandwidthLimiter {
|
||||
public int getInboundBurstKBytesPerSecond() { return _refiller.getInboundBurstKBytesPerSecond(); }
|
||||
|
||||
public void reinitialize() {
|
||||
clear();
|
||||
_refiller.reinitialize();
|
||||
}
|
||||
|
||||
/** @since 0.8.8 */
|
||||
public void shutdown() {
|
||||
_refiller.shutdown();
|
||||
_refillerThread.interrupt();
|
||||
clear();
|
||||
}
|
||||
|
||||
/** @since 0.8.8 */
|
||||
private void clear() {
|
||||
_pendingInboundRequests.clear();
|
||||
_pendingOutboundRequests.clear();
|
||||
_availableInbound.set(0);
|
||||
@ -134,7 +148,6 @@ public class FIFOBandwidthLimiter {
|
||||
_unavailableOutboundBurst.set(0);
|
||||
_inboundUnlimited = false;
|
||||
_outboundUnlimited = false;
|
||||
_refiller.reinitialize();
|
||||
}
|
||||
|
||||
public Request createRequest() { return new SimpleRequest(); }
|
||||
|
@ -24,6 +24,7 @@ public class FIFOBandwidthRefiller implements Runnable {
|
||||
private long _lastCheckConfigTime;
|
||||
/** how frequently do we check the config for updates? */
|
||||
private long _configCheckPeriodMs = 60*1000;
|
||||
private volatile boolean _isRunning;
|
||||
|
||||
public static final String PROP_INBOUND_BANDWIDTH = "i2np.bandwidth.inboundKBytesPerSecond";
|
||||
public static final String PROP_OUTBOUND_BANDWIDTH = "i2np.bandwidth.outboundKBytesPerSecond";
|
||||
@ -67,12 +68,19 @@ public class FIFOBandwidthRefiller implements Runnable {
|
||||
_context = context;
|
||||
_log = context.logManager().getLog(FIFOBandwidthRefiller.class);
|
||||
reinitialize();
|
||||
_isRunning = true;
|
||||
}
|
||||
|
||||
/** @since 0.8.8 */
|
||||
public void shutdown() {
|
||||
_isRunning = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// bootstrap 'em with nothing
|
||||
_lastRefillTime = _limiter.now();
|
||||
List<FIFOBandwidthLimiter.Request> buffer = new ArrayList(2);
|
||||
while (true) {
|
||||
while (_isRunning) {
|
||||
long now = _limiter.now();
|
||||
if (now >= _lastCheckConfigTime + _configCheckPeriodMs) {
|
||||
checkConfig();
|
||||
|
@ -113,6 +113,11 @@ class PacketHandler {
|
||||
return rv.toString();
|
||||
}
|
||||
|
||||
/** @since 0.8.8 */
|
||||
int getHandlerCount() {
|
||||
return _handlers.length;
|
||||
}
|
||||
|
||||
/** the packet is from a peer we are establishing an outbound con to, but failed validation, so fallback */
|
||||
private static final short OUTBOUND_FALLBACK = 1;
|
||||
/** the packet is from a peer we are establishing an inbound con to, but failed validation, so fallback */
|
||||
|
@ -147,6 +147,7 @@ class UDPEndpoint {
|
||||
|
||||
/**
|
||||
* Blocking call to receive the next inbound UDP packet from any peer.
|
||||
* @return null if we have shut down
|
||||
*/
|
||||
public UDPPacket receive() {
|
||||
if (_receiver == null)
|
||||
|
@ -58,9 +58,11 @@ class UDPReceiver {
|
||||
public void shutdown() {
|
||||
_keepRunning = false;
|
||||
_inboundQueue.clear();
|
||||
UDPPacket poison = UDPPacket.acquire(_context, false);
|
||||
poison.setMessageType(TYPE_POISON);
|
||||
_inboundQueue.offer(poison);
|
||||
for (int i = 0; i < _transport.getPacketHandlerCount(); i++) {
|
||||
UDPPacket poison = UDPPacket.acquire(_context, false);
|
||||
poison.setMessageType(TYPE_POISON);
|
||||
_inboundQueue.offer(poison);
|
||||
}
|
||||
for (int i = 1; i <= 5 && !_inboundQueue.isEmpty(); i++) {
|
||||
try {
|
||||
Thread.sleep(i * 50);
|
||||
|
@ -1367,6 +1367,15 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
return "";
|
||||
}
|
||||
|
||||
/** @since 0.8.8 */
|
||||
int getPacketHandlerCount() {
|
||||
PacketHandler handler = _handler;
|
||||
if (handler != null)
|
||||
return handler.getHandlerCount();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final int DROP_INACTIVITY_TIME = 60*1000;
|
||||
|
||||
public void failed(OutboundMessageState msg) { failed(msg, true); }
|
||||
|
@ -120,7 +120,9 @@ public class HTTPMUSocket
|
||||
return true;
|
||||
|
||||
try {
|
||||
ssdpMultiSock.leaveGroup(ssdpMultiGroup, ssdpMultiIf);
|
||||
// I2P close it instead of leaving group so the thread dies
|
||||
//ssdpMultiSock.leaveGroup(ssdpMultiGroup, ssdpMultiIf);
|
||||
ssdpMultiSock.close();
|
||||
ssdpMultiSock = null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
Reference in New Issue
Block a user