Open PetrToman opened 12 years ago
Good suggestion, this has been implemented in Encog 3.2. Also ripped out the old code that manually kept the project tree updated.
Are you aware that is a Java 7.0 feature? It is breaking the automated build, since the build server is not upgraded to 7.0. Do we REALLY want to force an upgrade of Encog to 7.0 for such a trivial feature???
Did not realize this was 7.0 when I implemented it. That explains a few emails I got about nio compile errors from people. Okay, yes we do not want to force 7.0 a this point. I checked, 7.0 is not part of the standard centos install, so it is "non-trivial" to upgrade our build server. Given that this is not officially supported by a distro as large as cent, I really don't think we want to force 7.0 at this point.
It is too late to roll back this change, as there have been quite a few other changes since. So I will have to do that manually. Thanks for the info Seema.
I will reassign this issue to future Encog release, for when we officially upgrade to 7.0.
Reopening this issue to address JDK6 compile issues.
Sorry, I should have noticed, WatchService requires Java 7. I suggest to make a fallback for Java 6 using http://commons.apache.org/vfs/apidocs/org/apache/commons/vfs2/impl/DefaultFileMonitor.html. A simple wrapper class like this would do the job:
public class MonitorService implements FileListener
{
public MonitorService(String folder)
{
boolean useWatchService = false;
try {
getClass().getClassLoader().loadClass("java.nio.file.WatchService");
useWatchService = true;
} catch(ClassNotFoundException ex) {}
if (useWatchService) {
// setup WatchService to call refresh() upon a change
// (use reflection to avoid Java 6 conflicts)
}
else {
FileSystemManager fsManager = VFS.getManager();
FileObject listendir = fsManager.resolveFile(folder);
DefaultFileMonitor fm = new DefaultFileMonitor(this);
fm.setRecursive(false);
fm.addFile(listendir);
fm.start();
}
}
public void fileCreated(FileChangeEvent event) throws Exception {
refresh();
}
public void fileDeleted(FileChangeEvent event) throws Exception {
refresh();
}
public void fileChanged(FileChangeEvent event) throws Exception {
refresh();
}
/**
* Called upon a change.
*/
private void refresh()
{
// ...
}
}
PS: Alternatives: http://jpathwatch.wordpress.com, http://jnotify.sourceforge.net (but these are using native libs).
For now did a rollback. Will evaluate the best way to do this, or wait for Encog to require Java 7.
Sometimes project files (left pane) in Workbench get out of sync. Currently, "Refresh" command in the popup menu can be used to synchronize. However, there is a better way to ensure proper synchronization, which allows replacing manual refresh completely - by means of WatchService (see http://docs.oracle.com/javase/tutorial/essential/io/notification.html).