Search in sources :

Example 1 with ReplyCallback

use of herddb.network.ReplyCallback in project herddb by diennea.

the class NettyChannel method handleReply.

private void handleReply(Message anwermessage) {
    final ReplyCallback callback = pendingReplyMessages.get(anwermessage.getReplyMessageId());
    pendingReplyMessages.remove(anwermessage.getReplyMessageId());
    pendingReplyMessagesDeadline.remove(anwermessage.getReplyMessageId());
    Message original = pendingReplyMessagesSource.remove(anwermessage.getReplyMessageId());
    if (callback != null && original != null) {
        submitCallback(() -> {
            callback.replyReceived(original, anwermessage, null);
        });
    }
}
Also used : Message(herddb.network.Message) ReplyCallback(herddb.network.ReplyCallback)

Example 2 with ReplyCallback

use of herddb.network.ReplyCallback 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();
}
Also used : Message(herddb.network.Message) ArrayList(java.util.ArrayList) ReplyCallback(herddb.network.ReplyCallback) IOException(java.io.IOException)

Aggregations

Message (herddb.network.Message)2 ReplyCallback (herddb.network.ReplyCallback)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1