Search in sources :

Example 1 with BalanceReverseSocketSession

use of com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession in project baseio by generallycloud.

the class SimpleNextRouter method getNextRouterSession.

private BalanceReverseSocketSession getNextRouterSession() {
    List<BalanceReverseSocketSession> list = this.routerList;
    if (list.isEmpty()) {
        return null;
    }
    BalanceReverseSocketSession session;
    if (index < list.size()) {
        session = list.get(index++);
    } else {
        index = 1;
        session = list.get(0);
    }
    return session;
}
Also used : BalanceReverseSocketSession(com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession)

Example 2 with BalanceReverseSocketSession

use of com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession in project baseio by generallycloud.

the class SimpleNextRouter method getRouterSessionFresh.

private BalanceReverseSocketSession getRouterSessionFresh(BalanceFacadeSocketSession session) {
    ReentrantLock lock = this.lock;
    lock.lock();
    try {
        BalanceReverseSocketSession router_session = getRouterSession(session);
        if (router_session == null || router_session.isClosed()) {
            router_session = getNextRouterSession();
            if (router_session == null) {
                return null;
            }
            session.setReverseSocketSession(router_session);
        }
        return router_session;
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BalanceReverseSocketSession(com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession)

Example 3 with BalanceReverseSocketSession

use of com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession in project baseio by generallycloud.

the class BalanceFacadeAcceptorHandler method accept.

@Override
public void accept(SocketSession session, Future future) throws Exception {
    BalanceFacadeSocketSession fs = (BalanceFacadeSocketSession) session;
    BalanceFuture f = (BalanceFuture) future;
    if (facadeInterceptor.intercept(fs, f)) {
        logger.info("msg intercepted [ {} ], msg: {}", fs.getRemoteSocketAddress(), f);
        return;
    }
    BalanceReverseSocketSession rs = balanceRouter.getRouterSession(fs, f);
    if (rs == null || rs.isClosed()) {
        noneLoadReadFutureAcceptor.accept(fs, f, balanceReverseLogger);
        return;
    }
    doAccept(fs, rs, f);
}
Also used : BalanceReverseSocketSession(com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession) BalanceFuture(com.generallycloud.baseio.balance.BalanceFuture)

Example 4 with BalanceReverseSocketSession

use of com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession in project baseio by generallycloud.

the class BalanceFacadeAcceptorSEListener method sessionClosed.

@Override
public void sessionClosed(SocketSession session) {
    BalanceFacadeSocketSession fs = (BalanceFacadeSocketSession) session;
    balanceRouter.removeClientSession(fs);
    logger.info("client from [ {} ] disconnected.", session.getRemoteSocketAddress());
    BalanceRouter balanceRouter = balanceContext.getBalanceRouter();
    BalanceReverseSocketSession rs = balanceRouter.getRouterSession(fs);
    if (rs == null) {
        return;
    }
    ChannelLostFutureFactory factory = balanceContext.getChannelLostReadFutureFactory();
    if (factory == null) {
        return;
    }
    rs.flush(factory.createChannelLostPacket(fs));
}
Also used : BalanceReverseSocketSession(com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession) ChannelLostFutureFactory(com.generallycloud.baseio.balance.ChannelLostFutureFactory) BalanceRouter(com.generallycloud.baseio.balance.router.BalanceRouter)

Aggregations

BalanceReverseSocketSession (com.generallycloud.baseio.balance.reverse.BalanceReverseSocketSession)4 BalanceFuture (com.generallycloud.baseio.balance.BalanceFuture)1 ChannelLostFutureFactory (com.generallycloud.baseio.balance.ChannelLostFutureFactory)1 BalanceRouter (com.generallycloud.baseio.balance.router.BalanceRouter)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1