use of com.generallycloud.baseio.component.SocketSessionAliveSEListener in project baseio by generallycloud.
the class SimpleTestProtobaseServer method main.
public static void main(String[] args) throws Exception {
DebugUtil.setEnableDebug(true);
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
DebugUtil.debug("receive:" + future.getReadText());
future.write("yes server already accept your message:");
future.write(future.getReadText());
session.flush(future);
}
};
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
context.getServerConfiguration().setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
context.getServerConfiguration().setSERVER_SESSION_IDLE_TIME(60 * 60 * 1000);
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setBeatFutureFactory(new ProtobaseBeatFutureFactory());
context.addSessionIdleEventListener(new SocketSessionAliveSEListener());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new ProtobaseProtocolFactory());
acceptor.bind();
}
use of com.generallycloud.baseio.component.SocketSessionAliveSEListener in project baseio by generallycloud.
the class HttpApplicationContextEnricher method enrich.
@Override
public void enrich(ApplicationContext context) {
SocketChannelContext channelContext = context.getChannelContext();
context.setServiceFilter(new FutureAcceptorHttpFilter());
context.setExceptionCaughtHandle(new HttpExceptionCaughtHandle());
// FIXME 重复的
Set<String> blackIPs = context.getBlackIPs();
if (blackIPs != null && !blackIPs.isEmpty()) {
channelContext.addSessionEventListener(new BlackIPFilter(blackIPs));
}
channelContext.setBeatFutureFactory(new WebSocketBeatFutureFactory());
channelContext.addSessionEventListener(new LoggerSocketSEListener());
channelContext.addSessionIdleEventListener(new SocketSessionAliveSEListener());
channelContext.setProtocolFactory(new ServerHTTPProtocolFactory());
}
Aggregations