Example usage for org.apache.hadoop.hdfs DFSInotifyEventInputStream take

List of usage examples for org.apache.hadoop.hdfs DFSInotifyEventInputStream take

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs DFSInotifyEventInputStream take.

Prototype

public EventBatch take() throws IOException, InterruptedException, MissingEventsException 

Source Link

Document

Returns the next batch of events in the stream, waiting indefinitely if a new batch is not immediately available.

Usage

From source file:INotifyUtil.java

License:Apache License

/**
 * Poll events and output the details./*from w w w . j  a  v  a2 s  .c  om*/
 * Ctrl + C to stop polling.
 * @param args the parameter is not used.
 * @throws IOException if configuration error or I/O error happens.
 */
public static void main(String args[]) throws IOException {
    Configuration conf = new HdfsConfiguration();
    DFSClient client = new DFSClient(DFSUtilClient.getNNAddress(conf), conf);
    DFSInotifyEventInputStream iStream = client.getInotifyEventStream();
    while (true) {
        try {
            EventBatch eventBatch = iStream.take();
            for (Event event : eventBatch.getEvents()) {
                System.out.println(event.toString());
            }
        } catch (InterruptedException e) {
            System.out.println("Interrupted. Exiting...");
            return;
        } catch (MissingEventsException e) {
            e.printStackTrace();
            return;
        }
    }
}