Example usage for io.netty.util.internal.logging InternalLoggerFactory setDefaultFactory

List of usage examples for io.netty.util.internal.logging InternalLoggerFactory setDefaultFactory

Introduction

In this page you can find the example usage for io.netty.util.internal.logging InternalLoggerFactory setDefaultFactory.

Prototype

public static void setDefaultFactory(InternalLoggerFactory defaultFactory) 

Source Link

Document

Changes the default factory.

Usage

From source file:cc.agentx.client.net.nio.XClient.java

License:Apache License

public void start() {
    Configuration config = Configuration.INSTANCE;
    InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    try {//from   w  ww . j  a  v a 2 s  .  c o  m
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel socketChannel) throws Exception {
                        socketChannel.pipeline().addLast("logging", new LoggingHandler(LogLevel.DEBUG))
                                .addLast(new SocksInitRequestDecoder()).addLast(new SocksMessageEncoder())
                                .addLast(new Socks5Handler()).addLast(Status.TRAFFIC_HANDLER);
                    }
                });
        log.info("\tStartup {}-{}-client [{}{}]", Constants.APP_NAME, Constants.APP_VERSION, config.getMode(),
                config.getMode().equals("socks5") ? "" : ":" + config.getProtocol());
        ChannelFuture future = bootstrap.bind(config.getLocalHost(), config.getLocalPort()).sync();
        future.addListener(
                future1 -> log.info("\tListening at {}:{}...", config.getLocalHost(), config.getLocalPort()));
        future.channel().closeFuture().sync();
    } catch (Exception e) {
        log.error("\tSocket bind failure ({})", e.getMessage());
    } finally {
        log.info("\tShutting down");
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:cc.agentx.server.net.nio.XServer.java

License:Apache License

public void start() {
    Configuration config = Configuration.INSTANCE;
    InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//from   ww w .  j a v  a2 s  .  c  om
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    protected void initChannel(SocketChannel socketChannel) throws Exception {
                        socketChannel.pipeline().addLast("logging", new LoggingHandler(LogLevel.DEBUG))
                                .addLast(new XConnectHandler());
                        if (config.getReadLimit() != 0 || config.getWriteLimit() != 0) {
                            socketChannel.pipeline().addLast(
                                    new GlobalTrafficShapingHandler(Executors.newScheduledThreadPool(1),
                                            config.getWriteLimit(), config.getReadLimit()));
                        }
                    }
                });
        log.info("\tStartup {}-{}-server [{}]", Constants.APP_NAME, Constants.APP_VERSION,
                config.getProtocol());
        ChannelFuture future = bootstrap.bind(config.getHost(), config.getPort()).sync();
        future.addListener(future1 -> log.info("\tListening at {}:{}...", config.getHost(), config.getPort()));
        future.channel().closeFuture().sync();
    } catch (Exception e) {
        log.error("\tSocket bind failure ({})", e.getMessage());
    } finally {
        log.info("\tShutting down and recycling...");
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
        Configuration.shutdownRelays();
    }
    System.exit(0);
}

From source file:cn.wantedonline.puppy.Bootstrap.java

License:Apache License

private void initEnv() {
    long begin = System.currentTimeMillis();
    //?Netty/*  w w  w .  java  2s  .  c o m*/
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    //????
    try {
        statisticManager.readStatisticData();
    } catch (Throwable t) {//???????
        log.error("read statistic data error, error info{}", t);
    }
    System.out.println("------------------------------> "
            + (System.currentTimeMillis() - begin) + "MS");
}

From source file:com.alibaba.dubbo.remoting.transport.netty.logging.NettyHelper.java

License:Apache License

public static void setNettyLoggerFactory() {
    InternalLoggerFactory factory = InternalLoggerFactory.getDefaultFactory();
    if (factory == null || !(factory instanceof DubboLoggerFactory)) {
        InternalLoggerFactory.setDefaultFactory(new DubboLoggerFactory());
    }/*  w  w  w  . ja  v  a  2 s.  c o m*/
}

From source file:com.chiorichan.Loader.java

License:Mozilla Public License

