aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Daemon for polling directory for files and uploading the files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Daemon for polling directory for files and uploading the files" Watch "Daemon for polling directory for files and uploading the files" New topic
Author

Daemon for polling directory for files and uploading the files

Sheetal Tiwari
Greenhorn

Joined: May 12, 2009
Posts: 18
Hi,

I wanted to code for a daemon that would check the directory for files with particular naming continuously.
Once it finds those files it should upload those into DB.

One of the approaches that I thought of is to create a servlet that would start a thread which would start polling for the files.
Once the file is found it would invoke a stateless session Bean that would handle the upload logic.

Please suggest/ comment about the approach.Also if you have some references regarding this functionality, kindly share it across.

Thank you.


SCJP, OCEJWCD
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


Where are these files located? On the client machine? Or do they arrive on the server? If it's the former, you would need to have a client select the file for upload and press a button that would submit the request. If it's the later, a program local to the server and that executes the main method is sufficient.

ram.
Sheetal Tiwari
Greenhorn

Joined: May 12, 2009
Posts: 18
The files will be put onto the server through FTP.
The purpose is to automate the loading part of the files. This would be a daemon that would conntinuously look for files and send them for upload.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

A main method which has an infinite loop polling the directory with a sleep() in between would be simple and sufficient enough.
You could even move that logic to a thread and have the main method kick it off.

But servlets and ejbs for this? Why do you have to make it complicated? Is there a control that does not allow stand alone programs on a production server box?

ram.
Sheetal Tiwari
Greenhorn

Joined: May 12, 2009
Posts: 18
Yes there is a limitiation on use of stand alone applications on production.
Also there is a requirement to prevent direct access to load functionality.That is why thought of shielding it with stateless session beans.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Also there is a requirement to prevent direct access to load functionality.That is why thought of shielding it with stateless session beans.


Spawn the thread from a ServletContextListener.

ram.
Mark Kiami
Greenhorn

Joined: Apr 21, 2010
Posts: 5
Is it possible to use an EJB Timer in this case?
An EJB Timer is a SLSB that can run a business logic periodically, they are managed by the Timer Server of the EJB Container.
 
jQuery in Action, 2nd edition
 
subject: Daemon for polling directory for files and uploading the files