drapostolos / rdp4j

Remote Directory Poller for Java
MIT License
46 stars 25 forks source link

Can I get directory details along with file name in MyListener? I want to check which directory the mentioned file is added / removed #20

Open Shraddha1685 opened 5 years ago

Shraddha1685 commented 5 years ago

Can I get directory details along with file name in MyListener? I want to check which directory the mentioned file is added / removed / modified. Can I have one listener to poll 10 directories and I get which event is called on which folder?

drapostolos commented 5 years ago

You can add as many PolledDirectory implementations as you wish into the DirectoryPoller. Either via the DirectoryPollerBuilder or the DirectoryPoller instance it self.

The FileElement and PolledDirectory implementations, as exposed by the Listener interfaces, are yours, so you can expose anything you like from those. Just cast to your implementation to get access.

See example below:

    public static void main(String[] args) {
        DirectoryPoller dirPoller = DirectoryPoller.newBuilder()
        .addPolledDirectory(new MyPolledDirectory("some/path"))
        .addPolledDirectory(new MyPolledDirectory("another/path"))
        .addListener(new MyListener())
        .start();

        dirPoller.addPolledDirectory(new MyPolledDirectory("third/path"));

    }

    static class MyListener extends AbstractRdp4jListener {

        @Override
        public void fileAdded(FileAddedEvent event) throws InterruptedException {
            MyPolledDirectory myDir = (MyPolledDirectory) event.getPolledDirectory();
            MyFileElement myFileElement = (MyFileElement) event.getFileElement();
        }
    }