@Override
public void onRunlevelChange(RunLevel level) throws ApplicationException {
    switch (level) {
    case SHUTDOWN: {
        Log.get().info("Shutting Down Session Manager...");
        if (AppManager.manager(SessionManager.class).isInitalized())
            SessionManager.instance().shutdown();

        Log.get().info("Shutting Down Network Manager...");
        NetworkManager.shutdown();//w ww.  j ava2 s.  c  o  m

        Log.get().info("Shutting Down Site Manager...");
        if (AppManager.manager(SiteManager.class).isInitalized())
            SiteManager.instance().unloadSites();

        break;
    }
    case INITIALIZATION: {
        InternalLoggerFactory.setDefaultFactory(new DefaultLogFactory());
        break;
    }
    case INITIALIZED:
        break;
    case POSTSTARTUP: {
        Log.get().info("Initalizing the Site Subsystem...");
        AppManager.manager(SiteManager.class).init();

        Log.get().info("Initalizing the Session Subsystem...");
        AppManager.manager(SessionManager.class).init();

        Log.get().info("Initalizing the File Watcher Subsystem...");
        AppManager.manager(ServerFileWatcher.class).init();

        break;
    }
    case RELOAD: {
        // TODO: Reload seems to be broken. This needs some serious reworking.

        Log.get().info("Reinitalizing the Session Manager...");
        SessionManager.instance().reload();

        Log.get().info("Reinitalizing the Site Manager...");
        SiteManager.instance().reload();
        break;
    }
    case RUNNING: {
        if (AppConfig.getApplicationJar() != null) {
            AppManager.manager(AutoUpdater.class).init(
                    new DownloadUpdaterService(AppConfig.get().getString("auto-updater.host")),
                    AppConfig.get().getString("auto-updater.preferred-channel"));
            AutoUpdater updater = AutoUpdater.instance();

            updater.setEnabled(AppConfig.get().getBoolean("auto-updater.enabled"));
            updater.setSuggestChannels(AppConfig.get().getBoolean("auto-updater.suggest-channels"));
            updater.getOnBroken().addAll(AppConfig.get().getStringList("auto-updater.on-broken"));
            updater.getOnUpdate().addAll(AppConfig.get().getStringList("auto-updater.on-update"));

            updater.check();
        }
        break;
    }
    case STARTUP: {
        if (!options().has("tcp-disable") && AppConfig.get().getBoolean("server.enableTcpServer", true))
            NetworkManager.startTcpServer();
        else
            Log.get().warning(
                    "The integrated tcp server has been disabled per the configuration. Change server.enableTcpServer to true to reenable it.");

        if (!options().has("web-disable") && AppConfig.get().getBoolean("server.enableWebServer", true)) {
            NetworkManager.startHttpServer();
            NetworkManager.startHttpsServer();
        } else
            Log.get().warning(
                    "The integrated web server has been disabled per the configuration. Change server.enableWebServer to true to reenable it.");

        if (!options().has("query-disable") && AppConfig.get().getBoolean("server.queryEnabled", true))
            NetworkManager.startQueryServer();

        break;
    }
    case CRASHED:
        break;
    case DISPOSED:
        break;
    default:
        break;
    }
}

From source file:com.heliosapm.tsdblite.TSDBLite.java

License:Apache License

/**
 * Main entry point/*from   ww  w.ja va2  s  . c  o m*/
 * @param args None for now
 */
public static void main(String[] args) {
    log.info("TSDBLite booting....");
    ExtendedThreadManager.install();
    InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
    final String jmxmpIface = ConfigurationHelper.getSystemThenEnvProperty(Constants.CONF_JMXMP_IFACE,
            Constants.DEFAULT_JMXMP_IFACE);
    final int jmxmpPort = ConfigurationHelper.getIntSystemThenEnvProperty(Constants.CONF_JMXMP_PORT,
            Constants.DEFAULT_JMXMP_PORT);
    JMXHelper.fireUpJMXMPServer(jmxmpIface, jmxmpPort, JMXHelper.getHeliosMBeanServer());
    server = Server.getInstance();
    final Thread mainThread = Thread.currentThread();
    StdInCommandHandler.getInstance().registerCommand("stop", new Runnable() {
        @Override
        public void run() {
            if (server != null) {
                log.info("Stopping TSDBLite Server.....");
                server.stop();
                log.info("TSDBLite Server Stopped. Bye.");
                mainThread.interrupt();
            }
        }
    });
    try {
        Thread.currentThread().join();
    } catch (Exception x) {
        /* No Op */}
}

From source file:com.tesora.dve.db.mysql.portal.MySqlPortal.java

License:Open Source License

