@Override
public boolean send(int partitionId, EventMessage eventMessage) {
try {
byte[] message = serDeser.serialize(eventMessage);
ClusterNode node = nodes.get(partitionId);
if (node == null) {
LoggerFactory.getLogger(getClass()).error(
"Cannot send message to partition {} because this partition is not visible to this emitter",
partitionId);
return false;
}
byte[] byteBuffer = new byte[message.length];
System.arraycopy(message, 0, byteBuffer, 0, message.length);
InetAddress inetAddress = inetCache.get(partitionId);
if (inetAddress == null) {
inetAddress = InetAddress.getByName(node.getMachineName());
inetCache.put(partitionId, inetAddress);
}
DatagramPacket dp = new DatagramPacket(byteBuffer, byteBuffer.length, inetAddress, node.getPort());
socket.send(dp);
} catch (IOException e) {
throw new RuntimeException(e);
}