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

4

1 回答 1

0

我不清楚的一点是你希望这个功能有多明显?(在单个 servlet 内?到 Tomcat 实例内的所有 servlet?到 Tomcat 实例外的资源?)

如果对于您的其他 servlet,您可以(从 servlet)在 Global JNDI 中注册一个接口,然后其他 servlet 可以检索该接口,并且可以向其中添加一个侦听器。

对于 Tomcat 之外的资源,您可以公开一个 RMI 对象或一个简单的 REST 类型的服务,该服务具有类似 COMET 的轮询。如果您可以访问 servlet 3.0,您甚至可以实现异步调用。

于 2012-03-12T16:50:47.933 回答