Example usage for org.apache.commons.io.input Tailer stop

List of usage examples for org.apache.commons.io.input Tailer stop

Introduction

In this page you can find the example usage for org.apache.commons.io.input Tailer stop.

Prototype

public void stop() 

Source Link

Document

Allows the tailer to complete its current loop and return.

Usage

From source file:com.hellblazer.process.JavaProcessTest.java

public void testTailStdInputOutputStreams() throws Exception {
    final List<String> lines = new CopyOnWriteArrayList<>();
    TailerListener listener = new TailerListenerAdapter() {
        @Override/* ww  w  .  ja va  2s . c  o m*/
        public void handle(String line) {
            lines.add(line);
        }
    };

    copyTestClassFile();
    JavaProcess process = new JavaProcessImpl(processFactory.create());
    String testLine = "hello";
    process.setArguments(new String[] { "-readln", testLine });
    process.setJavaClass(HelloWorld.class.getCanonicalName());
    process.setDirectory(testDir);
    process.setJavaExecutable(javaBin);

    Tailer tailer = null;
    try {
        launchProcess(process);
        tailer = process.tailStdOut(listener);

        try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(process.getStdIn()))) {
            writer.println(testLine);
            writer.flush();
        }

        assertEquals("Process exited normally", 0, process.waitFor());
        assertTrue("Process not active", !process.isActive());
        Utils.waitForCondition(1000, new Condition() {
            @Override
            public boolean isTrue() {
                return lines.size() > 1;
            }
        });

        assertEquals(2, lines.size());
        assertEquals(testLine, lines.get(1));

        tailer.stop();
    } finally {
        if (tailer != null) {
            tailer.stop();
        }

        process.destroy();
    }
}

From source file:org.apache.directory.studio.ldapservers.LdapServersUtils.java

/**
 * Stops the tailer thread.// ww w.j av  a 2s.  com
 *
 * @param server
 *      the server
 */
public static void stopConsolePrinterThread(LdapServer server) {
    // Getting the console printer
    Tailer tailer = (Tailer) server.removeCustomObject(CONSOLE_PRINTER_CUSTOM_OBJECT);
    if (tailer != null) {
        // Closing the console printer
        tailer.stop();
    }
}

From source file:org.cloudifysource.usm.liveness.FileLivenessDetector.java

/**
 * isProcessAlive will sample the file defined in the groovy configuration file every second for the specified
 * timeout period looking for a regex in the log that confirms the process has loaded successfully and return true
 * if the regex was found.// w ww.j a va  2s.  com
 * 
 * @throws USMException .
 * 
 */
@Override
public boolean isProcessAlive() throws USMException {
    if (this.regex.isEmpty() || this.filePath.isEmpty()) {
        throw new USMException(
                "When using the FileLivnessDetector, both the file path and regex should be defined.");
    }
    File file = new File(this.filePath);
    if (!file.isAbsolute()) {
        file = new File(serviceDirectory, this.filePath);
    }
    final FileTailerListener listener = new FileTailerListener(this.regex);
    Tailer tailer = null;
    try {
        final long startTime = System.currentTimeMillis();
        while (System.currentTimeMillis() < startTime + TimeUnit.SECONDS.toMillis(timeoutInSeconds)) {
            if (file.exists()) {
                if (tailer == null) {
                    tailer = Tailer.create(file, listener, TIMEOUT_BETWEEN_FILE_QUERYING, false);
                }
                if (listener.isProcessUp()) {
                    logger.info("The regular expression " + this.regex + " was found in the process log");
                    return true;
                }
            }
            try {
                Thread.sleep(TIMEOUT_BETWEEN_FILE_QUERYING);
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    } finally {
        if (tailer != null) {
            tailer.stop();
        }
    }
    logger.info("The regular expression " + this.regex + " was NOT found in the process log");
    return false;

}

From source file:org.jboss.additional.testsuite.jdkall.present.messaging.jms.deployment.PooledCFAvailableOnStartupTestCase.java

@Test
public void test() {

    ServerLogPatternListener listener = new ServerLogPatternListener(Pattern.compile(".*WFLYCTL0030.*"));
    Tailer serverLogTailer = new Tailer(SERVER_LOG, listener, 100, true);
    Thread tailerThread = new Thread(serverLogTailer);
    tailerThread.start();//from   w w w.java 2 s . co  m

    ServerReload.executeReloadAndWaitForCompletion(mc.getControllerClient());
    serverLogTailer.stop();
    Assert.assertTrue("Server log contains error messages caused by missing resource definitions!",
            listener.getMatchedLines().isEmpty());
}

From source file:org.sonarqube.qa.util.LogsTailer.java

@Override
public void close() {
    for (Tailer tailer : tailers) {
        tailer.stop();
    }
}