@Override public void fileNotFound() { this.publish("File not found: " + this.getFile().getAbsolutePath()); try { Thread.sleep(this.getMissingFileDelay()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
@Override public void handle(String line) { send(line); }
@Test public void testIdleEvent() throws Exception { ApacheCommonsFileTailingMessageProducer adapter = new ApacheCommonsFileTailingMessageProducer(); adapter.setTaskScheduler(taskScheduler); adapter.setApplicationEventPublisher(event -> { if (event instanceof FileTailingIdleEvent) { idleCountDownLatch.countDown(); adapter.setFile(file); adapter.setOutputChannel(new NullChannel()); adapter.setIdleEventInterval(10); adapter.afterPropertiesSet(); adapter.start(); boolean eventRaised = idleCountDownLatch.await(10, TimeUnit.SECONDS); assertTrue("idle event did not emit", eventRaised); adapter.stop(); file.delete();
Assert.isTrue(this.nativeOptions == null, "'native-options' is not allowed with 'delay', 'end', or 'reopen'"); adapter = new ApacheCommonsFileTailingMessageProducer(); if (this.delay != null) { ((ApacheCommonsFileTailingMessageProducer) adapter).setPollingDelay(this.delay); ((ApacheCommonsFileTailingMessageProducer) adapter).setEnd(this.end); ((ApacheCommonsFileTailingMessageProducer) adapter).setReopen(this.reopen);
@Test public void testApache() throws Exception { ApacheCommonsFileTailingMessageProducer adapter = new ApacheCommonsFileTailingMessageProducer(); adapter.setPollingDelay(100); adapter.setEnd(false); testGuts(adapter, "tailer"); }
@Test public void testMessageProducerFlow() throws Exception { FileOutputStream file = new FileOutputStream(new File(tmpDir.getRoot(), "TailTest")); for (int i = 0; i < 50; i++) { file.write((i + "\n").getBytes()); } this.tailer.start(); for (int i = 0; i < 50; i++) { Message<?> message = this.tailChannel.receive(5000); assertNotNull(message); assertEquals("hello " + i, message.getPayload()); } assertNull(this.tailChannel.receive(1)); this.controlBus.send("@tailer.stop()"); file.close(); }
@Override protected void doStart() { super.doStart(); Tailer theTailer = new Tailer(this.getFile(), this, this.pollingDelay, this.end, this.reopen); this.getTaskExecutor().execute(theTailer); this.tailer = theTailer; }
@Override public void handle(Exception ex) { this.publish(ex.getMessage()); }
@Test public void testMessageProducerFlow() throws Exception { FileOutputStream file = new FileOutputStream(new File(tmpDir.getRoot(), "TailTest")); for (int i = 0; i < 50; i++) { file.write((i + "\n").getBytes()); } this.tailer.start(); for (int i = 0; i < 50; i++) { Message<?> message = this.tailChannel.receive(5000); assertNotNull(message); assertEquals("hello " + i, message.getPayload()); } assertNull(this.tailChannel.receive(1)); this.controlBus.send("@tailer.stop()"); file.close(); }