drapostolos / rdp4j

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

Start Listener in only one cluster in multi host multi cluster environment #33

Open gurujava454 opened 1 month ago

gurujava454 commented 1 month ago

We are adding file poll listener while starting of the server. In multi cluster environment(ex clust1, clust2), Listener is getting added in two clusters. When a file is being added to directory/path, two listener(listeners from clust1 and clus2 ) are getting invoked and two times fileAdded method is calling. Please help me how to avoid this situation getting called two times.

drapostolos commented 1 month ago

Can you please elaborate a bit about your issue. Could you share som example code? How many instances of a DirectoryPoller are you running? Any chance you have two listeners registered in the same DirectoryPoller instance?

gurujava454 commented 1 month ago

try { directoryPoller = DirectoryPoller.newBuilder() .addPolledDirectory(directory) .addListener(new EventListener(this))//EventListener implements DirectoryListener .setPollingInterval(interval, TimeUnit.SECONDS) .setDefaultFileFilter(new RegexFileFilter(mask)) .start(); } catch (Exception e) { log.error(e); } How many instances of a DirectoryPoller are you running? In weblogic server, if we have 4 clusters , DirectoryPoller will run in all 4 clusters. Any chance you have two listeners registered in the same DirectoryPoller instance? yes How do we know that how many listeners registered in the same DirectoryPoller instance?

drapostolos commented 1 month ago

How do we know that how many listeners registered in the same DirectoryPoller instance?

You register listeners like this:

.addListener(new EventListener(this))

...

DirectoryPoller will run in all 4 clusters.

Does this mean you have four DirectoryPoller instances running (one for each cluster) or just one instance with four registered PolledDirectory?

gurujava454 commented 1 month ago

2 rectoryPoller instances running one for each cluster node and 2 listeners listening to one directory. So 2 calls had been called.