use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class TestReconnectClient method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
}
};
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration("localhost", 8300));
ReconnectableConnector connector = new ReconnectableConnector(context);
connector.setRetryTime(5000);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setProtocolFactory(new FixedLengthProtocolFactory());
// context.addSessionEventListener(new CloseConnectorSEListener(connector.getRealConnector()));
connector.connect();
ThreadUtil.sleep(Long.MAX_VALUE);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class TestRedisClient method main.
public static void main(String[] args) throws Exception {
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(6379));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(new RedisIOEventHandle());
context.addSessionEventListener(new LoggerSocketSEListener());
context.setProtocolFactory(new RedisProtocolFactory());
SocketSession session = connector.connect();
RedisClient client = new RedisClient(session);
String value = client.set("name222", "hello redis!");
System.out.println("__________________res______" + value);
value = client.get("name222");
System.out.println("__________________res______" + value);
value = client.set("debug", "PONG");
System.out.println("__________________res______" + value);
value = client.get("debug");
System.out.println("__________________res______" + value);
value = client.ping();
System.out.println("__________________res______" + value);
ThreadUtil.sleep(100);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.NioSocketChannelContext 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.NioSocketChannelContext in project baseio by generallycloud.
the class TestGetPhoneNO method main.
public static void main(String[] args) throws Exception {
String serviceKey = "TestGetPhoneNOServlet";
LoggerFactory.configure();
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
ServerConfiguration configuration = new ServerConfiguration(8300);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
connector.getContext().setProtocolFactory(new ProtobaseProtocolFactory());
FixedSession session = new FixedSession(connector.connect());
ProtobaseFuture future = session.request(serviceKey, null);
System.out.println(future.getReadText());
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class TestSessionDisconnect method main.
public static void main(String[] args) throws Exception {
String serviceName = "TestSessionDisconnectServlet";
String param = "ttt";
LoggerFactory.configure();
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
ServerConfiguration configuration = new ServerConfiguration(8300);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
ProtobaseFuture future = session.request(serviceName, param);
System.out.println(future.getReadText());
session.listen(serviceName, new OnFuture() {
@Override
public void onResponse(SocketSession session, Future future) {
ProtobaseFuture f = (ProtobaseFuture) future;
System.out.println(f.getReadText());
}
});
session.write(serviceName, param);
ThreadUtil.sleep(9999);
CloseUtil.close(connector);
}
Aggregations