2

I want to create a servlet to be contained within Tomcat which uses Jnotify (probably but open to suggestions) to monitor a directory for changes.

I would use Java 7 and the NIO stuff but our production systems run Ubuntu 10.04 and I want to stick with stuff currently which is mostly in the repositories and in deb packages for deployment reasons.

My question concerns how I would integrate Jnotify into a my Tomcat servelts. My think at present is that I create a servlet using the GenericServlet class which in the init() method sets up the watch on the directories I want. I then somehow (this is the bit I don't understand) call the service() method when ever I get activity on the directory. I could then have a Listener which does an action on the directory (in this case moves files)

Or I could create a new protocol handler (e.g use PoolTcpEndpoint as a starting point), but its not a protocol so this seems stupid.

Or there is a better way? The only reason behind using Tomcat is that a lot of our other logic is held within our tomcat servers. If there is a way to Daemonise Java and get an event driven architecture in another fashion then I'm open minded, but I wouldn't want to do something like use Jetty for instance as this would be another piece of technology to add to the stack to support which isn't possible.

Look forward to hearing your thoughts.

Thanks

David
  • 139
  • 1
  • 8

1 Answers1

0

The bit I am unclear about is how visible you want this functionality to be ? (within a single servlet? to all servlets within the Tomcat instance? to resources outside the Tomcat instance?)

If to your other servlets, you could register (from a servlet) an interface in the Global JNDI, which can then be retrieved by other servlets and to which they may add a listener.

To resources outside Tomcat, you could expose an RMI object or a simple REST type service with a COMET like polling. If you have access to servlet 3.0, you can even implement asynchronous calls.

Bruno Grieder
  • 22,490
  • 7
  • 57
  • 88