Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Writing my first directory polling app - advice anyone?

Posted on 2007-10-17
8
Medium Priority
?
1,182 Views
Last Modified: 2013-11-23
Hello Experts,

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:

Main (args[]){

     while(true){
           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 ;-).
0
Comment
Question by:Lurp
  • 4
  • 3
8 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 1000 total points
ID: 20099106
I think you could use the FileMonitor utility you can find @ http://geosoft.no/software/index.html very well.
0
 

Author Comment

by:Lurp
ID: 20100652
I had thought of that, actually, but I am constrained by what I can bring into the customer environment in terms of outside software. Thus, the question about the Apache Commons project. So, not sure that FileMonitor is going to do it for me. Thank you for the suggestion anyway, it is appreciated!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 20100755
>> I am constrained by what I can bring into the customer environment in terms of outside software.
What do you mean exactly? That FileMonitor is free software you can redistribute and/or modify
under the terms of the GNU Lesser General Public License...

>> Thank you for the suggestion anyway, it is appreciated!
You're welcome. Nice to hear.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Lurp
ID: 20101594

>What do you mean exactly? That FileMonitor is free software you can redistribute and/or modify
under the terms of the GNU Lesser General Public License...

What I mean is that I have to conform to a set software baseline. If FileMonitor is open source, that makes it easier to get it into the environment in which I work. Problem is, I have to jump through many, many hoops to bring in a new product, whether it is freeware, open source, whatever. I was specifically asking about apache commons as we already have many of the commons projects products on the baseline. Having said that, I am having a difficult time ascertaining of those commons products, which might help me in my present task.

So, given the difficulty in getting software approved for use in our environment, we typically wind up rolling our own stuff. Which brings up the second question about tips and tricks and lessons learned.

>You're welcome. Nice to hear.

Of course, my pleasure to spread a little cheer ;-).
0
 
LVL 1

Assisted Solution

by:dleehanson
dleehanson earned 1000 total points
ID: 20103599
I have been digging around the net for a similar project, and think this might be up your alley:

http://svn.apache.org/viewvc/commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/

This is my first time doing a project like this as well, so I hope we get some more pointers and best-practices.

--Charly
0
 

Author Comment

by:Lurp
ID: 20110501

As it turns out, I am writing my own solution. I have come up with four or five base classes and a polling app. Pretty simple, really, though I am sure I will realize issues as I run the thing.
0
 

Author Comment

by:Lurp
ID: 20132620

Well, even though it turns out I will be doing my own thing, I did investigate both to the options posted in this question thread, and did like them both. So, in order to capture this for archival purposes, going to split the points between both of the answers that I liked.

Thanks again, experts!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 20153684
Thanx 4 axxepting
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question