List of usage examples for io.netty.util ResourceLeakDetector setLevel
public static void setLevel(Level level)
From source file:com.vmware.xenon.common.TestEventStreams.java
License:Open Source License
@Test public void testWithLoad() throws Throwable { Level level = ResourceLeakDetector.getLevel(); ResourceLeakDetector.setLevel(Level.PARANOID); try {//from w ww . j av a2 s . c om doTestWithLoad(); } finally { ResourceLeakDetector.setLevel(level); } }
From source file:de.jackwhite20.apex.Apex.java
License:Open Source License
public void start(Mode mode) { commandManager.addCommand(new HelpCommand("help", "List of available commands", "h")); commandManager.addCommand(new EndCommand("end", "Stops Apex", "stop", "exit")); commandManager.addCommand(new DebugCommand("debug", "Turns the debug mode on/off", "d")); commandManager.addCommand(new StatsCommand("stats", "Shows live stats", "s", "info")); Header generalHeader = copeConfig.getHeader("general"); Key serverKey = generalHeader.getKey("server"); Key balanceKey = generalHeader.getKey("balance"); Key bossKey = generalHeader.getKey("boss"); Key workerKey = generalHeader.getKey("worker"); Key timeoutKey = generalHeader.getKey("timeout"); Key backlogKey = generalHeader.getKey("backlog"); Key probeKey = generalHeader.getKey("probe"); Key debugKey = generalHeader.getKey("debug"); Key statsKey = generalHeader.getKey("stats"); // Set the log level to debug or info based on the config value changeDebug((Boolean.valueOf(debugKey.next().asString())) ? Level.DEBUG : Level.INFO); List<BackendInfo> backendInfo = copeConfig.getHeader("backend").getKeys().stream().map( backend -> new BackendInfo(backend.getName(), backend.next().asString(), backend.next().asInt())) .collect(Collectors.toList()); logger.debug("Mode: {}", mode); logger.debug("Host: {}", serverKey.next().asString()); logger.debug("Port: {}", serverKey.next().asString()); logger.debug("Balance: {}", balanceKey.next().asString()); logger.debug("Backlog: {}", backlogKey.next().asInt()); logger.debug("Boss: {}", bossKey.next().asInt()); logger.debug("Worker: {}", workerKey.next().asInt()); logger.debug("Stats: {}", statsKey.next().asString()); logger.debug("Probe: {}", probeKey.next().asInt()); logger.debug("Backend: {}", backendInfo.stream().map(BackendInfo::getHost).collect(Collectors.joining(", "))); StrategyType type = StrategyType.valueOf(balanceKey.next().asString()); balancingStrategy = BalancingStrategyFactory.create(type, backendInfo); // Disable the resource leak detector ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED); if (PipelineUtils.isEpoll()) { logger.info("Using high performance epoll event notification mechanism"); } else {/*w ww . j a va 2 s . co m*/ logger.info("Using normal select/poll event notification mechanism"); } // Check boss thread config value int bossThreads = bossKey.next().asInt(); if (bossThreads < PipelineUtils.DEFAULT_THREADS_THRESHOLD) { bossThreads = PipelineUtils.DEFAULT_BOSS_THREADS; logger.warn("Boss threads needs to be greater or equal than {}. Using default value of {}", PipelineUtils.DEFAULT_THREADS_THRESHOLD, PipelineUtils.DEFAULT_BOSS_THREADS); } // Check worker thread config value int workerThreads = workerKey.next().asInt(); if (workerThreads < PipelineUtils.DEFAULT_THREADS_THRESHOLD) { workerThreads = PipelineUtils.DEFAULT_WORKER_THREADS; logger.warn("Worker threads needs to be greater or equal than {}. Using default value of {}", PipelineUtils.DEFAULT_THREADS_THRESHOLD, PipelineUtils.DEFAULT_WORKER_THREADS); } bossGroup = PipelineUtils.newEventLoopGroup(bossThreads, new ApexThreadFactory("Apex Boss Thread")); workerGroup = PipelineUtils.newEventLoopGroup(workerThreads, new ApexThreadFactory("Apex Worker Thread")); if (statsKey.next().asBoolean()) { // Only measure connections per second if stats are enabled connectionsPerSecondTask = new ConnectionsPerSecondTask(); // Load the total stats long[] totalBytes = FileUtil.loadStats(); logger.debug("Loaded total read bytes: {}", totalBytes[0]); logger.debug("Loaded total written bytes: {}", totalBytes[1]); // Traffic shaping handler with default check interval of one second trafficShapingHandler = new GlobalTrafficShapingHandler(workerGroup, 0, 0); // Set the total stats ReflectionUtil.setAtomicLong(trafficShapingHandler.trafficCounter(), "cumulativeReadBytes", totalBytes[0]); ReflectionUtil.setAtomicLong(trafficShapingHandler.trafficCounter(), "cumulativeWrittenBytes", totalBytes[1]); logger.debug("Traffic stats collect handler initialized"); } try { serverChannel = bootstrap(bossGroup, workerGroup, serverKey.next().asString(), serverKey.next().asInt(), backlogKey.next().asInt(), timeoutKey.next().asInt(), timeoutKey.next().asInt()); int probe = probeKey.next().asInt(); if (probe < -1 || probe == 0) { probe = 10000; logger.warn("Probe time value must be -1 to turn it off or greater than 0"); logger.warn("Using default probe time of 10000 milliseconds (10 seconds)"); } if (probe != -1) { backendTask = (mode == Mode.TCP) ? new CheckSocketBackendTask(balancingStrategy) : new CheckDatagramBackendTask(balancingStrategy); scheduledExecutorService.scheduleAtFixedRate(backendTask, 0, probe, TimeUnit.MILLISECONDS); } else { // Shutdown unnecessary scheduler scheduledExecutorService.shutdown(); } restServer = new RestServer(copeConfig); restServer.start(); logger.info("Apex listening on {}:{}", serverKey.next().asString(), serverKey.next().asInt()); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.jackwhite20.comix.Comix.java
License:Open Source License
public void start() { System.setProperty("java.net.preferIPv4Stack", "true"); ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED); AnsiConsole.systemInstall();/*from w w w .j ava2s. c o m*/ LogManager.getLogManager().reset(); logger = new ComixLogger(consoleReader); logger.log(Level.INFO, "Comix", "------ Comix v.0.1 ------"); loadConfig(); logger.log(Level.INFO, "Load-Balancer", (targets.size() > 0) ? "Targets:" : "No Target Servers found!"); targets.forEach(t -> logger.log(Level.INFO, "Load-Balancer", t.getName() + " - " + t.getHost() + ":" + t.getPort())); logger.log(Level.INFO, "Commands", "Registering commands..."); registerCommands(); logger.log(Level.INFO, "Comix", "Starting Comix on " + balancerHost + ":" + balancerPort + "..."); balancingStrategy = new RoundRobinBalancingStrategy(targets); new Timer("CheckTargets").scheduleAtFixedRate(new CheckTargets(balancingStrategy), 0, TimeUnit.SECONDS.toMillis(comixConfig.getCheckTime())); bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(comixConfig.getThreads()); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_BACKLOG, comixConfig.getBacklog()) .option(ChannelOption.SO_REUSEADDR, true).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.AUTO_READ, false).childOption(ChannelOption.SO_TIMEOUT, 4000) .childHandler(new ComixChannelInitializer()); ChannelFuture f = bootstrap.bind(comixConfig.getPort()).sync(); reload(); logger.log(Level.INFO, "Comix", "Comix is started!"); f.channel().closeFuture().sync(); running = false; } catch (Exception e) { e.printStackTrace(); } finally { shutdown(); } }
From source file:de.unipassau.isl.evs.ssh.core.network.Client.java
License:Open Source License
/** * Configure netty and initialize related Components. * Afterwards call {@link #initClient()} method to start the netty IO client asynchronously. *//*from w ww . j ava 2 s . c o m*/ @Override public void init(Container container) { super.init(container); // Configure netty InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory() { @Override public InternalLogger newInstance(String name) { return new NettyInternalLogger(name); } }); ResourceLeakDetector.setLevel(CoreConstants.NettyConstants.RESOURCE_LEAK_DETECTION); // And try to connect isActive = true; initClient(); // register BroadcastListener IntentFilter filter = new IntentFilter(); filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); requireComponent(ContainerService.KEY_CONTEXT).registerReceiver(broadcastReceiver, filter); }
From source file:de.unipassau.isl.evs.ssh.master.network.Server.java
License:Open Source License
/** * Init timeouts and the connection registry and start the netty IO server synchronously *//*w w w . j av a 2 s .c om*/ @Override public void init(Container container) { super.init(container); try { // Configure netty InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory() { @Override public InternalLogger newInstance(String name) { return new NettyInternalLogger(name); } }); ResourceLeakDetector.setLevel(CoreConstants.NettyConstants.RESOURCE_LEAK_DETECTION); // Start server startServer(); } catch (InterruptedException e) { throw new StartupException("Could not start netty server", e); } }
From source file:deathcap.wsmc.web.WebThread.java
License:Apache License
public WebThread(String wsAddress, int wsPort, String mcAddress, int mcPort, UserIdentityLinker users, PacketFilter filter, boolean verbose) { this.wsAddress = wsAddress; this.wsPort = wsPort; this.mcAddress = mcAddress; this.mcPort = mcPort; this.users = users; this.filter = filter; this.verbose = verbose; // TODO: fix leaks ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED); //ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED); }
From source file:divconq.log.Logger.java
License:Open Source License
/** * Called from Hub.start this method configures the logging features. * //from ww w . ja v a2 s. co m * @param config xml holding the configuration */ static public void init(XElement config) { Logger.config = config; // TODO return operation result // TODO load levels, path etc // include a setting for startup logging - if present set the TC log level directly Logger.startNewLogFile(); // set by operation context init //Logger.locale = LocaleUtil.getDefaultLocale(); // From here on we can use netty and so we need the logger setup InternalLoggerFactory.setDefaultFactory(new divconq.log.netty.LoggerFactory()); if (Logger.config != null) { // set by operation context init //if (Logger.config.hasAttribute("Level")) // Logger.globalLevel = DebugLevel.parse(Logger.config.getAttribute("Level")); if (Logger.config.hasAttribute("NettyLevel")) { ResourceLeakDetector.setLevel(Level.valueOf(Logger.config.getAttribute("NettyLevel"))); Logger.debug("Netty Level set to: " + ResourceLeakDetector.getLevel()); } else if (!"none".equals(System.getenv("dcnet"))) { // TODO anything more we should do here? maybe paranoid isn't helpful? } // set by operation context init //if (Logger.config.hasAttribute("Locale")) // Logger.locale = Logger.config.getAttribute("Locale"); } }
From source file:dorkbox.network.rmi.multiJVM.TestClient.java
License:Apache License
public static void setup() { ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID); // assume SLF4J is bound to logback in the current environment Logger rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); LoggerContext context = rootLogger.getLoggerContext(); JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context);/*from w w w . j a v a2s . c o m*/ context.reset(); // override default configuration // rootLogger.setLevel(Level.OFF); // rootLogger.setLevel(Level.DEBUG); rootLogger.setLevel(Level.TRACE); // rootLogger.setLevel(Level.ALL); // we only want error messages Logger nettyLogger = (Logger) LoggerFactory.getLogger("io.netty"); nettyLogger.setLevel(Level.ERROR); // we only want error messages Logger kryoLogger = (Logger) LoggerFactory.getLogger("com.esotericsoftware"); kryoLogger.setLevel(Level.ERROR); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(context); encoder.setPattern("%date{HH:mm:ss.SSS} %-5level [%logger{35}] %msg%n"); encoder.start(); ConsoleAppender<ILoggingEvent> consoleAppender = new ch.qos.logback.core.ConsoleAppender<ILoggingEvent>(); consoleAppender.setContext(context); consoleAppender.setEncoder(encoder); consoleAppender.start(); rootLogger.addAppender(consoleAppender); }
From source file:io.airlift.drift.transport.netty.buffer.TestingPooledByteBufAllocator.java
License:Apache License
private static ResourceLeakDetector.Level getAndSetResourceLeakDetectorLevel( ResourceLeakDetector.Level newLevel) { ResourceLeakDetector.Level oldLevel = ResourceLeakDetector.getLevel(); ResourceLeakDetector.setLevel(newLevel); return oldLevel; }
From source file:io.airlift.drift.transport.netty.buffer.TestingPooledByteBufAllocator.java
License:Apache License
@Override @SuppressFBWarnings(value = "DM_GC", justification = "Netty's leak detection only works if buffer is garbage collected") public void close() { try {/* ww w. j av a 2s .co m*/ boolean leaked; synchronized (this) { leaked = trackedBuffers.stream().anyMatch(byteBuf -> byteBuf.refCnt() > 0); trackedBuffers.clear(); } // Throw an error if there were any leaked buffers if (leaked) { // Trigger a GC. This will hopefully (but not necessarily) print // details about detected leaks to standard error before the error // is thrown. System.gc(); throw new AssertionError("LEAK"); } } finally { ResourceLeakDetector.setLevel(oldLevel); } }