@SuppressWarnings("synthetic-access") @Override protected void onRecordReceived(final IMonitoringRecord record) { final boolean success = DualSocketTcpReader.this.deliver(OUTPUT_PORT_NAME_RECORDS, record); if (!success) { this.logger.warn("Failed to deliver record: " + record); } } };
/** * Causes the calling thread to wait until the analysis controller has been initialized. */ protected final void awaitInitialization() { try { this.initializationLatch.await(); } catch (final InterruptedException ex) { LOG.warn("Interrupted while waiting for initialization of analysis controller.", ex); } }
/** * Initiates the termination of this thread. */ public void terminate() { // Do not call interrupt() to indicate thread termination. // It interrupts writes to (socket) channels. // Instead, we use a unique end-of-monitoring token to indicate that the thread should terminate itself. try { // apply "blocking wait" since we must ensure that this EOF record is inserted to terminate the thread this.writerQueue.put(END_OF_MONITORING_RECORD); } catch (final InterruptedException e) { LOG.warn("An exception occurred", e); } }
public void onMaxLogFilesExceeded() { final Path oldestFile = this.logFiles.remove(0); try { Files.delete(oldestFile); } catch (final IOException e) { this.writerLog.warn("Cannot delete oldest file.", e); } }
@Override public void init(final FilterConfig config) throws ServletException { // by default, we do nothing here. Extending classes may override this method final String valString = config.getInitParameter(CONFIG_PROPERTY_NAME_LOG_FILTER_EXECUTION); if (valString != null) { this.logFilterExecution = Boolean.parseBoolean(valString); } else { LOG.warn("Filter configuration '" + CONFIG_PROPERTY_NAME_LOG_FILTER_EXECUTION + "' not set. Using the value: " + this.logFilterExecution); } }
private static void loadLogger(final String loggerProperties) { try { final LogManager logManager = LogManager.getLogManager(); final InputStream configStream = ClassLoader.getSystemClassLoader().getResourceAsStream(loggerProperties); if (configStream != null) { logManager.readConfiguration(configStream); } else { LOG.warn("Could not load verbose/debug logger"); } } catch (final SecurityException ex) { LOG.warn("Could not load verbose/debug logger", ex); } catch (final IOException ex) { LOG.warn("Could not load verbose/debug logger", ex); } }
private long readLongInitParameter(final ServletContext c, final String paramName, final long defaultValue) { long val = -1; final String valStr = c.getInitParameter(paramName); if (valStr != null) { try { val = Long.parseLong(valStr); } catch (final NumberFormatException exc) { val = -1; // will use default value below. } } if (val < 0) { LOG.warn("Invalid or missing value for context-param '" + paramName + "': " + valStr + ". Using default value: " + defaultValue); val = defaultValue; } return val; }
@Override public void onStarting() { if (CONFIG_STREAM_STDOUT.equals(this.configPrintStreamName)) { this.printStream = System.out; } else if (CONFIG_STREAM_STDERR.equals(this.configPrintStreamName)) { this.printStream = System.err; } else { try { this.printStream = new PrintStream(new FileOutputStream(this.configPrintStreamName), false, ENCODING); } catch (UnsupportedEncodingException | FileNotFoundException e) { LOG.warn("An exception occurred", e); } } }
/** * {@inheritDoc} */ @Override public final boolean terminateMonitoring() { if (super.monitoringController != null) { return super.monitoringController.terminate(); } else { LOG.warn("Shutting down Monitoring before it is correctly initialized"); return false; } }
@Override public void onTerminating() { // Terminate scheduled execution and write remaining chunks, if any this.scheduledExecutor.shutdown(); try { // Wait for the executor to shut down this.scheduledExecutor.awaitTermination(Long.MAX_VALUE, TASK_RUN_INTERVAL_TIME_UNIT); } catch (final InterruptedException e) { LOG.warn("Awaiting termination of the scheduled executor was interrupted.", e); } this.writerTask.terminate(); }
@Override public boolean insert(final E element) { final boolean offered = this.queue.offer(element); if (!offered) { final long tmpMissedRecords = this.numFailedInserts.incrementAndGet(); if (LOG.isWarnEnabled() && ((tmpMissedRecords % 1024) == 1)) { // warn upon the first failed element and upon all 1024th one LOG.warn("Queue is full, dropping records. Number of already dropped records: " + tmpMissedRecords); } } return true; }
public static void close(final Closeable closeable, final Log log) { try { closeable.close(); } catch (final IOException e) { if (log.isWarnEnabled()) { log.warn("Caught exception while closing '" + closeable.getClass() + "'.", e); } } } }
@Override public int getConfidenceLevel() { if (this.supportsConfidence()) { return this.confidenceLevel; } else { if (!this.warningAlreadyLogged) { LOG.warn("Confidence level not supported. Falling back to 0.0."); this.warningAlreadyLogged = true; } return 0; } } }
/** * Reads the given property from the configuration and interprets it as a long. * * @param key * The key of the property. * @return A long with the value of the given property or null, if the property does not exist. */ public final long getLongProperty(final String key) { final String s = this.getStringProperty(key); try { return Long.parseLong(s); } catch (final NumberFormatException ex) { LOG.warn("Error parsing configuration property '" + key + "', found value '" + s + "', using default value 0"); // ignore ex return 0; } }
private void initParameters(final ServletContext c) { if (c == null) { LOG.warn("ServletContext == null"); // we are using the default values assigned during variable declaration. return; } // allowed values: Int>=0 this.initialDelaySeconds = this.readLongInitParameter(c, this.contextParameterNameSamplingDelaySeconds, DEFAULT_SENSOR_INITIAL_DELAY_SECONDS); // allows values: Int>0 this.sensorIntervalSeconds = this.readLongInitParameter(c, this.contextParameterNameSamplingIntervalSeconds, DEFAULT_SENSOR_INTERVAL_SECONDS); if (this.sensorIntervalSeconds == 0) { LOG.warn("values for the init-param '" + this.contextParameterNameSamplingIntervalSeconds + "' must be >0; found: " + this.sensorIntervalSeconds + ". Using default value: " + DEFAULT_SENSOR_INTERVAL_SECONDS); this.sensorIntervalSeconds = DEFAULT_SENSOR_INTERVAL_SECONDS; } }
/** * {@inheritDoc} */ @Override public final ScheduledSamplerJob schedulePeriodicSampler(final ISampler sensor, final long initialDelay, final long period, final TimeUnit timeUnit) { if (null == this.periodicSensorsPoolExecutor) { LOG.warn("Won't schedule periodic sensor since Periodic Sampling is deactivated."); return null; } final ScheduledSamplerJob job = new ScheduledSamplerJob(super.monitoringController, sensor); // we need to keep the future for later cancellation/removal final ScheduledFuture<?> future = this.periodicSensorsPoolExecutor.scheduleAtFixedRate(job, initialDelay, period, timeUnit); job.setFuture(future); return job; }
public MonitoringThroughputFilter(final Configuration configuration, final IProjectContext projectContext) { super(configuration, projectContext); this.timeunit = super.recordsTimeUnitFromProjectContext; final String configTimeunitProperty = configuration.getStringProperty(CONFIG_PROPERTY_NAME_TIMEUNIT); TimeUnit configTimeunit; try { configTimeunit = TimeUnit.valueOf(configTimeunitProperty); } catch (final IllegalArgumentException ex) { this.log.warn(configTimeunitProperty + " is no valid TimeUnit! Using inherited value of " + this.timeunit.name() + " instead."); configTimeunit = this.timeunit; } this.intervalSize = this.timeunit.convert(configuration.getLongProperty(CONFIG_PROPERTY_NAME_INTERVAL_SIZE), configTimeunit); }
/** * {@inheritDoc} */ @Override public void terminate(final boolean error) { this.monitoringController.terminateMonitoring(); try { // we expect a waiting time of 10-100 ms. // So, a timeout of 10,000 ms should be high enough. this.monitoringController.waitForTermination(10000); } catch (final InterruptedException e) { LOG.warn("An exception occurred while waiting for the monitoring to terminate.", e); } }
/** * This simple helper method validates the configuration object. * * @param configuration * The configuration object to check and (perhaps) update. * @return The configuration object. */ private Configuration validateConfiguration(final Configuration configuration) { final String stringProperty = configuration.getStringProperty(CONFIG_PROPERTY_NAME_RECORDS_TIME_UNIT); try { TimeUnit.valueOf(stringProperty); } catch (final IllegalArgumentException ignore) { LOG.warn(stringProperty + " is no valid TimeUnit! Using NANOSECONDS instead."); configuration.setProperty(CONFIG_PROPERTY_NAME_RECORDS_TIME_UNIT, TimeUnit.NANOSECONDS.name()); } return configuration; }
@Override public void onStarting() { final IMonitoringController monitoringController = MonitoringController.getInstance(); try { final HostApplicationMetaData record = new HostApplicationMetaData( "Default System", InetAddress.getLocalHost().getHostAddress(), monitoringController.getHostname(), monitoringController.getName()); this.writeMonitoringRecord(record); } catch (final UnknownHostException e) { LOG.warn("An exception occurred", e); } }