@Override public void waitForTermination(final long timeoutInMs) throws InterruptedException { this.writerController.waitForTermination(timeoutInMs); }
@Override public void beforeEnableMonitoring() { if (this.writerController.isLogMetadataRecord()) { this.sendMetadataAsRecord(); } }
@Override public final boolean newMonitoringRecord(final IMonitoringRecord record) { final boolean recordSent = this.insertBehavior.insert(record); if (!recordSent) { LOGGER.error("Error writing the monitoring data. Will terminate monitoring!"); this.terminate(); } return recordSent; }
@Test @SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") // @SuppressFBWarnings("SIC") public void testBlockOnFailedInsertBehavior() throws Exception { final Configuration configuration = new Configuration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_FQN, MpscArrayQueue.class.getName()); configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_SIZE, "1"); configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_INSERT_BEHAVIOR, "1"); final WriterController writerController = new WriterController(configuration); final Thread thread = new Thread(new Runnable() { @Override public void run() { // the first element fits into the queue writerController.newMonitoringRecord(new EmptyRecord()); // the second element exceeds the queue's capacity and triggers // the blocking wait writerController.newMonitoringRecord(new EmptyRecord()); } }); thread.start(); Await.awaitThreadState(thread, State.WAITING, THREAD_STATE_CHANGE_TIMEOUT_IN_MS); writerController.init(); // starts the queue consumer Await.awaitThreadState(thread, State.TERMINATED, THREAD_STATE_CHANGE_TIMEOUT_IN_MS); writerController.cleanup(); // triggers the termination of the queue // consumer writerController.waitForTermination(CONTROLLER_TIMEOUT_IN_MS); Assert.assertThat(writerController.getStateOfMonitoringWriterThread(), CoreMatchers.is(State.TERMINATED)); }
final String queueFqn = configuration.getStringProperty(PREFIX + RECORD_QUEUE_FQN); final Queue<IMonitoringRecord> queue = this.newQueue(queueFqn, this.queueCapacity); if (queue instanceof BlockingQueue) { this.writerQueue = (BlockingQueue<IMonitoringRecord>) queue; configuration); if (this.monitoringWriter == null) { this.terminate(); return; // TODO should throw an exception! and then monitoringWriter can be declared
monitoringController.terminate(); monitoringController.writerController.setMonitoringController(monitoringController); if (monitoringController.writerController.isTerminated()) { monitoringController.terminate();
private MonitoringController(final Configuration configuration) { super(configuration); this.stateController = new StateController(configuration); this.samplingController = new SamplingController(configuration); this.jmxController = new JMXController(configuration); this.writerController = new WriterController(configuration); this.stateController.setStateListener(this); this.timeSourceController = new TimeSourceController(configuration); this.probeController = new ProbeController(configuration); this.autoSetLoggingTimestamp = configuration.getBooleanProperty(ConfigurationFactory.AUTO_SET_LOGGINGTSTAMP); }
@Override public void run() { // the first element fits into the queue writerController.newMonitoringRecord(new EmptyRecord()); // the second element exceeds the queue's capacity and triggers // the blocking wait writerController.newMonitoringRecord(new EmptyRecord()); } });
final String queueFqn = configuration.getStringProperty(PREFIX + RECORD_QUEUE_FQN); final Queue<IMonitoringRecord> queue = this.newQueue(queueFqn, this.queueCapacity); if (queue instanceof BlockingQueue) { this.writerQueue = (BlockingQueue<IMonitoringRecord>) queue; configuration); if (this.monitoringWriter == null) { this.terminate(); return; // TODO should throw an exception! and then monitoringWriter can be declared final
monitoringController.terminate(); monitoringController.writerController.setMonitoringController(monitoringController); if (monitoringController.writerController.isTerminated()) { monitoringController.terminate();
@Test(expected = IllegalStateException.class) public void testInvalidWriterQueueConfiguration() { final Configuration configuration = new Configuration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, "invalid writer queue fully qualified name"); new WriterController(configuration); }
@Override public final boolean newMonitoringRecord(final IMonitoringRecord record) { if (!this.isMonitoringEnabled()) { // enabled and not terminated return false; } if (this.autoSetLoggingTimestamp) { record.setLoggingTimestamp(this.getTimeSource().getTime()); } return this.writerController.newMonitoringRecord(record); }
private MonitoringController(final Configuration configuration) { super(configuration); this.stateController = new StateController(configuration); this.samplingController = new SamplingController(configuration); this.jmxController = new JMXController(configuration); this.tcpController = new TCPController(configuration, this); this.writerController = new WriterController(configuration); this.stateController.setStateListener(this); this.timeSourceController = new TimeSourceController(configuration); this.probeController = new ProbeController(configuration); this.autoSetLoggingTimestamp = configuration.getBooleanProperty(ConfigurationKeys.AUTO_SET_LOGGINGTSTAMP); }
@Override public final boolean newMonitoringRecord(final IMonitoringRecord record) { if (!this.isMonitoringEnabled()) { // enabled and not terminated return false; } if (this.autoSetLoggingTimestamp) { record.setLoggingTimestamp(this.getTimeSource().getTime()); } return this.writerController.newMonitoringRecord(record); }
@Override public void waitForTermination(final long timeoutInMs) throws InterruptedException { this.writerController.waitForTermination(timeoutInMs); }
@Override public final boolean newMonitoringRecord(final IMonitoringRecord record) { final boolean recordSent = this.insertBehavior.insert(record); if (!recordSent) { LOG.error("Error writing the monitoring data. Will terminate monitoring!"); this.terminate(); } return recordSent; }
@Override public void beforeEnableMonitoring() { if (this.writerController.isLogMetadataRecord()) { this.sendMetadataAsRecord(); } }
@Override protected final void cleanup() { LOGGER.info("Shutting down Monitoring Controller ({})", this.getName()); // this.saveMetadataAsRecord(); this.probeController.terminate(); this.timeSourceController.terminate(); this.writerController.terminate(); this.jmxController.terminate(); this.tcpController.terminate(); this.samplingController.terminate(); this.stateController.terminate(); }
@Override protected final void cleanup() { LOG.info("Shutting down Monitoring Controller (" + this.getName() + ")"); // this.saveMetadataAsRecord(); this.probeController.terminate(); this.timeSourceController.terminate(); this.writerController.terminate(); this.jmxController.terminate(); this.samplingController.terminate(); this.stateController.terminate(); }