use of com.alibaba.cobar.mysql.MySQLDataNode in project cobar by alibaba.
the class ShowDataSources method response.
public static void response(ServerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write field
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
Map<String, MySQLDataNode> nodes = CobarServer.getInstance().getConfig().getDataNodes();
for (MySQLDataNode node : nodes.values()) {
RowDataPacket row = getRow(node, c.getCharset());
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);
}
use of com.alibaba.cobar.mysql.MySQLDataNode in project cobar by alibaba.
the class NonBlockingSession method kill.
private void kill(Runnable run) {
boolean hooked = false;
AtomicInteger count = null;
Map<RouteResultsetNode, MySQLConnection> killees = null;
for (RouteResultsetNode node : target.keySet()) {
MySQLConnection c = target.get(node);
if (c != null && c.isRunning()) {
if (!hooked) {
hooked = true;
killees = new HashMap<RouteResultsetNode, MySQLConnection>();
count = new AtomicInteger(0);
}
killees.put(node, c);
count.incrementAndGet();
}
}
if (hooked) {
for (Entry<RouteResultsetNode, MySQLConnection> en : killees.entrySet()) {
KillConnectionHandler kill = new KillConnectionHandler(en.getValue(), this, run, count);
CobarConfig conf = CobarServer.getInstance().getConfig();
MySQLDataNode dn = conf.getDataNodes().get(en.getKey().getName());
try {
dn.getConnection(kill, en.getKey());
} catch (Exception e) {
LOGGER.error("get killer connection failed for " + en.getKey(), e);
kill.connectionError(e, null);
}
}
} else {
run.run();
}
}
Aggregations