public boolean send(Packet packet, Address target) {
return send(packet, target, null);
}
private boolean send(Packet packet, Address target, FutureSend futureSend) {
final ConnectionManager connectionManager = node.getConnectionManager();
final Connection connection = connectionManager.getConnection(target);
if (connection != null) {
return send(packet, connection);
} else {
if (futureSend == null) {
futureSend = new FutureSend(packet, target);
}
final int retries = futureSend.retries;
if (retries < 5 && node.isActive()) {
connectionManager.getOrConnect(target, true);
// TODO: Caution: may break the order guarantee of the packets sent from the same thread!
executionService.schedule(futureSend, (retries + 1) * 100, TimeUnit.MILLISECONDS);
return true;
}
return false;