List of usage examples for org.apache.wicket.util.watch IModificationWatcher add
boolean add(final IModifiable modifiable, final IChangeListener<IModifiable> listener);
IModifiable object and an IChangeListener object to call when the modifiable object is modified. From source file:de.micromata.less.LessWicketApplicationInstantiator.java
License:Open Source License
/** * adds a resource watcher entry to the given less source * /*from w ww . j a v a 2s . c om*/ * @param resourceWatcher * @param importedSource */ private void addWatcher(final IModificationWatcher resourceWatcher, final LessSource importedSource) { log.info("adding watcher to less file " + importedSource.getAbsolutePath()); resourceWatcher.add(new org.apache.wicket.util.file.File(new File(importedSource.getAbsolutePath())), new IChangeListener() { @Override public void onChange() { try { compile(); } catch (final Exception e) { log.error("unable to compile less source during watcher for file " + importedSource.getAbsolutePath(), e); } } }); }
From source file:wicket.contrib.groovy.GroovyClassResolver.java
License:Apache License
/** * Load the groovy file and watch for changes. If changes to the groovy * happens, than reload the file.//from w ww. ja v a2s. c om * * @param classname * @param resource * @return Loaded class */ private Class loadGroovyFileAndWatchForChanges(final String classname, final IResourceStream resource) { // Watch file in the future final IModificationWatcher watcher = application.getResourceSettings().getResourceWatcher(true); if (watcher != null) { watcher.add(resource, new IChangeListener() { public void onChange() { try { log.info("Reloading groovy file from " + resource); // Reload file and update cache final Class clazz = loadGroovyFile(classname, resource); log.debug("Groovy file contained definition for class: " + clazz.getName()); } catch (Exception e) { log.error("Unable to load groovyy file: " + resource, e); } } }); } log.info("Loading groovy file from " + resource); return loadGroovyFile(classname, resource); }