Search in sources :

Example 1 with SessionThread

use of io.mycat.proxy.reactor.SessionThread in project Mycat2 by MyCATApache.

the class MycatSessionManager method acceptNewSocketChannel.

@Override
public void acceptNewSocketChannel(Object keyAttachement, BufferPool bufPool, Selector nioSelector, SocketChannel frontChannel) throws IOException {
    MySQLClientAuthHandler mySQLClientAuthHandler = new MySQLClientAuthHandler(this);
    MycatSession mycat = new MycatSession(new MycatDataContextImpl(), bufPool, mySQLClientAuthHandler, this);
    // 用于monitor监控获取session
    SessionThread thread = (SessionThread) Thread.currentThread();
    thread.setCurSession(mycat);
    try {
        mycat.register(nioSelector, frontChannel, SelectionKey.OP_READ);
        MycatMonitor.onNewMycatSession(mycat);
        mySQLClientAuthHandler.sendAuthPackge(mycat);
        this.mycatSessions.add(mycat);
    } catch (Exception e) {
        MycatMonitor.onAuthHandlerWriteException(mycat, e);
        mycat.close(false, e);
    }
}
Also used : MycatDataContextImpl(io.mycat.runtime.MycatDataContextImpl) SessionThread(io.mycat.proxy.reactor.SessionThread) MySQLClientAuthHandler(io.mycat.proxy.handler.front.MySQLClientAuthHandler) IOException(java.io.IOException)

Example 2 with SessionThread

use of io.mycat.proxy.reactor.SessionThread in project Mycat2 by MyCATApache.

the class MycatMonitorCallback method getSession.

static Session getSession() {
    SessionThread thread = getThread();
    Session curSession = thread.getCurSession();
    if (curSession instanceof MycatSession) {
        return curSession;
    } else if (curSession instanceof MySQLClientSession) {
        MycatSession mycatSession = ((MySQLClientSession) curSession).getMycat();
        if (mycatSession == null) {
            return curSession;
        } else {
            return mycatSession;
        }
    } else {
        throw new MycatException("unknown session");
    }
}
Also used : MycatSession(io.mycat.proxy.session.MycatSession) SessionThread(io.mycat.proxy.reactor.SessionThread) MycatException(io.mycat.MycatException) MySQLClientSession(io.mycat.proxy.session.MySQLClientSession) MycatSession(io.mycat.proxy.session.MycatSession) Session(io.mycat.proxy.session.Session) MySQLClientSession(io.mycat.proxy.session.MySQLClientSession)

Aggregations

SessionThread (io.mycat.proxy.reactor.SessionThread)2 MycatException (io.mycat.MycatException)1 MySQLClientAuthHandler (io.mycat.proxy.handler.front.MySQLClientAuthHandler)1 MySQLClientSession (io.mycat.proxy.session.MySQLClientSession)1 MycatSession (io.mycat.proxy.session.MycatSession)1 Session (io.mycat.proxy.session.Session)1 MycatDataContextImpl (io.mycat.runtime.MycatDataContextImpl)1 IOException (java.io.IOException)1