public MySqlPortal(Properties props) throws PEException {
    // This is the port the Portal is going to listen on -
    // default to Mysql's port
    int port = Singletons.require(HostService.class).getPortalPort(props);
    Singletons.replace(MySqlPortalService.class, this);

    InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());

    int max_concurrent = KnownVariables.MAX_CONCURRENT.getValue(null).intValue();

    //TODO: parse/plan is on this pool, which is probably ok, especially with blocking calls to catalog.  Check for responses that can be done by backend netty threads and avoid two context shifts.

    clientExecutorService = new PEThreadPoolExecutor(max_concurrent, max_concurrent, 30L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(), //The thread count limits concurrency here.  Using a bounded queue here would block netty threads (very bad), so this pool could be overrun by 'bad' clients that pipeline. -sgossard
            new PEDefaultThreadFactory("msp-client"));
    clientExecutorService.allowCoreThreadTimeOut(true);

    bossGroup = new NioEventLoopGroup(1, new PEDefaultThreadFactory("msp-boss"));

    //fixes the number of Netty NIO threads to the number of available CPUs.
    workerGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(),
            new PEDefaultThreadFactory("netty-worker"));

    ServerBootstrap b = new ServerBootstrap();
    try {/*from   w w  w  .  j a  va 2s .  c  o m*/
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {

                    @Override
                    protected void initChannel(SocketChannel ch) throws Exception {
                        if (PACKET_LOGGER)
                            ch.pipeline().addFirst(new LoggingHandler(LogLevel.INFO));
                        ch.pipeline()
                                .addLast(MSPProtocolDecoder.class.getSimpleName(),
                                        new MSPProtocolDecoder(
                                                MSPProtocolDecoder.MyDecoderState.READ_CLIENT_AUTH))
                                .addLast(new MSPAuthenticateHandlerV10())
                                .addLast(MSPCommandHandler.class.getSimpleName(),
                                        new MSPCommandHandler(clientExecutorService))
                                .addLast(ConnectionHandlerAdapter.getInstance());
                    }
                })

                .childOption(ChannelOption.ALLOCATOR,
                        USE_POOLED_BUFFERS ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT)
                .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true)
                .bind(port).sync();

        logger.info("DVE Server bound to port " + port);

    } catch (Exception e) {
        throw new PEException("Failed to bind DVE server to port " + port + " - " + e.getMessage(), e);
    }
}

From source file:com.tesora.dve.standalone.LoadBalancer.java

License:Open Source License

public static void main(String[] args) throws Exception {

    Properties props = PEFileUtils.loadPropertiesFile(LoadBalancer.class, PEConstants.CONFIG_FILE_NAME);

    if (args.length == 2 && "-port".equalsIgnoreCase(args[0]))
        props.setProperty(PORT_PROPERTY, args[1]);
    else if (args.length > 0)
        throw new Exception("Usage: LoadBalancer [-port <port>]");

    InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
    LoadBalancer loadBalancer = new LoadBalancer(props);
    loadBalancer.run();/*  ww w .ja  v a 2  s  . c o  m*/
}

From source file:com.uber.tchannel.BaseTest.java

License:Open Source License

public static void setupLogger() {

    Properties properties = new Properties();
    properties.setProperty("log4j.rootLogger", "WARN, A1");
    properties.setProperty("log4j.appender.A1", "org.apache.log4j.ConsoleAppender");
    properties.setProperty("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
    properties.setProperty("log4j.appender.A1.layout.ConversionPattern", "%-4r [%t] %-5p %c %x - %m%n");
    PropertyConfigurator.configure(properties);

    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
}

From source file:com.uber.tchannel.benchmarks.LargePayloadBenchmark.java

License:Open Source License

@Setup(Level.Trial)
public void setup() throws Exception {
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    BasicConfigurator.configure();/*w ww .  ja va  2 s  .  co  m*/
    LogManager.getRootLogger().setLevel(org.apache.log4j.Level.INFO);

    this.host = InetAddress.getByName("127.0.0.1");
    this.channel = new TChannel.Builder("ping-server").setServerHost(host).setBossGroup(bossGroup)
            .setChildGroup(childGroup).build();
    channel.makeSubChannel("ping-server").register("ping", new PingDefaultRequestHandler());
    channel.listen();
    this.port = this.channel.getListeningPort();

    this.client = new TChannel.Builder("ping-client")
            // .setResetOnTimeoutLimit(100)
            .setClientMaxPendingRequests(200000).setBossGroup(bossGroup).setChildGroup(childGroup).build();
    this.subClient = this.client.makeSubChannel("ping-server");
    this.client.listen();

    byte[] buf = new byte[60 * 1024];
    new Random().nextBytes(buf);
    payload = Unpooled.wrappedBuffer(buf);
}