@Override
    public WatchKey register(final Watchable folder,
                             final WatchEvent.Kind<?>[] events,
                             final WatchEvent.Modifier... modifiers)
        throws IOException {
        if(log.isInfoEnabled()) {
            log.info(String.format("Register file %s for events %s", folder, Arrays.toString(events)));
        }
        final Pointer[] values = {
            CFStringRef.toCFString(folder.toString()).getPointer()};

        final MacOSXWatchKey key = new MacOSXWatchKey(folder, this, events);

        final double latency = 1.0; // Latency in seconds

        final Map<File, Long> timestamps = createLastModifiedMap(new File(folder.toString()));
        final FSEvents.FSEventStreamCallback callback = new Callback(key, timestamps);
        final FSEventStreamRef stream = library.FSEventStreamCreate(
            Pointer.NULL, callback, Pointer.NULL,
            library.CFArrayCreate(null, values, CFIndex.valueOf(1), null),
            -1, latency,
            kFSEventStreamCreateFlagNoDefer);
        final CountDownLatch lock = new CountDownLatch(1);
        final CFRunLoop loop = new CFRunLoop(lock, stream);
        threadFactory.newThread(loop).start();
        Uninterruptibles.awaitUninterruptibly(lock);
        loops.put(key, loop);
        callbacks.put(key, callback);
        return key;
    }
@Test
    public void testRegister() throws Exception {
        final RegisterWatchService fs = new FSEventWatchService();
        final Watchable folder = Paths.get(
            File.createTempFile(UUID.randomUUID().toString(), "t").getParent());
        final WatchKey key = fs.register(folder, new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY});
        assertTrue(key.isValid());
        fs.close();
        assertFalse(key.isValid());
    }