Search in sources :

Example 1 with KillConnectionHandler

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();
    }
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) KillConnectionHandler(com.alibaba.cobar.mysql.nio.handler.KillConnectionHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RouteResultsetNode(com.alibaba.cobar.route.RouteResultsetNode) CobarConfig(com.alibaba.cobar.CobarConfig) MySQLConnection(com.alibaba.cobar.mysql.nio.MySQLConnection)

Aggregations

CobarConfig (com.alibaba.cobar.CobarConfig)1 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)1 MySQLConnection (com.alibaba.cobar.mysql.nio.MySQLConnection)1 KillConnectionHandler (com.alibaba.cobar.mysql.nio.handler.KillConnectionHandler)1 RouteResultsetNode (com.alibaba.cobar.route.RouteResultsetNode)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1