Example usage for org.springframework.integration.file.tail FileTailingMessageProducerSupport setTailAttemptsDelay

List of usage examples for org.springframework.integration.file.tail FileTailingMessageProducerSupport setTailAttemptsDelay

Introduction

In this page you can find the example usage for org.springframework.integration.file.tail FileTailingMessageProducerSupport setTailAttemptsDelay.

Prototype

public void setTailAttemptsDelay(long tailAttemptsDelay) 

Source Link

Document

The delay in milliseconds between attempts to tail a non-existent file, or between attempts to execute a process if it fails for any reason.

Usage

From source file:org.springframework.integration.file.tail.FileTailingMessageProducerTests.java

private void testGuts(FileTailingMessageProducerSupport adapter, String field) throws Exception {
    this.adapter = adapter;
    final List<FileTailingEvent> events = new ArrayList<FileTailingEvent>();
    adapter.setApplicationEventPublisher(new ApplicationEventPublisher() {
        @Override/*  w  w w. j ava 2 s .  c  om*/
        public void publishEvent(ApplicationEvent event) {
            FileTailingEvent tailEvent = (FileTailingEvent) event;
            logger.warn(event);
            events.add(tailEvent);
        }
    });
    adapter.setFile(new File(testDir, "foo"));
    QueueChannel outputChannel = new QueueChannel();
    adapter.setOutputChannel(outputChannel);
    adapter.setTailAttemptsDelay(500);
    adapter.afterPropertiesSet();
    File file = new File(testDir, "foo");
    File renamed = new File(testDir, "bar");
    file.delete();
    renamed.delete();
    adapter.start();
    waitForField(adapter, field);
    FileOutputStream foo = new FileOutputStream(file);
    for (int i = 0; i < 50; i++) {
        foo.write(("hello" + i + "\n").getBytes());
    }
    foo.flush();
    foo.close();
    for (int i = 0; i < 50; i++) {
        Message<?> message = outputChannel.receive(5000);
        assertNotNull("expected a non-null message", message);
        assertEquals("hello" + i, message.getPayload());
    }
    file.renameTo(renamed);
    file = new File(testDir, "foo");
    foo = new FileOutputStream(file);
    if (adapter instanceof ApacheCommonsFileTailingMessageProducer) {
        Thread.sleep(1000);
    }
    for (int i = 50; i < 100; i++) {
        foo.write(("hello" + i + "\n").getBytes());
    }
    foo.flush();
    foo.close();
    for (int i = 50; i < 100; i++) {
        Message<?> message = outputChannel.receive(10000);
        assertNotNull("expected a non-null message", message);
        assertEquals("hello" + i, message.getPayload());
    }
}