Search in sources :

Example 16 with Message

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);
    }
}
Also used : Message(herddb.network.Message) SaslNettyServer(herddb.security.sasl.SaslNettyServer) DuplicatePrimaryKeyException(herddb.model.DuplicatePrimaryKeyException) HerdDBInternalException(herddb.core.HerdDBInternalException) StatementExecutionException(herddb.model.StatementExecutionException) NotLeaderException(herddb.model.NotLeaderException) DataScannerException(herddb.model.DataScannerException)

Example 17 with Message

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);
            }
        }
    });
}
Also used : Message(herddb.network.Message) SendResultCallback(herddb.network.SendResultCallback)

Example 18 with Message

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

Example 19 with Message

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));
                });
            }
        }
    });
}
Also used : Message(herddb.network.Message) SendResultCallback(herddb.network.SendResultCallback) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 20 with Message

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

Aggregations

Message (herddb.network.Message)22 StatementExecutionException (herddb.model.StatementExecutionException)10 NotLeaderException (herddb.model.NotLeaderException)9 ArrayList (java.util.ArrayList)9 TuplesList (herddb.utils.TuplesList)8 HerdDBInternalException (herddb.core.HerdDBInternalException)7 DataScannerException (herddb.model.DataScannerException)7 DuplicatePrimaryKeyException (herddb.model.DuplicatePrimaryKeyException)7 List (java.util.List)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 HashMap (java.util.HashMap)6 Table (herddb.model.Table)5 Record (herddb.model.Record)4 TransactionContext (herddb.model.TransactionContext)4 SQLPlannedOperationStatement (herddb.model.commands.SQLPlannedOperationStatement)4 ScanStatement (herddb.model.commands.ScanStatement)4 Channel (herddb.network.Channel)4 KeyValue (herddb.network.KeyValue)4 DataAccessor (herddb.utils.DataAccessor)4 Map (java.util.Map)4