use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl 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.future.ProtobaseFutureImpl in project baseio by generallycloud.
the class Consumer method push.
// FIXME push 失败时对message进行回收,并移除Consumer
public void push(Message message) throws IOException {
this.message = message;
TransactionSection section = attachment.getTransactionSection();
if (section != null) {
section.offerMessage(message);
}
int msgType = message.getMsgType();
String content = message.toString();
SocketSession session = this.session;
ProtobaseFuture f = new ProtobaseFutureImpl(session.getContext(), future.getFutureId(), future.getFutureName());
f.write(content);
if (msgType == Message.TYPE_TEXT || msgType == Message.TYPE_MAP) {
session.flush(f);
} else if (msgType == Message.TYPE_TEXT_BYTE || msgType == Message.TYPE_MAP_BYTE) {
BytedMessage byteMessage = (BytedMessage) message;
byte[] bytes = byteMessage.getByteArray();
f.writeBinary(bytes);
session.flush(f);
}
}
use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl 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.ProtobaseFutureImpl in project baseio by generallycloud.
the class FileSendUtil method sendFile.
public void sendFile(SocketSession session, String serviceName, File file, int cacheSize) throws Exception {
FileInputStream inputStream = new FileInputStream(file);
int available = inputStream.available();
int time = (available + cacheSize) / cacheSize - 1;
byte[] cache = new byte[cacheSize];
JSONObject json = new JSONObject();
json.put(FileReceiveUtil.FILE_NAME, file.getName());
json.put(FileReceiveUtil.IS_END, false);
String jsonString = json.toJSONString();
for (int i = 0; i < time; i++) {
FileUtil.readInputStream(inputStream, cache);
ProtobaseFuture f = new ProtobaseFutureImpl(session.getContext(), serviceName);
f.write(jsonString);
f.writeBinary(cache);
session.flush(f);
}
int r = FileUtil.readInputStream(inputStream, cache);
json.put(FileReceiveUtil.IS_END, true);
ProtobaseFuture f = new ProtobaseFutureImpl(session.getContext(), serviceName);
f.write(json.toJSONString());
f.writeBinary(cache, 0, r);
session.flush(f);
CloseUtil.close(inputStream);
}
use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl 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);
}
Aggregations