/** * @param configuration * A configuration object for Kieker monitoring * @param service * A service component to handle incoming data * @param respawn * Respawn the connector if it fails (this construct is debatable it should be handled by the connector * itself) */ public ServiceContainer(final Configuration configuration, final IServiceConnector service, final boolean respawn) { this.kiekerMonitoringController = MonitoringController.createInstance(configuration); this.respawn = respawn; this.service = service; }
/** * This method sends the meta data (like the controller and host name, the experiment ID, etc.) as a record. * * @return true on success; false in case of an error. */ @Override public final boolean sendMetadataAsRecord() { final ITimeSource timesource = this.getTimeSource(); return this.newMonitoringRecord(new KiekerMetadataRecord( null, // Kieker version will be filled in this.getName(), // controllerName this.getHostname(), // hostname this.getExperimentId(), // experimentId this.isDebug(), // debugMode timesource.getOffset(), // timeOffset timesource.getTimeUnit().name(), // timeUnit 0 // number of inserts (0 since not supported anymore) )); }
/** * {@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) { LOGGER.warn("An exception occurred while waiting for the monitoring to terminate.", e); } }
@Override public void run() { if (!monitoringController.isMonitoringTerminated()) { // WONTFIX: We should not use a logger in shutdown hooks, logger may already be // down! (#26) LOGGER.info("ShutdownHook notifies controller to initiate shutdown."); monitoringController.terminateMonitoring(); try { monitoringController.waitForTermination(SHUTDOWN_DELAY_MILLIS); } catch (final InterruptedException e) { // ignore since we cannot do anything at this point LOGGER.warn("Shutdown was interrupted while waiting"); } // LOG.info("ShutdownHook has finished."); // does not work anymore // System.out.println("ShutdownHook has finished."); // works! } } });
@SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation") private List<IMonitoringRecord> executeTest(final List<IMonitoringRecord> records, final String outputFileName) throws InterruptedException { // 2. define monitoring config final Configuration config = ConfigurationFactory.createDefaultConfiguration(); config.setProperty(WriterController.RECORD_QUEUE_SIZE, "128"); config.setProperty(WriterController.RECORD_QUEUE_INSERT_BEHAVIOR, "1"); config.setProperty(ConfigurationKeys.WRITER_CLASSNAME, PrintStreamWriter.class.getName()); config.setProperty(PrintStreamWriter.STREAM, outputFileName); final MonitoringController monitoringController = MonitoringController.createInstance(config); // 4. trigger records final TestProbe testProbe = new TestProbe(monitoringController); Assert.assertTrue(monitoringController.isMonitoringEnabled()); testProbe.triggerRecords(records); Assert.assertTrue(monitoringController.isMonitoringEnabled()); // 5. terminate monitoring monitoringController.terminateMonitoring(); // 6. wait for termination monitoringController.waitForTermination(TIMEOUT_IN_MS); // 7. read actual records // We cannot do anything meaningful here, because there's nothing like a PrintStreamReader. // We'll return an empty List and use our own buffer when evaluating the result. return new ArrayList<IMonitoringRecord>(); }
while (this.active) { try { this.kiekerMonitoringController.newMonitoringRecord(this.service.deserializeNextRecord()); this.numRecordsReceived++; if ((this.numRecordsReceived % this.listenerUpdateInterval) == 0) { } while (this.respawn); this.kiekerMonitoringController.terminateMonitoring(); try { this.kiekerMonitoringController.waitForTermination(10000); } catch (final InterruptedException e) { throw new IllegalStateException("Exception occured while waiting for the monitoring to terminate.", e);
@Test public void testWriteRead() throws InterruptedException { // NOPMD (JUnitTestsShouldIncludeAssert) final List<IMonitoringRecord> inputRecords = this.provideEvents(); // Create monitoring controller for JMSWriter final Configuration config = ConfigurationFactory.createDefaultConfiguration(); config.setProperty(ConfigurationKeys.WRITER_CLASSNAME, JmsWriter.class.getName()); config.setProperty(JmsWriter.CONFIG_CONTEXTFACTORYTYPE, FakeInitialContextFactory.class.getName()); config.setProperty(JmsWriter.CONFIG_FACTORYLOOKUPNAME, "ConnectionFactory"); final MonitoringController monCtrl = MonitoringController.createInstance(config); // Start the reader final JMSReaderThread jmsReaderThread = new JMSReaderThread("tcp://127.0.0.1:61616/", "queue1", FakeInitialContextFactory.class.getName()); jmsReaderThread.start(); Thread.sleep(1000); // wait a second to make sure the reader is ready to read this.checkControllerStateBeforeRecordsPassedToController(monCtrl); // Send records for (final IMonitoringRecord record : inputRecords) { monCtrl.newMonitoringRecord(record); } Thread.sleep(1000); // wait a second to give the FS writer the chance to write the monitoring log. this.checkControllerStateAfterRecordsPassedToController(monCtrl); final List<IMonitoringRecord> outputRecords = jmsReaderThread.getOutputList(); // Inspect records (sublist is used to exclude the KiekerMetadataRecord sent by // the monitoring controller) Assert.assertEquals("Unexpected set of records", inputRecords, outputRecords.subList(1, outputRecords.size())); // Need to terminate explicitly, because otherwise, the monitoring log directory // cannot be removed monCtrl.terminateMonitoring(); monCtrl.waitForTermination(TIMEOUT_IN_MS); }
/** * Test if records are passed to the writer when monitoring is enabled. * * @throws InterruptedException */ @Test public void testRecordsPassedToWriterWhenEnabled() throws InterruptedException { final String pipeName = NamedPipeFactory.createPipeName(); final MonitoringController monitoringController = NamedPipeFactory.createMonitoringControllerWithNamedPipe(pipeName); // We will now register a custom IPipeReader which receives records through the pipe and collects these in a list. On purpose, we are not using the // corresponding PipeReader that comes with Kieker. final List<IMonitoringRecord> receivedRecords = NamedPipeFactory.createAndRegisterNamedPipeRecordCollector(pipeName); Assert.assertTrue("Failed to enable monitoring", monitoringController.enableMonitoring()); monitoringController.newMonitoringRecord(new EmptyRecord()); monitoringController.terminateMonitoring(); monitoringController.waitForTermination(5000); Assert.assertEquals("Unexpected number of records received", 1, receivedRecords.size()); }
final long offset = 200; // 1st event after 200 ms this.monitoringController.schedulePeriodicSampler(this.sampler, offset, period, TimeUnit.MILLISECONDS); this.checkNumEventsBeforeMonitoringDisabled(numEventsBeforeProbeDisabled); this.monitoringController.deactivateProbe(this.jvmSignature); // DEACTIVATION (probe) Assert.assertEquals("Unexpected number of triggering events while probe being disabled", 0, numEventsWhileProbeDisabled); this.monitoringController.activateProbe(this.jvmSignature); // REACTIVATION (probe) this.checkNumEventsBeforeMonitoringDisabled(numEventsBeforeMonitoringDisabled); this.monitoringController.disableMonitoring(); // DEACTIVATION (monitoring) Assert.assertEquals("Unexpected number of triggering events while monitoring being disabled", 0, numEventsWhileMonitoringDisabled); this.monitoringController.enableMonitoring(); // REACTIVATION (monitoring) numEventsAfterMonitoringReEnabled > 0); this.monitoringController.terminateMonitoring(); this.monitoringController.waitForTermination(5000);
/** * Test if records are not passed to the writer when monitoring is disabled. * * @throws InterruptedException */ @Test public void testNoRecordsPassedToWriterWhenDisabled() throws InterruptedException { final String pipeName = NamedPipeFactory.createPipeName(); final MonitoringController monitoringController = NamedPipeFactory.createMonitoringControllerWithNamedPipe(pipeName); // We will now register a custom IPipeReader which receives records through the pipe and collects these in a list. On purpose, we are not using the // corresponding PipeReader that comes with Kieker. final List<IMonitoringRecord> receivedRecords = NamedPipeFactory.createAndRegisterNamedPipeRecordCollector(pipeName); Assert.assertTrue("Failed to disable monitoring", monitoringController.disableMonitoring()); monitoringController.newMonitoringRecord(new EmptyRecord()); monitoringController.terminateMonitoring(); monitoringController.waitForTermination(5000); Assert.assertEquals("Unexpected number of records received", 0, receivedRecords.size()); }
final MonitoringController monitoringController; monitoringController = new MonitoringController(configuration); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.setMonitoringController(monitoringController); if (monitoringController.isTerminated()) { return monitoringController; if (monitoringController.isMonitoringEnabled()) { monitoringController.enableMonitoring(); // notifies the listener LOGGER.info(monitoringController.toString()); return monitoringController;
/** * Creates a new instance of this class, using the singleton instance of the {@link MonitoringController} as controller. */ public OperationExecutionSOAPResponseOutInterceptor() { this(MonitoringController.getInstance()); }
@Test(timeout = 30000) public void testActivationAndDeactivation() throws IOException, InterruptedException { final MonitoringController controller = MonitoringController.createInstance(TCPControllerTest.configuration); final String pattern = "void test.pattern()"; this.tcpWriter = new SingleSocketTcpWriter(configuration); this.tcpWriter.onStarting(); Assert.assertTrue(controller.activateProbe(pattern)); controller.deactivateProbe(pattern); Assert.assertFalse(controller.isProbeActivated(pattern)); this.sendTCPEvent(new ActivationEvent(pattern)); while (!controller.isProbeActivated(pattern)) { Thread.yield(); } Assert.assertTrue(controller.isProbeActivated(pattern)); this.sendTCPEvent(new DeactivationEvent(pattern)); while (controller.isProbeActivated(pattern)) { Thread.yield(); } Assert.assertFalse(controller.isProbeActivated(pattern)); controller.cleanup(); this.tcpWriter.onTerminating(); }
/** * Safely end bridge loop. This routine should only be called from the shutdown hook thread in the main part of a * server. In other cases it will result in strange runtime errors. * * @throws ConnectorDataTransmissionException * An error occurred during data transmission and in this particular case while closing the data * transmission. */ public void shutdown() throws ConnectorDataTransmissionException { this.active = false; this.respawn = false; this.service.close(); this.kiekerMonitoringController.terminateMonitoring(); }
/** * This method represents the input port. The new records are send to the monitoring controller before they are delivered via the output port. * * @param record * The next record. */ @InputPort(name = INPUT_PORT_NAME_RECORD, description = "Receives records to be passed to the controller", eventTypes = { IMonitoringRecord.class }) public final void inputIMonitoringRecord(final IMonitoringRecord record) { this.monitoringController.newMonitoringRecord(record); super.deliver(OUTPUT_PORT_NAME_RELAYED_EVENTS, record); }
@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); }
config.setProperty(FileWriter.CONFIG_PATH, this.tmpFolder.getRoot().getCanonicalPath()); config.setProperty(FileWriter.CONFIG_COMPRESSION_FILTER, compressionFilter); final MonitoringController monitoringController = MonitoringController.createInstance(config); Assert.assertTrue(monitoringController.isMonitoringEnabled()); testProbe.triggerRecords(records); Assert.assertTrue(monitoringController.isMonitoringEnabled()); monitoringController.terminateMonitoring(); monitoringController.waitForTermination(TIMEOUT_IN_MS);
while (this.active) { try { this.kiekerMonitoringController.newMonitoringRecord(this.service.deserializeNextRecord()); this.numRecordsReceived++; if ((this.numRecordsReceived % this.listenerUpdateInterval) == 0) { } while (this.respawn); this.kiekerMonitoringController.terminateMonitoring(); try { this.kiekerMonitoringController.waitForTermination(10000); } catch (final InterruptedException e) { throw new IllegalStateException("Exception occured while waiting for the monitoring to terminate.", e);
final MonitoringController monitoringController; monitoringController = new MonitoringController(configuration); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.terminate(); monitoringController.setMonitoringController(monitoringController); if (monitoringController.isTerminated()) { return monitoringController; if (monitoringController.isMonitoringEnabled()) { monitoringController.enableMonitoring(); // notifies the listener LOG.warn("Shutdown Hook is disabled, loss of monitoring data might occur."); LOG.info(monitoringController.toString()); return monitoringController;
/** * Creates a new instance of this class, using the singleton instance of the * {@link MonitoringController} as controller. */ public OperationExecutionSOAPRequestOutInterceptor() { this(MonitoringController.getInstance()); }