use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class TestSimple method main.
public static void main(String[] args) throws Exception {
String serviceKey = "/test-simple";
String param = "ttt";
IoEventHandleAdaptor eventHandle = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
System.out.println("________________________" + future.getReadText());
}
};
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
context.setIoEventHandleAdaptor(eventHandle);
SocketSession session = connector.connect();
ProtobaseFuture f = new ProtobaseFutureImpl(connector.getContext(), serviceKey);
f.write(param);
session.flush(f);
ThreadUtil.sleep(500);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class SimpleTestProtobaseClient method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
System.out.println();
System.out.println("____________________" + future.getReadText());
System.out.println();
}
};
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration("localhost", 18300));
context.getServerConfiguration().setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
SocketChannelConnector connector = new SocketChannelConnector(context);
connector.setTimeout(99999999);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setProtocolFactory(new ProtobaseProtocolFactory());
SocketSession session = connector.connect();
ProtobaseFuture future = new ProtobaseFutureImpl(context, "test222");
future.write("hello server!");
session.flush(future);
ThreadUtil.sleep(100);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class TestTransaction method main.
public static void main(String[] args) throws Exception {
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");
MessageConsumer consumer = new DefaultMessageConsumer(session);
rollback(consumer);
// commit(consumer);
connector.close();
}
use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory 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);
}
use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class TestDownload method main.
public static void main(String[] args) throws Exception {
String serviceName = "TestDownloadServlet";
String fileName = "upload-flashmail-2.4.exe";
JSONObject j = new JSONObject();
j.put(FileReceiveUtil.FILE_NAME, fileName);
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());
final FileReceiveUtil fileReceiveUtil = new FileReceiveUtil("download-");
session.listen(serviceName, new OnFuture() {
@Override
public void onResponse(SocketSession session, Future future) {
try {
fileReceiveUtil.accept(session, (ParamedProtobaseFuture) future, false);
} catch (Exception e) {
DebugUtil.debug(e);
}
}
});
long old = System.currentTimeMillis();
session.write(serviceName, j.toJSONString());
System.out.println("Time:" + (System.currentTimeMillis() - old));
ThreadUtil.sleep(5000);
CloseUtil.close(connector);
}
Aggregations