use of com.generallycloud.baseio.component.LoggerSocketSEListener in project baseio by generallycloud.
the class TestListener method main.
public static void main(String[] args) throws Exception {
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 ParamedProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
MessageConsumer consumer = new DefaultMessageConsumer(session);
long old = System.currentTimeMillis();
consumer.receive(new OnMessage() {
@Override
public void onReceive(Message message) {
System.out.println(message);
}
});
System.out.println("Time:" + (System.currentTimeMillis() - old));
ThreadUtil.sleep(1500000);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.LoggerSocketSEListener in project baseio by generallycloud.
the class TestListenerByteMessage 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");
MessageConsumer consumer = new DefaultMessageConsumer(session);
final long old = System.currentTimeMillis();
consumer.receive(new OnMessage() {
@Override
public void onReceive(Message message) {
System.out.println(message);
if (message.getMsgType() == Message.TYPE_TEXT_BYTE) {
TextByteMessage _Message = (TextByteMessage) message;
System.out.println(new String(_Message.getByteArray(), Encoding.UTF8));
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
}
});
ThreadUtil.sleep(30000000);
connector.close();
}
use of com.generallycloud.baseio.component.LoggerSocketSEListener in project baseio by generallycloud.
the class TestListenerCallBack 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);
consumer.receive(new OnMessage() {
@Override
public void onReceive(Message message) {
System.out.println(message);
}
});
ThreadUtil.sleep(1000);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.LoggerSocketSEListener 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.LoggerSocketSEListener 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();
}
Aggregations