use of com.generallycloud.baseio.container.SimpleIoEventHandle 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.container.SimpleIoEventHandle 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.container.SimpleIoEventHandle in project baseio by generallycloud.
the class TestGetPhoneNO method main.
public static void main(String[] args) throws Exception {
String serviceKey = "TestGetPhoneNOServlet";
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());
ProtobaseFuture future = session.request(serviceKey, null);
System.out.println(future.getReadText());
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.container.SimpleIoEventHandle in project baseio by generallycloud.
the class TestSessionDisconnect method main.
public static void main(String[] args) throws Exception {
String serviceName = "TestSessionDisconnectServlet";
String param = "ttt";
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");
ProtobaseFuture future = session.request(serviceName, param);
System.out.println(future.getReadText());
session.listen(serviceName, new OnFuture() {
@Override
public void onResponse(SocketSession session, Future future) {
ProtobaseFuture f = (ProtobaseFuture) future;
System.out.println(f.getReadText());
}
});
session.write(serviceName, param);
ThreadUtil.sleep(9999);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.container.SimpleIoEventHandle in project baseio by generallycloud.
the class ConnectExecutable method exec.
@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
CmdResponse response = new CmdResponse();
SocketChannelConnector connector = getClientConnector(context);
if (connector != null) {
response.setResponse("已登录。");
return response;
}
String username = params.get("-un");
String password = params.get("-p");
String host = params.get("-host");
String port = params.get("-port");
if (StringUtil.isNullOrBlank(username) || StringUtil.isNullOrBlank(password) || StringUtil.isNullOrBlank(host) || StringUtil.isNullOrBlank(port)) {
response.setResponse("参数不正确!\n" + "example:\n" + "connect -host:localhost -port:8300 -un:admin -p:admin100");
return response;
}
try {
NioSocketChannelContext baseContext = new NioSocketChannelContext(new ServerConfiguration(Integer.parseInt(port)));
connector = new SocketChannelConnector(baseContext);
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
baseContext.setIoEventHandleAdaptor(eventHandle);
baseContext.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
// FIXME denglu cuowu
session.login(username, password);
MessageBrowser browser = new DefaultMessageBrowser(session);
response.setResponse("连接成功!");
setClientConnector(context, connector);
setMessageBrowser(context, browser);
} catch (Exception e) {
setClientConnector(context, null);
setMessageBrowser(context, null);
response.setResponse(e.getMessage());
// debug
logger.debug(e);
}
return response;
}
Aggregations