Search in sources :

Example 1 with Logger

use of com.generallycloud.baseio.log.Logger in project baseio by generallycloud.

the class ApplicationBootstrapEngine method bootstrap.

@Override
public void bootstrap(String rootPath, boolean deployModel) throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    Properties serverProperties = FileUtil.readPropertiesByCls("server.properties");
    ServerConfiguration sc = new ServerConfiguration();
    new PropertiesSCLoader("SERVER").loadConfiguration(sc, serverProperties);
    ApplicationContext applicationContext = new ApplicationContext(rootPath);
    applicationContext.setDeployModel(deployModel);
    SocketChannelContext channelContext = new NioSocketChannelContext(sc);
    // SocketChannelContext channelContext = new AioSocketChannelContext(sc);
    SocketChannelAcceptor acceptor = new SocketChannelAcceptor(channelContext);
    try {
        Properties intfProperties = FileUtil.readPropertiesByCls("intf.properties");
        applicationContext.setBlackIPs(loadBlackIPs());
        applicationContext.setChannelContext(channelContext);
        ApplicationConfigurationLoader acLoader = loadConfigurationLoader(intfProperties.getProperty("intf.ApplicationConfigurationLoader"));
        ApplicationExtLoader applicationExtLoader = loadApplicationExtLoader(intfProperties.getProperty("intf.ApplicationExtLoader"));
        ApplicationContextEnricher enricher = loadApplicationContextEnricher(intfProperties.getProperty("intf.ApplicationContextEnricher"));
        applicationContext.setApplicationExtLoader(applicationExtLoader);
        applicationContext.setApplicationConfigurationLoader(acLoader);
        enricher.enrich(applicationContext);
        channelContext.setIoEventHandleAdaptor(new ApplicationIoEventHandle(applicationContext));
        if (sc.isSERVER_ENABLE_SSL()) {
            if (!StringUtil.isNullOrBlank(sc.getSERVER_CERT_KEY())) {
                File certificate = FileUtil.readFileByCls(sc.getSERVER_CERT_CRT(), classLoader);
                File privateKey = FileUtil.readFileByCls(sc.getSERVER_CERT_KEY(), classLoader);
                SslContext sslContext = SSLUtil.initServer(privateKey, certificate);
                channelContext.setSslContext(sslContext);
            } else {
                String keystoreInfo = sc.getSERVER_SSL_KEYSTORE();
                if (StringUtil.isNullOrBlank(keystoreInfo)) {
                    throw new IllegalArgumentException("ssl enabled,but no config for");
                }
                String[] params = keystoreInfo.split(";");
                if (params.length != 4) {
                    throw new IllegalArgumentException("SERVER_SSL_KEYSTORE config error");
                }
                File storeFile = FileUtil.readFileByCls(params[0], classLoader);
                SslContext sslContext = SSLUtil.initServer(storeFile, params[1], params[2], params[3]);
                channelContext.setSslContext(sslContext);
            }
        }
        sc.setSERVER_PORT(getServerPort(sc.getSERVER_PORT(), sc.isSERVER_ENABLE_SSL()));
        acceptor.bind();
    } catch (Throwable e) {
        Logger logger = LoggerFactory.getLogger(getClass());
        logger.error(e.getMessage(), e);
        CloseUtil.unbind(acceptor);
    }
}
Also used : PropertiesSCLoader(com.generallycloud.baseio.configuration.PropertiesSCLoader) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) ApplicationIoEventHandle(com.generallycloud.baseio.container.ApplicationIoEventHandle) Properties(com.generallycloud.baseio.common.Properties) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) Logger(com.generallycloud.baseio.log.Logger) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ApplicationContext(com.generallycloud.baseio.container.ApplicationContext) ApplicationExtLoader(com.generallycloud.baseio.container.ApplicationExtLoader) ApplicationContextEnricher(com.generallycloud.baseio.container.ApplicationContextEnricher) ApplicationConfigurationLoader(com.generallycloud.baseio.container.configuration.ApplicationConfigurationLoader) File(java.io.File) SocketChannelAcceptor(com.generallycloud.baseio.acceptor.SocketChannelAcceptor) SslContext(com.generallycloud.baseio.component.ssl.SslContext)

Example 2 with Logger

use of com.generallycloud.baseio.log.Logger 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);
}
Also used : FixedLengthFutureImpl(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) Logger(com.generallycloud.baseio.log.Logger) CountDownLatch(java.util.concurrent.CountDownLatch) AioSocketChannelContext(com.generallycloud.baseio.component.AioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) BigDecimal(java.math.BigDecimal) AioSocketChannelContext(com.generallycloud.baseio.component.AioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) FixedLengthFuture(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SocketSession(com.generallycloud.baseio.component.SocketSession) FixedLengthProtocolFactory(com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) Future(com.generallycloud.baseio.protocol.Future) FixedLengthFuture(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)

Example 3 with Logger

use of com.generallycloud.baseio.log.Logger in project baseio by generallycloud.

the class TestLog method testSl4J.

static void testSl4J() {
    Logger logger = LoggerFactory.getLogger(TestLog.class);
    for (int i = 0; i < 1000000; i++) {
        logger.info("logback info 成功了..............................................");
        logger.error("logback error 成功了..............................................");
        logger.debug("logback debug 成功了..............................................");
    }
}
Also used : Logger(com.generallycloud.baseio.log.Logger)

Example 4 with Logger

use of com.generallycloud.baseio.log.Logger in project baseio by generallycloud.

the class TestLogger method main.

public static void main(String[] args) {
    LoggerFactory.setEnableSLF4JLogger(false);
    DebugUtil.setEnableDebug(true);
    Logger logger = LoggerFactory.getLogger(TestLogger.class);
    for (int i = 0; i < 10; i++) {
        logger.debug("debug test..........");
        logger.info("info test..............");
        logger.error("error test......");
    }
}
Also used : Logger(com.generallycloud.baseio.log.Logger)

Example 5 with Logger

use of com.generallycloud.baseio.log.Logger in project baseio by generallycloud.

the class TestLog method testInternalLogger.

static void testInternalLogger() throws IOException {
    LoggerFactory.setEnableSLF4JLogger(false);
    LoggerFactory.setInternalLogFile(new File("D://test/main.log"));
    LoggerFactory.setEnableDebug(true);
    Logger logger = LoggerFactory.getLogger(TestLog.class);
    for (int i = 0; i < 1000; i++) {
        logger.info("logback info 成功了..............................................");
        logger.error("logback error 成功了..............................................");
        logger.debug("logback debug 成功了..............................................");
    }
}
Also used : Logger(com.generallycloud.baseio.log.Logger) File(java.io.File)

Aggregations

Logger (com.generallycloud.baseio.log.Logger)5 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)2 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)2 File (java.io.File)2 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)1 FixedLengthProtocolFactory (com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory)1 FixedLengthFuture (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)1 FixedLengthFutureImpl (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl)1 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)1 Properties (com.generallycloud.baseio.common.Properties)1 AioSocketChannelContext (com.generallycloud.baseio.component.AioSocketChannelContext)1 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)1 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)1 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)1 SocketSession (com.generallycloud.baseio.component.SocketSession)1 SslContext (com.generallycloud.baseio.component.ssl.SslContext)1 PropertiesSCLoader (com.generallycloud.baseio.configuration.PropertiesSCLoader)1 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)1 ApplicationContext (com.generallycloud.baseio.container.ApplicationContext)1 ApplicationContextEnricher (com.generallycloud.baseio.container.ApplicationContextEnricher)1