use of org.nustaq.fastcast.api.FCSubscriber in project fast-cast by RuedigerMoeller.
the class TransportDriver method receiveDatagram.
private boolean receiveDatagram(ByteBuffer p, byte[] wrappedArr) throws IOException {
if (trans.receive(p)) {
boolean selfSent = receivedPacket.getSender().equals(nodeId);
if (!selfSent) {
// debug
if (RETRANS_DEBUG) {
Class debugtype = receivedPacket.getPointedClass();
if (debugtype == RetransPacket.class) {
RetransPacket retransPacket = receivedPacket.cast().detach();
System.out.println("retrans received " + retransPacket);
}
}
//
int topic = receivedPacket.getTopic();
if (topic > MAX_NUM_TOPICS || topic < 0) {
FCLog.get().warn("foreign traffic");
return true;
}
if (receiver[topic] == null && sender[topic] == null) {
return true;
}
Class type = receivedPacket.getPointedClass();
StructString receivedPacketReceiver = receivedPacket.getReceiver();
if (type == DataPacket.class) {
if (receiver[topic] == null)
return true;
dispatchDataPacket(receivedPacket, topic);
} else if (type == RetransPacket.class) {
if (sender[topic] == null)
return true;
if (receivedPacketReceiver == null || !receivedPacketReceiver.equals(nodeId)) {
return true;
}
if (RETRANS_DEBUG)
System.out.println("retrans dispatched ");
dispatchRetransmissionRequest(receivedPacket, topic);
} else if (type == ControlPacket.class) {
if (isForeignReceiver(receivedPacketReceiver)) {
return true;
}
ControlPacket control = receivedPacket.cast();
if (control.getType() == ControlPacket.DROPPED) {
ReceiveBufferDispatcher receiveBufferDispatcher = receiver[topic];
if (receiveBufferDispatcher != null) {
FCLog.get().warn(nodeId + " has been dropped by " + receivedPacket.getSender() + " on service " + receiveBufferDispatcher.getTopicEntry().getTopicId());
FCSubscriber service = receiveBufferDispatcher.getTopicEntry().getSubscriber();
if (service != null) {
if (service.dropped()) {
// retry if returns true
FCLog.get().warn("..resyncing..");
PacketReceiveBuffer buffer = receiveBufferDispatcher.getBuffer(receivedPacket.getSender());
if (buffer != null) {
buffer.resync();
} else {
FCLog.get().warn("unexpected null buffer");
}
} else {
// topic is lost forever now ..
receiver[topic] = null;
receiveBufferDispatcher.cleanupTopic();
}
}
}
}
// heartbeats are sent as regular data packets in order to have initialSync to happen correctly
// else if ( control.getType() == ControlPacket.HEARTBEAT ) {
// ReceiveBufferDispatcher receiveBufferDispatcher = receiver[topic];
// if ( receiveBufferDispatcher != null ) {
// PacketReceiveBuffer buffer = receiveBufferDispatcher.getBuffer(control.getSender());
// if ( buffer != null ) {
// buffer.updateHeartBeat(control.getSeqNo(),System.currentTimeMillis());
// }
// }
// }
}
return true;
} else {
return false;
}
}
return false;
}
Aggregations