use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture in project baseio by generallycloud.
the class TestListenSimpleServlet method doAccept.
@Override
protected void doAccept(SocketSession session, ParamedProtobaseFuture future) throws Exception {
String test = future.getReadText();
if (StringUtil.isNullOrBlank(test)) {
test = "test";
}
future.write(test);
future.write("$");
session.flush(future);
for (int i = 0; i < 5; i++) {
ProtobaseFuture f = new ProtobaseFutureImpl(session.getContext(), future.getFutureId(), future.getFutureName());
f.write(test);
f.write("$");
session.flush(f);
}
}
use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture 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