Is There a Sophisticated File System Monitor for Java Which Is Freeware or Open Source

Is there a sophisticated file system monitor for Java which is freeware or open source?

JNotify seems to do what you require.

Polling a filesystem (say, a directory for update time changes) won't impose a significant load on your system, and shouldn't be discounted. Apps like Tomcat etc. use this for managing hot deploys with few problems.

It's not a lot of help now, but the upcoming Java 7 has a WatchService precisely for this.

Java: Keep track of files that are touched in the OS

Apache commons io library, if you want to use with Java 6.*

extending more: On a second look here is question in SO { Is there a sophisticated file system monitor for Java which is freeware or open source? } It may be the one Roflcoptr is interested. It talks about http://jnotify.sourceforge.net/. I did not use that for getting info on reading, though.

Automated Ant build - any open source projects that discover changes in a file system to fire off a build?

Since you are using ant I assume a java based directory polling program will help here. You can write a program using IO notification api

Notes from the page

When to Use and Not Use This API

The Watch Service API is designed for applications that need to be
notified about file change events. It is well suited for any
application, like an editor or IDE, that potentially has many open
files and needs to ensure that the files are synchronized with the
file system. It is also well suited for an application server that
watches a directory, perhaps waiting for .jsp or .jar files to drop,
in order to deploy them.

This API is not designed for indexing a hard drive. Most file system
implementations have native support for file change notification. The
Watch Service API takes advantage of this support where available.
However, when a file system does not support this mechanism, the Watch
Service will poll the file system, waiting for events.

Edit

After I wrote that this question and its answer seems to be more useful here: Is there a sophisticated file system monitor for Java which is freeware or open source?

How can I receive Windows filesystem events in Java?

I think this is one of the key features of Java 7 when it is more available. Example code from Sun's blog on Java 7:

import static java.nio.file.StandardWatchEventKind.*;

Path dir = ...;
try {
WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
} catch (IOException x) {
System.err.println(x);
}

In Java, what is the best/safest pattern for monitoring a file being appended to?

Since Java 7 there has been the newWatchService() method on the FileSystem class.

However, there are some caveats:

  • It is only Java 7
  • It is an optional method
  • it only watches directories, so you have to do the file handling yourself, and worry about the file moving etc

Before Java 7 it is not possible with standard APIs.

I tried the following (polling on a 1 sec interval) and it works (just prints in processing):

  private static void monitorFile(File file) throws IOException {
final int POLL_INTERVAL = 1000;
FileReader reader = new FileReader(file);
BufferedReader buffered = new BufferedReader(reader);
try {
while(true) {
String line = buffered.readLine();
if(line == null) {
// end of file, start polling
Thread.sleep(POLL_INTERVAL);
} else {
System.out.println(line);
}
}
} catch(InterruptedException ex) {
ex.printStackTrace();
}
}

As no-one else has suggested a solution which uses a current production Java I thought I'd add it. If there are flaws please add in comments.

Monitor file/folders to get change notifications in UNIX

If you use Java 7, you can use the WatchService API to monitor changes to the file system.

If you are stuck with Java 6-, you can have a look at some alternatives proposed in this post or this other one.

How do I create a monitor for a specific directory?

If you can't wait for Java 7 and the WatchService you'll have to do something like this:

final File watched = new File("[path of directory to watch]");
long lastModified = watched.lastModified();
while(true) {
if (watched.lastModified() > lastModified) {
// Change happened in the directory do what you want.
}
Thread.sleep(2000); // 2 second interval
}

java: open-source APM (application performance management)

i don't think that you can do full-featured profiling of distributed request across number of JVM's - AppDynamics from what i can remember understands the EE stuff - like calling DB, EJB, RMI, or remote webservice - however it still works in scope of JVM.

Isn't it suffient in your case just to use java profiler (like yourkit, jprofiler)?



Related Topics



Leave a reply



Submit