blob: ad44eb143065c9ee8ffefc11a7fda3bc18f613d2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package derms.net.rmulticast;
import derms.net.Packet;
import java.io.Serializable;
import java.net.DatagramPacket;
import java.net.MulticastSocket;
import java.net.SocketAddress;
import java.util.concurrent.BlockingQueue;
import java.util.logging.Logger;
/** Retransmit dropped messages. */
class Retransmit<T extends Serializable & Hashable> implements Runnable {
private final BlockingQueue<Message<T>> retransmissions;
private final MulticastSocket outSock;
private final SocketAddress group;
private final Logger log;
Retransmit(BlockingQueue<Message<T>> retransmissions, MulticastSocket outSock, SocketAddress group) {
this.retransmissions = retransmissions;
this.outSock = outSock;
this.group = group;
this.log = Logger.getLogger(this.getClass().getName());
}
@Override
public void run() {
try {
for (; ; ) {
Message<T> msg = retransmissions.take();
try {
DatagramPacket pkt = Packet.encode(msg, group);
synchronized (outSock) {
outSock.send(pkt);
}
} catch (Exception e) {
log.warning(e.getMessage());
}
}
} catch (InterruptedException e) {
log.info("Retransmit thread interrupted: " + e.getMessage());
}
}
}
|