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

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

Introduction

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

Prototype

public static Tailer create(File file, TailerListener listener, long delay, boolean end) 

Source Link

Document

Creates and starts a Tailer for the given file.

Usage

From source file:io.adeptj.runtime.websocket.ServerLogsTailer.java

ServerLogsTailer(File logFile, Session session) {
    this.tailer = Tailer.create(logFile, new ServerLogsTailerListener(logFile, session), DELAY_MILLIS, true);
}

From source file:com.heartbuffer.pipette.input.FileInput.java

public FileInput(FileInputConfig inputConfig, PipetteConfig config) throws IOException, GrokException {
    super(config, inputConfig.getGrokPattern());
    outputQueue = new LinkedBlockingQueue<String>();
    fileTailer = Tailer.create(new File(inputConfig.getFilepath()), this, inputConfig.getCheckDelayInMillis(),
            !inputConfig.isFromBeginning());
}

From source file:com.adeptj.runtime.websocket.ServerLogsTailer.java

ServerLogsTailer(Session session) {
    this.tailerListener = new ServerLogsTailerListener();
    this.tailerListener.setWebSocketSession(session);
    this.tailer = Tailer.create(Paths.get(Configs.of().logging().getString(SERVER_LOG_FILE)).toFile(),
            this.tailerListener, DELAY_MILLIS, true);
}

From source file:cz.msebera.unbound.dns.fragments.MainLogFragment.java

@Nullable
@Override//w  w  w. j  a  va 2s.c  o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.textview, container, false);
    mTextArea = (TextView) v.findViewById(R.id.textview);
    File logFile = new File(getActivity().getFilesDir(), getString(R.string.path_mainlog));
    mTailer = Tailer.create(logFile, this, 400, true);
    return v;
}

From source file:eu.tango.energymodeller.datasourceclient.SlurmDataSourceAdaptor.java

/**
 * This is the generic startup code for the Slurm data source adaptor
 *
 * @param interval The interval at which to take logging data.
 *//*ww w. jav a  2s.c om*/
public final void startup(int interval) {
    String filename = settings.getString("energy.modeller.slurm.scrape.file", "slurm-host-data.log");
    boolean useFileScraper = settings.getBoolean("energy.modeller.slurm.scrape.from.file", false);
    if (useFileScraper) {
        File scrapeFile = new File(filename);
        fileTailer = new SlurmDataSourceAdaptor.SlurmTailer();
        tailer = Tailer.create(scrapeFile, fileTailer, (interval * 1000) / 16, true);
        Thread tailerThread = new Thread(tailer);
        tailerThread.setDaemon(true);
        tailerThread.start();
        System.out.println("Scraping from Slurm output file");
    } else {
        //Parse directly from SLURM
        String hostsList = settings.getString("energy.modeller.slurm.hosts", "ns[52-53]");
        poller = new SlurmPoller(hostsList, interval);
        Thread pollerThread = new Thread(poller);
        pollerThread.setDaemon(true);
        pollerThread.start();
        System.out.println("Reading from SLURM directly");
    }
    if (settings.isChanged()) {
        settings.save("energy-modeller-slurm-config.properties");
    }
}

From source file:eu.tango.energymodeller.datasourceclient.WattsUpMeterDataSourceAdaptor.java

/**
 * This is the generic startup code for the WattsUp data source adaptor
 *
 * @param port The port to connect to/*from  w ww  .ja  v  a  2 s .  co m*/
 * @param duration The duration to connect for (< 0 means forever) 
 * @param interval The interval at which to take logging data.
 */
public final void startup(String port, int duration, int interval) {
    if (port.equalsIgnoreCase("file")) {
        String filename = settings.getString("energy.modeller.wattsup.scrape.file", "testnodex-wattsup.log");
        if (settings.isChanged()) {
            settings.save("energy-modeller-watts-up-meter.properties");
        }
        File scrapeFile = new File(filename);
        fileTailer = new WattsUpTailer();
        tailer = Tailer.create(scrapeFile, fileTailer, (interval * 1000) / 16, true);
        Thread tailerThread = new Thread(tailer);
        tailerThread.setDaemon(true);
        tailerThread.start();
        System.out.println("Scraping from WattsUp meter file");
    } else {
        try {
            WattsUpConfig config = new WattsUpConfig().withPort(port).scheduleDuration(duration)
                    .withInternalLoggingInterval(interval).withExternalLoggingInterval(interval);
            meter = new WattsUp(config);
            System.out.println("WattsUp Meter Created");
            registerEventListeners(meter);
            System.out.println("WattsUp Meter Connecting");
            meter.connect(false);
            meter.setLoggingModeSerial(1);
            System.out.println("WattsUp Meter Connected " + meter.isConnected());
        } catch (IOException ex) {
            Logger.getLogger(WattsUpMeterDataSourceAdaptor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:adams.gui.tools.FileMonitorPanel.java

/**
 * Monitors the specified file./*w w w.  j av  a2 s.  c o  m*/
 *
 * @param file    the file to monitor
 */
protected void open(File file) {
    Listener listener;

    stopListening();
    listener = new Listener(this, file.getAbsolutePath());
    m_Tailer = Tailer.create(file.getAbsoluteFile(), listener, 100, true);
    m_RecentFilesHandler.addRecentItem(file);
    setCurrentFile(file);
}

From source file:adams.flow.transformer.FileTailer.java

/**
 * Executes the flow item.//  w w w  .  j a  va 2  s .c om
 *
 * @return      null if everything is fine, otherwise error message
 */
@Override
protected String doExecute() {
    String result;
    PlaceholderFile file;
    Listener listener;

    result = null;

    file = null;
    if (m_InputToken.getPayload() instanceof String)
        file = new PlaceholderFile((String) m_InputToken.getPayload());
    else if (m_InputToken.getPayload() instanceof File)
        file = new PlaceholderFile((File) m_InputToken.getPayload());
    else
        result = "Unhandled input type: " + Utils.classToString(m_InputToken.getPayload());

    if (file != null) {
        listener = new Listener(this, file.getAbsolutePath());
        m_Tailer = Tailer.create(file.getAbsoluteFile(), listener, m_Delay, m_End);
    }

    return result;
}

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

/**
 * Starts the console printer thread./*from   w w  w .  j a  v  a  2s  .com*/
 *
 * @param server
 *      the server
 * @param serverLogsFile
 *       the server logs file
 */
public static void startConsolePrinterThread(LdapServer server, File serverLogsFile) {
    MessageConsole messageConsole = ConsolesManager.getDefault().getMessageConsole(server);
    MessageConsoleStream messageStream = messageConsole.newMessageStream();

    /*
     * DIRSTUDIO-1148: Tail the log file and update the console.
     * Tail from end only to avoid overwhelming the system in case the log file is large.
     */
    TailerListener l = new TailerListenerAdapter() {
        public void handle(String line) {
            messageStream.println(line);
        };
    };
    Tailer tailer = Tailer.create(serverLogsFile, l, 1000L, true);

    // Storing the tailer as a custom object in the LDAP Server for later use
    server.putCustomObject(CONSOLE_PRINTER_CUSTOM_OBJECT, tailer);
}

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.//from w w  w .j av a  2s.co m
 * 
 * @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;

}