本文整理汇总了Java中com.alibaba.cobar.server.ServerConnection.write方法的典型用法代码示例。如果您正苦于以下问题:Java ServerConnection.write方法的具体用法?Java ServerConnection.write怎么用?Java ServerConnection.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.cobar.server.ServerConnection
的用法示例。
在下文中一共展示了ServerConnection.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(ServerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
buffer = eof.write(buffer, c);
byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(FrontendConnection.getServerVersion().getBytes());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
c.write(buffer);
}
示例2: oneSetResponse
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
private static void oneSetResponse(String stmt, ServerConnection c, int rs) {
if ((rs & 0xff) == CHARACTER_SET_CLIENT) {
/* 忽略client属性设置 */
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
} else {
String charset = stmt.substring(rs >>> 8).trim();
if (charset.endsWith(";")) {
/* 结尾为 ; 标识符 */
charset = charset.substring(0, charset.length() - 1);
}
if (charset.startsWith("'") || charset.startsWith("`")) {
/* 与mysql保持一致,引号里的字符集不做trim操作 */
charset = charset.substring(1, charset.length() - 1);
}
// 设置字符集
setCharset(charset, c);
}
}
示例3: setCharset
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
private static void setCharset(String charset, ServerConnection c) {
if ("null".equalsIgnoreCase(charset)) {
/* 忽略字符集为null的属性设置 */
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
} else if (c.setCharset(charset)) {
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
} else {
try {
if (c.setCharsetIndex(Integer.parseInt(charset))) {
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
} else {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset :" + charset);
}
} catch (RuntimeException e) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset :" + charset);
}
}
}
示例4: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(ServerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
buffer = eof.write(buffer, c);
byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(getUser(c));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
c.write(buffer);
}
示例5: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(ServerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
buffer = eof.write(buffer, c);
byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(c.getSchema(), c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
c.write(buffer);
}
示例6: okResponse
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
@Override
public void okResponse(byte[] ok, MySQLConnection conn) {
conn.setRunning(false);
if (decrementCountBy(1)) {
if (isFail.get() || session.closed()) {
notifyError((byte) 1);
} else {
session.releaseConnections();
if (okPacket == null) {
ServerConnection source = session.getSource();
source.write(ok);
} else {
okPacket.write(session.getSource());
}
}
}
}
示例7: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(ServerConnection c) {
if (CobarServer.getInstance().isOnline()) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
buffer = eof.write(buffer, c);
byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(getUser(c));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
c.write(buffer);
} else {
error.write(c);
}
}
示例8: handleSuccessEOF
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
/**
* @throws nothing never throws any exception
*/
private void handleSuccessEOF(BlockingSession ss, BinaryPacket bin) {
if (decrementCountAndIsZero()) {
if (isFail.get()) {
notifyFailure(ss);
return;
}
try {
ServerConnection source = ss.getSource();
if (source.isAutocommit()) {
ss.release();
}
bin.packetId = ++packetId;// LAST_EOF
source.write(bin.write(buffer, source));
} catch (Exception e) {
LOGGER.warn("exception happens in success notification: " + ss.getSource(), e);
}
}
}
示例9: okResponse
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
@Override
public void okResponse(byte[] data, MySQLConnection conn) {
boolean executeResponse = false;
try {
executeResponse = conn.syncAndExcute();
} catch (UnsupportedEncodingException e) {
executeException(conn);
}
if (executeResponse) {
conn.setRunning(false);
ServerConnection source = session.getSource();
if (source.isAutocommit()) {
session.clearConnections();
}
endRunning();
OkPacket ok = new OkPacket();
ok.read(data);
source.setLastInsertId(ok.insertId);
buffer = source.writeToBuffer(data, buffer);
source.write(buffer);
}
}
示例10: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(ServerConnection c) {
if (CobarServer.getInstance().isOnline()) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
buffer = eof.write(buffer, c);
buffer = status.write(buffer, c);
buffer = lastEof.write(buffer, c);
c.write(buffer);
} else {
error.write(c);
}
}
示例11: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(String stmt, ServerConnection c, int rs) {
String sqlMode = stmt.substring(rs >>> 8).trim();
if (sqlMode.startsWith("'") || sqlMode.startsWith("`") || sqlMode.startsWith("\"")) {
sqlMode = sqlMode.substring(1, sqlMode.length() - 1);
}
c.setSqlMode(sqlMode);
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
}
示例12: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(ServerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(VERSION_COMMENT);
row.packetId = ++packetId;
buffer = row.write(buffer, c);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// post write
c.write(buffer);
}
示例13: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(ServerConnection c, String stmt, int aliasIndex) {
String alias = ParseUtil.parseAlias(stmt, aliasIndex);
if (alias == null) {
alias = ORG_NAME;
}
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
byte packetId = header.packetId;
FieldPacket field = PacketUtil.getField(alias, ORG_NAME, Fields.FIELD_TYPE_LONGLONG);
field.packetId = ++packetId;
buffer = field.write(buffer, c);
// write eof
EOFPacket eof = new EOFPacket();
eof.packetId = ++packetId;
buffer = eof.write(buffer, c);
// write rows
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(c.getLastInsertId()));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// post write
c.write(buffer);
}
示例14: response
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void response(ServerConnection c, String stmt, int aliasIndex, final String orgName) {
String alias = ParseUtil.parseAlias(stmt, aliasIndex);
if (alias == null) {
alias = orgName;
}
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
byte packetId = header.packetId;
FieldPacket field = PacketUtil.getField(alias, orgName, Fields.FIELD_TYPE_LONGLONG);
field.packetId = ++packetId;
buffer = field.write(buffer, c);
// write eof
EOFPacket eof = new EOFPacket();
eof.packetId = ++packetId;
buffer = eof.write(buffer, c);
// write rows
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(c.getLastInsertId()));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// post write
c.write(buffer);
}
示例15: execute
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void execute(ServerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
String charset = c.getCharset();
for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
for (FrontendConnection fc : p.getFrontends().values()) {
if (fc != null) {
if (c.getUser().equals(fc.getUser())) {
RowDataPacket row = getRow(fc, charset);
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}