rdp4j icon indicating copy to clipboard operation
rdp4j copied to clipboard

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

Open Shraddha1685 opened this issue 6 years ago • 1 comments

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?

Shraddha1685 avatar Dec 12 '18 10:12 Shraddha1685

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();
        }
    }

drapostolos avatar Dec 12 '18 18:12 drapostolos