Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active September 13, 2020 22:25
Show Gist options
  • Select an option

  • Save jayhuang75/8d2a2f99739394366068dee4344f7804 to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/8d2a2f99739394366068dee4344f7804 to your computer and use it in GitHub Desktop.
hdfs-file-notifiy-java-implementation
HdfsAdmin admin = new HdfsAdmin(URI.create(args[0]), new Configuration());
DFSInotifyEventInputStream eventStream = admin.getInotifyEventStream(lastReadTxid);
while (true) {
EventBatch batch = eventStream.take();
System.out.println("TxId = " + batch.getTxid());
for (Event event : batch.getEvents()) {
System.out.println("event type = " + event.getEventType());
switch (event.getEventType()) {
case CREATE:
CreateEvent createEvent = (CreateEvent) event;
System.out.println(" path = " + createEvent.getPath());
System.out.println(" owner = " + createEvent.getOwnerName());
System.out.println(" ctime = " + createEvent.getCtime());
break;
case UNLINK:
UnlinkEvent unlinkEvent = (UnlinkEvent) event;
System.out.println(" path = " + unlinkEvent.getPath());
System.out.println(" timestamp = " + unlinkEvent.getTimestamp());
break;
default:
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment