use of com.generallycloud.baseio.component.SocketSessionActiveSEListener in project baseio by generallycloud.
the class TestHeartBeat 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());
}
};
ServerConfiguration configuration = new ServerConfiguration(18300);
configuration.setSERVER_SESSION_IDLE_TIME(20);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.addSessionIdleEventListener(new SocketSessionActiveSEListener());
context.addSessionEventListener(new LoggerSocketSEListener());
context.setBeatFutureFactory(new FLBeatFutureFactory());
context.setProtocolFactory(new FixedLengthProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
SocketSession session = connector.connect();
String param = "tttt";
long old = System.currentTimeMillis();
for (int i = 0; i < 5; i++) {
Future future = new FixedLengthFutureImpl(context);
future.write(param);
session.flush(future);
ThreadUtil.sleep(300);
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
Thread.sleep(2000);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.SocketSessionActiveSEListener 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