use of com.generallycloud.baseio.codec.protobase.future.ProtobaseBeatFutureFactory 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.codec.protobase.future.ProtobaseBeatFutureFactory in project baseio by generallycloud.
the class TestBeat 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("______________" + future.getReadText());
}
};
String serviceKey = "TestSimpleServlet";
ServerConfiguration configuration = new ServerConfiguration(18300);
configuration.setSERVER_SESSION_IDLE_TIME(10);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.addSessionIdleEventListener(new SocketSessionActiveSEListener());
context.setBeatFutureFactory(new ProtobaseBeatFutureFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
SocketSession session = connector.connect();
String param = "tttt";
long old = System.currentTimeMillis();
for (int i = 0; i < 5; i++) {
Future future = new ProtobaseFutureImpl(context, serviceKey);
future.write(param);
session.flush(future);
ThreadUtil.sleep(300);
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
Thread.sleep(2000);
CloseUtil.close(connector);
}
Aggregations