Prevent two NTCP Pumpers

This commit is contained in:
zzz
2009-01-17 17:28:37 +00:00
parent 0ea532c72e
commit 416b0e4540
3 changed files with 19 additions and 3 deletions

View File

@ -285,9 +285,10 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
_log.warn("Halting NTCP to change address");
t.stopListening();
newAddr.setOptions(newProps);
// Give NTCP Pumper time to stop so we don't end up with two...
// Need better way
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
// Wait for NTCP Pumper to stop so we don't end up with two...
while (t.isAlive()) {
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
}
t.restartListening(newAddr);
_log.warn("Changed NTCP Address and started up, address is now " + newAddr);
return;

View File

@ -85,6 +85,13 @@ public class EventPumper implements Runnable {
_selector.wakeup();
}
/**
* Selector can take quite a while to close after calling stopPumping()
*/
public boolean isAlive() {
return _alive || (_selector != null && _selector.isOpen());
}
public void register(ServerSocketChannel chan) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Registering server socket channel");
synchronized (_wantsRegister) { _wantsRegister.add(chan); }

View File

@ -432,6 +432,10 @@ public class NTCPTransport extends TransportImpl {
return bindAddress();
}
public boolean isAlive() {
return _pumper.isAlive();
}
private RouterAddress bindAddress() {
if (_myAddress != null) {
try {
@ -538,6 +542,10 @@ public class NTCPTransport extends TransportImpl {
}
}
/**
* This doesn't (completely) block, caller should check isAlive()
* before calling startListening() or restartListening()
*/
public void stopListening() {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Stopping ntcp transport");
_pumper.stopPumping();