Added max. retries for ack
This commit is contained in:
parent
aeea7ad486
commit
2d8008abf6
@ -13,6 +13,12 @@ public class Ack {
|
||||
// timeout in seconds
|
||||
private final int TIMEOUT = 1000;
|
||||
|
||||
private final int MAX_RETRIES = 5;
|
||||
|
||||
// the number of times we already sent this ack (IRGENDWANN IST AUCH MAL
|
||||
// SCHLUSS!)
|
||||
private int retries = 1;
|
||||
|
||||
private int id;
|
||||
private SocketAddress address;
|
||||
private ByteBuffer buf;
|
||||
@ -73,6 +79,7 @@ public class Ack {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
retries++;
|
||||
while (notReceived && System.currentTimeMillis() < timeToStop) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
@ -83,32 +90,19 @@ public class Ack {
|
||||
|
||||
// Timeout hit -> re-send
|
||||
if (notReceived) {
|
||||
try {
|
||||
LOGGER.log(Level.INFO, "Absent ack #{0}. Resending to {1}",
|
||||
new Object[] { id, address.toString() });
|
||||
|
||||
/**
|
||||
* TODO: This would be the intuitive order (first re-send,
|
||||
* then start the new TimeoutThread), right? Unfortunately
|
||||
* this gives ugly log outputs, because the re-sent message
|
||||
* arrives before the new thread is constructed, so we get:
|
||||
*
|
||||
* <pre>
|
||||
* [2012-11-28 07:53:05 PM] node.Node INFO: Initialized node /127.0.0.1:37179
|
||||
* a spawn b
|
||||
* [2012-11-28 07:53:15 PM] node.Node INFO: Initialized node /127.0.0.1:35358
|
||||
* [2012-11-28 07:53:15 PM] node.Ack INFO: Starting timeout thread for ack #-1276001492
|
||||
* [2012-11-28 07:53:15 PM] node.Node INFO: /127.0.0.1:35358 received invite from /127.0.0.1:37179
|
||||
* [2012-11-28 07:53:20 PM] node.Ack INFO: Absent ack #-1276001492). Resending to /127.0.0.1:35358
|
||||
* </pre>
|
||||
*
|
||||
* No big deal, and we could just swap the statements, but
|
||||
* meh...
|
||||
*/
|
||||
channel.send(buf, address);
|
||||
startThread();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
if (retries < MAX_RETRIES) {
|
||||
try {
|
||||
LOGGER.log(Level.INFO,
|
||||
"Absent ack #{0}. Resending to {1}",
|
||||
new Object[] { id, address.toString() });
|
||||
channel.send(buf, address);
|
||||
startThread();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
LOGGER.log(Level.SEVERE, "Dropping ack #{0}",
|
||||
new Object[] { id });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user