e(fx)clipse 1.2.0 – New service to observe a filesystem path

With 1.2.0 the e(fx)clipse core runtime bundle comes with a service who is able to track filesystem modifications. Since Java7 there’s an API to observe filesystem paths and so has the Eclipse Core Resources System which is used inside your Eclipse IDE.

The service we created looks like this:

public interface FilesystemService {
  public enum Kind {
  public Subscription observePath(URI path, BiConsumer<Kind, URI> consumer);
  public Subscription observePath(Path path, BiConsumer<Kind, Path> consumer);
  public boolean applies(URI uri);

and you use it like this:

import org.eclipse.fx.core.Util;
import org.eclipse.fx.core.FilesystemService;
import org.eclipse.fx.core.URI;

public class Sample {
   private static Optional<Subscription> void observe(String pathUri, Consumer<Kind,URI> c) {
    URI uri = URI.createURI(pathUri);
    return Util.lookupService(FilesystemService.class)
       .filter(fs -> fs.applies(uri))
       .map(fs -> fs.observe(uri,c));

   public static void main(String[] args) {
       (kind,uri) -> System.out.println( kind + " => " + uri));

Things to notice:

  • There can be multiple Filesystem Services depending on the URI you want to observe
  • This whole stuff works in plain Java as well as it does in an OSGi-Environment
  • The system is extensible so you could plug-in your own filesystem service for you special filesystem and register it using the Java built-in service loader and the OSGi-Service registry

One thought on “e(fx)clipse 1.2.0 – New service to observe a filesystem path

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s