/** * Used in tests only. */ @SuppressWarnings({ "PMD.DefaultPackage", "PMD.CommentDefaultAccessModifier" }) State getStateOfMonitoringWriterThread() { return this.monitoringWriterThread.getState(); } }
@Override public void waitForTermination(final long timeoutInMs) throws InterruptedException { if (this.monitoringWriterThread != null) { this.monitoringWriterThread.join(timeoutInMs); } }
@Override protected final void init() { LOGGER.debug("Initializing Writer Controller"); if (this.monitoringWriterThread != null) { this.monitoringWriterThread.start(); } }
@Test public void testBlocking() throws Exception { final Configuration configuration = new Configuration(); final AbstractMonitoringWriter writer = new DumpWriter(configuration); final BlockingQueue<IMonitoringRecord> writerQueue = new LinkedBlockingQueue<IMonitoringRecord>(); final MonitoringWriterThread thread = new MonitoringWriterThread(writer, writerQueue); thread.start(); Await.awaitThreadState(thread, State.WAITING, THREAD_STATE_CHANGE_TIMEOUT_IN_MS); thread.terminate(); thread.join(THREAD_STATE_CHANGE_TIMEOUT_IN_MS); Assert.assertThat(thread.getState(), CoreMatchers.is(State.TERMINATED)); } }
@Override protected final void cleanup() { LOGGER.debug("Shutting down Writer Controller"); if (this.monitoringWriterThread != null) { this.monitoringWriterThread.terminate(); } // if (this.disruptor != null) { // this.disruptor.shutdown(); // } // LOG.info("block durations: {}" + this.insertBehavior.toString()); // System.out.println("block durations: " + this.insertBehavior.toString()); }
this.monitoringWriterThread = new MonitoringWriterThread(this.monitoringWriter, this.writerQueue);
public MonitoringWriterThread(final AbstractMonitoringWriter writer, final BlockingQueue<IMonitoringRecord> writerQueue) { if (writer == null) { throw new NullPointerException("The given writer may not be null."); } if (writerQueue == null) { throw new NullPointerException("The given writerQueue may not be null."); } this.writer = writer; this.writerQueue = writerQueue; // All Kieker threads must be daemon threads. Otherwise the monitored application can never terminate. this.setDaemon(true); }
@Test public void testTermination() throws Exception { final Configuration configuration = new Configuration(); final AbstractMonitoringWriter writer = new DumpWriter(configuration); final BlockingQueue<IMonitoringRecord> writerQueue = new LinkedBlockingQueue<IMonitoringRecord>(); writerQueue.add(new EmptyRecord()); final MonitoringWriterThread thread = new MonitoringWriterThread(writer, writerQueue); thread.start(); while (!writerQueue.isEmpty()) { Thread.yield(); } // thread terminates before the timeout has been reached, i.e., // it correctly writes out the EmptyRecord from the writerQueue thread.terminate(); thread.join(THREAD_STATE_CHANGE_TIMEOUT_IN_MS); Assert.assertThat(thread.getState(), CoreMatchers.is(State.TERMINATED)); }
@Override protected final void cleanup() { if (LOG.isDebugEnabled()) { LOG.debug("Shutting down Writer Controller"); } if (this.monitoringWriterThread != null) { this.monitoringWriterThread.terminate(); } // if (this.disruptor != null) { // this.disruptor.shutdown(); // } // LOG.info("block durations: {}" + this.insertBehavior.toString()); // System.out.println("block durations: " + this.insertBehavior.toString()); }
this.monitoringWriterThread = new MonitoringWriterThread(this.monitoringWriter, this.writerQueue);
public MonitoringWriterThread(final AbstractMonitoringWriter writer, final BlockingQueue<IMonitoringRecord> writerQueue) { if (writer == null) { throw new NullPointerException("The given writer may not be null."); } if (writerQueue == null) { throw new NullPointerException("The given writerQueue may not be null."); } this.writer = writer; this.writerQueue = writerQueue; // All Kieker threads must be daemon threads. Otherwise the monitored application can never terminate. this.setDaemon(true); }
/** * Used in tests only. */ // default State getStateOfMonitoringWriterThread() { // NOPMD (package-private) return this.monitoringWriterThread.getState(); } }
@Override public void waitForTermination(final long timeoutInMs) throws InterruptedException { if (this.monitoringWriterThread != null) { this.monitoringWriterThread.join(timeoutInMs); } }
@Override protected final void init() { if (LOG.isDebugEnabled()) { LOG.debug("Initializing Writer Controller"); } if (this.monitoringWriterThread != null) { this.monitoringWriterThread.start(); } }