Search in sources :

Example 1 with BackendNIOHandler

use of io.mycat.proxy.handler.BackendNIOHandler in project Mycat2 by MyCATApache.

the class ProxyReactorThread method processConnectKey.

/**
 * 该方法仅Reactor自身创建的主动连接使用
 */
@SuppressWarnings("unchecked")
protected void processConnectKey(SelectionKey curKey) throws IOException {
    T session = (T) curKey.attachment();
    setCurSession(session);
    SocketChannel channel = (SocketChannel) curKey.channel();
    NIOHandler curNIOHandler = session.getCurNIOHandler();
    if (curNIOHandler instanceof BackendNIOHandler) {
        BackendNIOHandler handler = (BackendNIOHandler) curNIOHandler;
        try {
            if (channel.finishConnect()) {
                handler.onConnect(curKey, session, true, null);
            } else {
                handler.onConnect(curKey, session, false, new ConnectException());
            }
        } catch (Exception e) {
            handler.onConnect(curKey, session, false, e);
        }
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) NIOHandler(io.mycat.proxy.handler.NIOHandler) BackendNIOHandler(io.mycat.proxy.handler.BackendNIOHandler) BackendNIOHandler(io.mycat.proxy.handler.BackendNIOHandler) IOException(java.io.IOException) ClosedSelectorException(java.nio.channels.ClosedSelectorException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Aggregations

BackendNIOHandler (io.mycat.proxy.handler.BackendNIOHandler)1 NIOHandler (io.mycat.proxy.handler.NIOHandler)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 ClosedSelectorException (java.nio.channels.ClosedSelectorException)1 SocketChannel (java.nio.channels.SocketChannel)1