use of com.alibaba.cobar.exception.UnknownPacketException in project cobar by alibaba.
the class MySQLChannel method sendCharset.
/**
* 发送字符集设置
*/
private void sendCharset(int ci) throws IOException {
// 发送命令: 直接写入到out中即可
CommandPacket cmd = getCharsetCommand(ci);
cmd.write(out);
out.flush();
BinaryPacket bin = receive();
switch(bin.data[0]) {
case OkPacket.FIELD_COUNT:
this.charsetIndex = ci;
this.charset = CharsetUtil.getCharset(ci);
this.dbCharset = CharsetUtil.getCharset(ci);
break;
case ErrorPacket.FIELD_COUNT:
ErrorPacket err = new ErrorPacket();
err.read(bin);
throw new ErrorPacketException(new String(err.message, charset));
default:
throw new UnknownPacketException(bin.toString());
}
}
use of com.alibaba.cobar.exception.UnknownPacketException in project cobar by alibaba.
the class MySQLChannel method sendAutocommit.
/**
* 发送事务递交模式设置
*/
private void sendAutocommit(boolean autocommit) throws IOException {
CommandPacket cmd = getAutocommitCommand(autocommit);
cmd.write(out);
out.flush();
BinaryPacket bin = receive();
switch(bin.data[0]) {
case OkPacket.FIELD_COUNT:
this.autocommit = autocommit;
break;
case ErrorPacket.FIELD_COUNT:
ErrorPacket err = new ErrorPacket();
err.read(bin);
throw new ErrorPacketException(new String(err.message, charset));
default:
throw new UnknownPacketException(bin.toString());
}
}
use of com.alibaba.cobar.exception.UnknownPacketException in project cobar by alibaba.
the class DefaultCommitExecutor method _commit.
private void _commit(MySQLChannel mc, BlockingSession session) {
ServerConnection source = session.getSource();
if (isFail.get() || source.isClosed()) {
mc.setRunning(false);
try {
throw new Exception("other task fails, commit cancel");
} catch (Exception e) {
handleException(mc, session, e);
}
return;
}
try {
BinaryPacket bin = mc.commit();
switch(bin.data[0]) {
case OkPacket.FIELD_COUNT:
mc.setRunning(false);
if (decrementCountBy(1)) {
try {
if (isFail.get()) {
// some other tasks failed
session.clear();
source.writeErrMessage(ErrorCode.ER_YES, getErrorMessage() + " error!");
} else {
// all tasks are successful
session.release();
if (indicatedOK != null) {
indicatedOK.write(source);
} else {
ByteBuffer buffer = source.allocate();
source.write(bin.write(buffer, source));
}
}
} catch (Exception e) {
getLogger().warn("exception happens in success notification: " + source, e);
}
}
break;
case ErrorPacket.FIELD_COUNT:
mc.setRunning(false);
isFail.set(true);
if (decrementCountBy(1)) {
try {
session.clear();
getLogger().warn(mc.getErrLog(getErrorMessage(), mc.getErrMessage(bin), source));
ByteBuffer buffer = source.allocate();
source.write(bin.write(buffer, source));
} catch (Exception e) {
getLogger().warn("exception happens in failure notification: " + source, e);
}
}
break;
default:
throw new UnknownPacketException(bin.toString());
}
} catch (IOException e) {
mc.close();
handleException(mc, session, e);
} catch (RuntimeException e) {
mc.close();
handleException(mc, session, e);
}
}
use of com.alibaba.cobar.exception.UnknownPacketException in project cobar by alibaba.
the class MySQLChannel method auth323.
/**
* 323协议认证
*/
private void auth323(byte packetId, byte[] seed) throws IOException {
Reply323Packet r323 = new Reply323Packet();
r323.packetId = ++packetId;
String passwd = dsc.getPassword();
if (passwd != null && passwd.length() > 0) {
r323.seed = SecurityUtil.scramble323(passwd, new String(seed)).getBytes();
}
r323.write(out);
out.flush();
BinaryPacket bin = receive();
switch(bin.data[0]) {
case OkPacket.FIELD_COUNT:
afterSuccess();
break;
case ErrorPacket.FIELD_COUNT:
ErrorPacket err = new ErrorPacket();
err.read(bin);
throw new ErrorPacketException(new String(err.message, charset));
default:
throw new UnknownPacketException(bin.toString());
}
}
Aggregations