use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class TestBalanceBroadcast method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
ProtobaseFuture f = (ProtobaseFuture) future;
if (BalanceContext.BALANCE_CHANNEL_LOST.equals(f.getFutureName())) {
System.out.println("客户端已下线:" + f.getReadText());
} else {
System.out.println("~~~~~~收到报文:" + future.toString());
String res = "(***" + f.getReadText() + "***)";
System.out.println("~~~~~~处理报文:" + res);
f.write(res);
session.flush(future);
}
}
};
ServerConfiguration configuration = new ServerConfiguration(8800);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
SocketSession session = connector.connect();
for (; session.isOpened(); ) {
ProtobaseFuture future = new ProtobaseFutureImpl(context, "broadcast");
future.setBroadcast(true);
String msg = "broadcast msg___S:" + System.currentTimeMillis();
future.write(msg);
future.writeBinary("__^^^binary^^^__".getBytes());
session.flush(future);
ThreadUtil.sleep(10);
}
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class TestBalanceClient method main.
public static void main(String[] args) throws Exception {
final AtomicInteger res = new AtomicInteger();
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
ProtobaseFuture f = (ProtobaseFuture) future;
if (f.hasReadBinary()) {
System.out.println(f.getReadText() + new String(f.getReadBinary()) + "______R:" + System.currentTimeMillis());
} else {
System.out.println(f.getReadText() + "______R:" + System.currentTimeMillis());
}
res.incrementAndGet();
}
};
ServerConfiguration configuration = new ServerConfiguration(8600);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.setSocketSessionFactory(new BalanceClientSocketSessionFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
BalanceClientSocketSession session = (BalanceClientSocketSession) connector.connect();
for (int i = 0; i < 100; i++) {
int fid = Math.abs(new Random().nextInt());
ProtobaseFuture future = new ProtobaseFutureImpl(context, "future-name");
future.write("你好!");
future.setHashCode(fid);
session.flush(future);
}
ThreadUtil.sleep(300);
System.out.println("==========" + res.get());
ThreadUtil.sleep(500000000);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class TestBalanceLoad method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
ProtobaseFuture f = (ProtobaseFuture) future;
if (BalanceContext.BALANCE_CHANNEL_LOST.equals(f.getFutureName())) {
System.out.println("客户端已下线:" + f.getReadText());
} else {
System.out.println("收到报文:" + future.toString());
String res = "_____________" + f.getReadText();
System.out.println("处理报文:" + res);
f.write(res);
session.flush(future);
}
}
};
ServerConfiguration configuration = new ServerConfiguration(8800);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
connector.connect();
System.in.read();
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class TestBalanceMain method main.
public static void main(String[] args) throws IOException {
BalanceServerBootStrap f = new BalanceServerBootStrap();
f.setBalanceProtocolFactory(new ProtobaseProtocolFactory());
f.setBalanceReverseProtocolFactory(new ProtobaseProtocolFactory());
f.setBalanceProtocolFactory(new ProtobaseProtocolFactory());
f.setBalanceReverseProtocolFactory(new ProtobaseProtocolFactory());
ServerConfiguration fc = new ServerConfiguration();
fc.setSERVER_PORT(8600);
ServerConfiguration frc = new ServerConfiguration();
frc.setSERVER_PORT(8800);
f.setFacadeExceptionCaughtHandle(new LoggerExceptionCaughtHandle());
f.setReverseExceptionCaughtHandle(new LoggerExceptionCaughtHandle());
f.setBalanceServerConfiguration(fc);
f.setBalanceReverseServerConfiguration(frc);
f.setFacadeInterceptor(new FacadeInterceptorImpl(500, 50000));
f.setBalanceRouter(new HashedBalanceRouter(10240));
// f.setBalanceRouter(new SimpleNextRouter());
f.startup();
}
use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.
the class TestTellerPower 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");
MessageProducer producer = new DefaultMessageProducer(session);
TextMessage message = new TextMessage("msgId", "qName", "你好!");
long old = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
producer.offer(message);
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
connector.close();
}
Aggregations