private FileSystem registerFS( final FileSystem fs, final FileSystemType type ) { checkNotNull( "type", type ); if ( fs == null ) { return fs; } if ( ioWatchService != null ) { ioWatchService.addWatchService( fs.newWatchService() ); } synchronized ( this ) { List<FileSystem> fsList = fileSystems.get( type ); if ( fsList == null ) { fsList = new ArrayList<FileSystem>(); fileSystems.put( type, fsList ); } fsList.add( fs ); } return fs; }
@Test @Ignore public void testDaemob() throws InterruptedException { final URI newRepo = URI.create( "git://repo-name" ); final Map<String, ?> env = new HashMap<String, Object>() {{ put( "init", Boolean.TRUE ); }}; FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); WatchService ws = null; ws = fs.newWatchService(); final Path path = fs.getRootDirectories().iterator().next(); path.register( ws, StandardWatchEventKind.ENTRY_CREATE, StandardWatchEventKind.ENTRY_MODIFY, StandardWatchEventKind.ENTRY_DELETE, StandardWatchEventKind.ENTRY_RENAME ); final WatchKey k = ws.take(); final List<WatchEvent<?>> events = k.pollEvents(); for ( WatchEvent object : events ) { if ( object.kind() == StandardWatchEventKind.ENTRY_MODIFY ) { System.out.println( "Modify: " + object.context().toString() ); } if ( object.kind() == StandardWatchEventKind.ENTRY_RENAME ) { System.out.println( "Rename: " + object.context().toString() ); } if ( object.kind() == StandardWatchEventKind.ENTRY_DELETE ) { System.out.println( "Delete: " + object.context().toString() ); } if ( object.kind() == StandardWatchEventKind.ENTRY_CREATE ) { System.out.println( "Created: " + object.context().toString() ); } } }