use of herddb.network.Message in project herddb by diennea.
the class ServerSideConnectionPeer method handleSaslTokenMessageRequest.
private void handleSaslTokenMessageRequest(Message message, Channel _channel) {
try {
byte[] token = (byte[]) message.parameters.get("token");
if (token == null) {
token = new byte[0];
}
String mech = (String) message.parameters.get("mech");
if (saslNettyServer == null) {
saslNettyServer = new SaslNettyServer(server, mech);
}
byte[] responseToken = saslNettyServer.response(token);
Message tokenChallenge = Message.SASL_TOKEN_SERVER_RESPONSE(responseToken);
_channel.sendReplyMessage(message, tokenChallenge);
} catch (Exception err) {
Message error = Message.ERROR(null, err);
_channel.sendReplyMessage(message, error);
}
}
use of herddb.network.Message in project herddb by diennea.
the class NettyChannel method sendReplyMessage.
@Override
public void sendReplyMessage(Message inAnswerTo, Message message) {
if (message.getMessageId() == null) {
message.assignMessageId();
}
if (this.socket == null) {
LOGGER.log(Level.SEVERE, this + " channel not active, discarding reply message " + message);
return;
}
message.setReplyMessageId(inAnswerTo.messageId);
sendOneWayMessage(message, new SendResultCallback() {
@Override
public void messageSent(Message originalMessage, Throwable error) {
if (error != null) {
LOGGER.log(Level.SEVERE, this + " error:" + error, error);
}
}
});
}
use of herddb.network.Message in project herddb by diennea.
the class NettyChannel method processPendingReplyMessagesDeadline.
private void processPendingReplyMessagesDeadline() {
List<String> messagesWithNoReply = new ArrayList<>();
long now = System.currentTimeMillis();
pendingReplyMessagesDeadline.forEach((messageId, deadline) -> {
if (deadline < now) {
messagesWithNoReply.add(messageId);
}
});
if (messagesWithNoReply.isEmpty()) {
return;
}
LOGGER.log(Level.SEVERE, this + " found " + messagesWithNoReply + " without reply, channel will be closed");
ioErrors = true;
for (String messageId : messagesWithNoReply) {
Message original = pendingReplyMessagesSource.remove(messageId);
ReplyCallback callback = pendingReplyMessages.remove(messageId);
pendingReplyMessagesDeadline.remove(messageId);
if (original != null && callback != null) {
submitCallback(() -> {
callback.replyReceived(original, null, new IOException(this + " reply timeout expired, channel will be closed"));
});
}
}
close();
}
use of herddb.network.Message in project herddb by diennea.
the class NettyChannel method sendMessageWithAsyncReply.
@Override
public void sendMessageWithAsyncReply(Message message, long timeout, ReplyCallback callback) {
if (message.getMessageId() == null) {
message.assignMessageId();
}
if (!isValid()) {
submitCallback(() -> {
callback.replyReceived(message, null, new Exception(this + " connection is not active"));
});
return;
}
pendingReplyMessages.put(message.getMessageId(), callback);
pendingReplyMessagesSource.put(message.getMessageId(), message);
pendingReplyMessagesDeadline.put(message.getMessageId(), System.currentTimeMillis() + timeout);
sendOneWayMessage(message, new SendResultCallback() {
@Override
public void messageSent(Message originalMessage, Throwable error) {
if (error != null) {
LOGGER.log(Level.SEVERE, this + ": error while sending reply message to " + originalMessage, error);
submitCallback(() -> {
callback.replyReceived(message, null, new Exception(this + ": error while sending reply message to " + originalMessage, error));
});
}
}
});
}
use of herddb.network.Message in project herddb by diennea.
the class NettyChannel method failPendingMessages.
private void failPendingMessages(String socketDescription) {
pendingReplyMessages.forEach((key, callback) -> {
Message original = pendingReplyMessagesSource.remove(key);
LOGGER.log(Level.SEVERE, this + " message " + key + " was not replied (" + original + ") callback:" + callback);
if (original != null) {
submitCallback(() -> {
callback.replyReceived(original, null, new IOException("comunication channel is closed. Cannot wait for pending messages, socket=" + socketDescription));
});
}
});
pendingReplyMessages.clear();
pendingReplyMessagesSource.clear();
pendingReplyMessagesDeadline.clear();
}
Aggregations