use of com.alibaba.cobar.mysql.nio.handler.KillConnectionHandler 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