use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class TestListenerPower 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);
long old = System.currentTimeMillis();
OnMessage onMessage = new OnMessage() {
@Override
public void onReceive(Message message) {
System.out.println(message);
}
};
for (int i = 0; i < 10000; i++) {
consumer.receive(onMessage);
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
connector.close();
}
use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class TestTellerByteMessage method main.
public static void main(String[] args) throws Exception {
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(8300));
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");
MessageProducer producer = new DefaultMessageProducer(session);
TextByteMessage message = new TextByteMessage("msgId", "uuid", "============", "你好!".getBytes(session.getContext().getEncoding()));
long old = System.currentTimeMillis();
for (int i = 0; i < 5; i++) {
producer.offer(message);
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
connector.close();
}
use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class BalanceServerBootStrap method getBalanceReverseChannelContext.
private SocketChannelContext getBalanceReverseChannelContext(BalanceContext balanceContext, ServerConfiguration configuration, ProtocolFactory protocolFactory) {
SocketChannelContext context = new NioSocketChannelContext(configuration);
// SocketChannelContext context = new AioSocketChannelContext(configuration);
context.setIoEventHandleAdaptor(balanceContext.getBalanceReverseAcceptorHandler());
context.addSessionEventListener(balanceContext.getBalanceReverseAcceptorSEListener());
context.setProtocolFactory(protocolFactory);
context.setBeatFutureFactory(balanceReverseBeatFutureFactory);
if (balanceReverseSessionEventListeners != null) {
addSessionEventListener2Context(context, balanceReverseSessionEventListeners);
}
if (balanceReverseSessionIdleEventListeners != null) {
addSessionIdleEventListener2Context(context, balanceReverseSessionIdleEventListeners);
}
return context;
}
use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class BalanceServerBootStrap method getBalanceChannelContext.
private SocketChannelContext getBalanceChannelContext(BalanceContext balanceContext, ServerConfiguration configuration, ProtocolFactory protocolFactory) {
SocketChannelContext context = new NioSocketChannelContext(configuration);
// SocketChannelContext context = new AioSocketChannelContext(configuration);
context.setIoEventHandleAdaptor(balanceContext.getBalanceFacadeAcceptorHandler());
context.addSessionEventListener(balanceContext.getBalanceFacadeAcceptorSEListener());
context.setProtocolFactory(protocolFactory);
context.setBeatFutureFactory(balanceBeatFutureFactory);
if (balanceSessionEventListeners != null) {
addSessionEventListener2Context(context, balanceSessionEventListeners);
}
if (balanceSessionIdleEventListeners != null) {
addSessionIdleEventListener2Context(context, balanceSessionIdleEventListeners);
}
if (sslContext != null) {
context.setSslContext(sslContext);
}
return context;
}
use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class TestProtobufClient method main.
public static void main(String[] args) throws Exception {
ProtobufUtil protobufUtil = new ProtobufUtil();
protobufUtil.regist(SearchRequest.getDefaultInstance());
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
ProtobaseFuture f = (ProtobaseFuture) future;
SearchRequest res = (SearchRequest) protobufUtil.getMessage(f);
System.out.println();
System.out.println("________" + res);
System.out.println();
}
};
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
// context.addSessionEventListener(new SessionActiveSEListener());
// context.setBeatFutureFactory(new FLBeatFutureFactory());
context.setProtocolFactory(new ProtobaseProtocolFactory());
SocketSession session = connector.connect();
ProtobaseFuture f = new ProtobaseFutureImpl(context);
ByteString byteString = ByteString.copyFrom("222".getBytes());
SearchRequest request = SearchRequest.newBuilder().setCorpus(Corpus.IMAGES).setPageNumber(100).setQuery("test").setQueryBytes(byteString).setResultPerPage(-1).build();
protobufUtil.writeProtobuf(request, f);
session.flush(f);
ThreadUtil.sleep(100);
CloseUtil.close(connector);
}
Aggregations