Search in sources :

Example 1 with Frame

use of com.mysql.cj.x.protobuf.MysqlxNotice.Frame in project aws-mysql-jdbc by awslabs.

the class SyncMessageReader method readMessageLocal.

@SuppressWarnings("unchecked")
private <T extends GeneratedMessageV3> T readMessageLocal(Class<T> messageClass, boolean fromQueue) {
    XMessageHeader header;
    if (fromQueue) {
        header = this.headersQueue.poll();
        T msg = (T) this.messagesQueue.poll();
        if (msg != null) {
            return msg;
        }
    } else {
        header = this.headersQueue.getLast();
    }
    Parser<T> parser = (Parser<T>) MessageConstants.MESSAGE_CLASS_TO_PARSER.get(messageClass);
    byte[] packet = new byte[header.getMessageSize()];
    try {
        this.inputStream.readFully(packet);
    } catch (IOException ex) {
        // TODO close socket?
        throw new CJCommunicationsException("Cannot read packet payload", ex);
    }
    try {
        T msg = parser.parseFrom(packet);
        if (msg instanceof Frame && ((Frame) msg).getType() == Frame.Type.WARNING_VALUE && ((Frame) msg).getScope() == Frame.Scope.GLOBAL) {
            XWarning w = new XWarning((Frame) msg);
            int code = (int) w.getCode();
            if (code == MysqlErrorNumbers.ER_SERVER_SHUTDOWN || code == MysqlErrorNumbers.ER_IO_READ_ERROR || code == MysqlErrorNumbers.ER_SESSION_WAS_KILLED) {
                CJCommunicationsException ex = new CJCommunicationsException(w.getMessage());
                ex.setVendorCode(code);
                if (this.protocolEventHandler != null) {
                    this.protocolEventHandler.invokeListeners(code == MysqlErrorNumbers.ER_SERVER_SHUTDOWN ? EventType.SERVER_SHUTDOWN : EventType.SERVER_CLOSED_SESSION, ex);
                }
                throw ex;
            }
        }
        return msg;
    } catch (InvalidProtocolBufferException ex) {
        throw new WrongArgumentException(ex);
    }
}
Also used : XWarning(com.mysql.cj.protocol.x.Notice.XWarning) Frame(com.mysql.cj.x.protobuf.MysqlxNotice.Frame) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) IOException(java.io.IOException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) Parser(com.google.protobuf.Parser)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Parser (com.google.protobuf.Parser)1 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)1 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)1 XWarning (com.mysql.cj.protocol.x.Notice.XWarning)1 Frame (com.mysql.cj.x.protobuf.MysqlxNotice.Frame)1 IOException (java.io.IOException)1