Writing my first directory polling app - advice anyone?
Posted on 2007-10-17
I am a bit new to Java, and have been assigned a task to write a program that will do the following:
1. Run on either Linux or Windows as a daemon or service
2. Continuously poll a directory for error logs generated by a separate application
3. If a log file is found, mail the log file to as specified email address
3a. If successfully mailed, move log file to another directory
3b. If not successfully mailed, generate an error log and move file to a directory for future mailing
I sat down and thought about this for a while, and have done some reading. As best as I can figure it, my approach will be to do something like this:
1. Poll directory at specified intervals
2. If file found, spawn new thread that will:
2a. Package up all files found and mail them
2a1. If successful, move to new directory, return status code to calling thread
2a2. If not successful, move to new directory, return status code to calling thread
This is, of course, the highly simplified gist of what I want to do.
My questions are these:
1. I imagine something like this has been done a million times. Is there a package out there (say, from apache-commons) that already accomplishes this?
2. If not, anyone have any "best practice" pointers they would like to provide? Any tips or lessons learned?
I am assigning this question a 500 point value because I suspect I am asking a lot ;-).