drapostolos / rdp4j

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

Add a port field #4

Closed rootrepo closed 9 years ago

rootrepo commented 9 years ago

@drapostolos Nice one! thanks for your works Indeed a timely help !! , As a small suggestion to your Grt Work , Why didn't you add "port" field in FtpDirectory.class(since I'm using specific port, I added manually )

I'm facing an issue of not being notified when a file is changed in remote loc more than 2 times inside the polled directory.... : ( pls post any work around ..Thanks in advance!!

drapostolos commented 9 years ago

Thanks for the feedback :)

The FtpDirectory example, is just an example. I tried to keep the example as short as possible just to give an idea how the rdp4j library can be used. How about adding FtpDirectory (using apache Ftp client ) implementation as a separate library? Would you find that useful?

I'm not sure I understand your issue, could you please describe it in more detail? and preferable in a separate issue (to keep separate issues apart.).

/Alex

rootrepo commented 9 years ago

I think I misunderstood the thread calling and sleeping methods

String host = "192.168.100.1";
        String workingDirectory = "/test";
        String username = "username";
        String password = "password@121";
        int port = 26;
        PolledDirectory polledDirectory = new FtpDirectory(host, workingDirectory, username, password, port);

DirectoryPoller dp = DirectoryPoller.newBuilder()
            .addPolledDirectory(polledDirectory)
            .addListener(new MyListener())
            .enableFileAddedEventsForInitialContent()
            .setPollingInterval(4, TimeUnit.SECONDS)//   assume as t1= 4 secs
            .start();

        TimeUnit.HOURS.sleep(2);// t2 = 2 hrs`

Above is your code , Here are my understandings : 1) here directory poller thread checks for any poll in the listeners for every t1 secs ,Am I right? 2) this thread will be executing for 2 hours of duration 3)The listener checks only once in 4 secs .

My Aim: 1) To listen to a log folder. 2) To notify when new log is added or new log file is created

When I put the code in debug mode ,I found

Thread [pool-1-thread-1] (Running)  

is runnning( even after dp.stop()) .

I'm a newbie to threads and FTP's When I do around your code I saw I saw "FileElementCacher.class" Does it preventing me from showing modification.

Please correct me If I'm wrong. @drapostolos I am stuck, Suggest me a good config for main class for implementing in log environment(frequent logs will happen) I was redirected to GIT from StackOverflow !!

cheers Ajay

drapostolos commented 9 years ago

This part is just there as an example: TimeUnit.HOURS.sleep(2); It is meant for your application to do whatever it does, until something triggers it to shut down. Then you call dp.stop

You are correct, your code snipped will ask the FTP server for the content of the PolledDirectory every 4th second. The current content is then compared with previous content.

The FileElementCacher class holds a snapshot view of the lastModified date for the file, so it can be used when comparing it with the next coming poll. If lastModified() method returns a "live" date for each call, then it would not be possible to use the value to compare with the value from the previous or next poll.

Regarding the Thread [pool-1-thread-1] (Running): I'm not sure what that is. I will have a look at it. I'm internally using the java.util.concurrent.Executors.newSingleThreadExecutor() when polling Directories sequentially. It might be the case that this executor keeps its working thread running in idle mode.

drapostolos commented 9 years ago

Seems this is a bug: Thread [pool-1-thread-1] (Running):

Will fix this in next release. Thanks for reporting it.

drapostolos commented 9 years ago

Created a new issue for the bug (See issue #7) and closing this.