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);
}
}
Aggregations