use of com.generallycloud.baseio.configuration.ServerConfiguration 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.configuration.ServerConfiguration 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.configuration.ServerConfiguration in project baseio by generallycloud.
the class TestBytebufAllocator method test.
static void test() throws Exception {
ServerConfiguration configuration = new ServerConfiguration();
configuration.setSERVER_MEMORY_POOL_CAPACITY(10);
configuration.setSERVER_MEMORY_POOL_UNIT(1);
SocketChannelContext context = new NioSocketChannelContext(configuration);
PooledByteBufAllocatorManager allocator = new PooledByteBufAllocatorManager(context);
allocator.start();
ByteBufAllocator allocator2 = allocator.getNextBufAllocator();
ByteBuf buf = allocator2.allocate(15);
System.out.println(buf);
}
use of com.generallycloud.baseio.configuration.ServerConfiguration 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();
}
use of com.generallycloud.baseio.configuration.ServerConfiguration in project baseio by generallycloud.
the class TestLoadClient method main.
public static void main(String[] args) throws Exception {
final Logger logger = LoggerFactory.getLogger(TestLoadClient.class);
final CountDownLatch latch = new CountDownLatch(time);
final AtomicInteger res = new AtomicInteger();
final AtomicInteger req = new AtomicInteger();
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
// latch.countDown();
// long count = latch.getCount();
// if (count % 10 == 0) {
// if (count < 50) {
// logger.info("************************================" + count);
// }
// }
// logger.info("res==========={}",res.getAndIncrement());
}
};
ServerConfiguration configuration = new ServerConfiguration(8300);
// SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelContext context = new AioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
connector.getContext().setProtocolFactory(new FixedLengthProtocolFactory());
connector.getContext().getServerConfiguration().setSERVER_CORE_SIZE(1);
SocketSession session = connector.connect();
System.out.println("################## Test start ####################");
long old = System.currentTimeMillis();
for (int i = 0; i < time; i++) {
FixedLengthFuture future = new FixedLengthFutureImpl(session.getContext());
future.write("hello server!");
session.flush(future);
}
latch.await();
long spend = (System.currentTimeMillis() - old);
System.out.println("## Execute Time:" + time);
System.out.println("## OP/S:" + new BigDecimal(time * 1000).divide(new BigDecimal(spend), 2, BigDecimal.ROUND_HALF_UP));
System.out.println("## Expend Time:" + spend);
CloseUtil.close(connector);
}
Aggregations