Examples of WatchService


Examples of java.nio.file.WatchService

  @Override
  public void run() {
    try {
      Path evdev = Paths.get("/dev/input");
     
      WatchService watcher = evdev.getFileSystem().newWatchService();
      evdev.register(watcher, StandardWatchEventKinds.ENTRY_CREATE);
     
      WatchKey watckKey = watcher.take();
      List<WatchEvent<?>> events = watckKey.pollEvents();
      for (WatchEvent event:events) {
        if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
          String name = event.context().toString();
          if (filter.accept(input, name)) {
View Full Code Here

Examples of java.nio.file.WatchService

      process(StandardWatchEventKinds.ENTRY_CREATE, child);
    }

    FileSystem fileSystem = directory.getFileSystem();

    WatchService watcher = fileSystem.newWatchService();

    try {
      WatchKey key = directory.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
      if(key.isValid()){
        process(key);
      }

      while(key.reset()){

        try {
          key = watcher.take();
        } catch(InterruptedException ie){
          break;
        }

        if(key.isValid()){
          process(key);
        }
      }
    } finally {
      watcher.close();
    }
  }
View Full Code Here

Examples of org.uberfire.java.nio.file.WatchService

    @Override
    public WatchService newWatchService()
            throws UnsupportedOperationException, IOException {
        checkClose();
        final WatchService ws = new WatchService() {
            private boolean wsClose = false;

            @Override
            public WatchKey poll() throws ClosedWatchServiceException {
                return events.get( this ).poll();
View Full Code Here

Examples of org.uberfire.java.nio.file.WatchService

            }
        };

        for ( final Map.Entry<WatchService, Queue<WatchKey>> watchServiceQueueEntry : events.entrySet() ) {
            watchServiceQueueEntry.getValue().add( wk );
            final WatchService ws = watchServiceQueueEntry.getKey();
            synchronized ( ws ) {
                ws.notifyAll();
            }
        }
    }
View Full Code Here

Examples of org.uberfire.java.nio.file.WatchService

    }

    @Test
    public void testBatch() throws IOException, InterruptedException {
        final Path init = ioService.get( URI.create( "git://amend-repo-test/readme.txt" ) );
        final WatchService ws = init.getFileSystem().newWatchService();

        ioService.write( init, "init!", new CommentedOption( "User Tester", "message1" ) );
        ioService.write( init, "init 2!", new CommentedOption( "User Tester", "message2" ) );
        {
            List<WatchEvent<?>> events = ws.poll().pollEvents();
            assertEquals( 1, events.size() );//modify readme
        }

        final Path init2 = ioService.get( URI.create( "git://amend-repo-test/readme2.txt" ) );
        ioService.write( init2, "init 3!", new CommentedOption( "User Tester", "message3" ) );
        {
            List<WatchEvent<?>> events = ws.poll().pollEvents();
            assertEquals( 1, events.size() ); // add file
        }
        ioService.write( init2, "init 4!", new CommentedOption( "User Tester", "message4" ) );
        {
            List<WatchEvent<?>> events = ws.poll().pollEvents();
            assertEquals( 1, events.size() );// modify file
        }

        final VersionAttributeView vinit = ioService.getFileAttributeView( init, VersionAttributeView.class );
        final VersionAttributeView vinit2 = ioService.getFileAttributeView( init, VersionAttributeView.class );

        assertEquals( "init 2!", ioService.readAllString( init ) );

        assertNotNull( vinit );
        assertEquals( 2, vinit.readAttributes().history().records().size() );
        assertNotNull( vinit2 );
        assertEquals( 2, vinit2.readAttributes().history().records().size() );

        ioService.startBatch( new FileSystem[]{ init.getFileSystem() } );
        final Path path = ioService.get( URI.create( "git://amend-repo-test/mybatch" + new Random( 10L ).nextInt() + ".txt" ) );
        final Path path2 = ioService.get( URI.create( "git://amend-repo-test/mybatch2" + new Random( 10L ).nextInt() + ".txt" ) );
        ioService.write( path, "ooooo!" );
        //init.file event
        assertNotNull( ws.poll() );
        ioService.write( path, "ooooo wdfs fg sdf!" );
        assertNull( ws.poll() );
        ioService.write( path2, "ooooo222!" );
        assertNull( ws.poll() );
        ioService.write( path2, " sdfsdg sdg ooooo222!" );
        assertNull( ws.poll() );
        ioService.endBatch();
        {
            List<WatchEvent<?>> events = ws.poll().pollEvents();
            assertEquals( 2, events.size() ); //adds files
        }

        final VersionAttributeView v = ioService.getFileAttributeView( path, VersionAttributeView.class );
        final VersionAttributeView v2 = ioService.getFileAttributeView( path2, VersionAttributeView.class );
View Full Code Here

Examples of org.uberfire.java.nio.file.WatchService

        final Path f3 = ioService.get( URI.create( "git://check-amend-repo-test/f3.txt" ) );

        ioService.write( f1, "init f1!" );
        ioService.write( f2, "init f2!" );

        final WatchService ws = f1.getFileSystem().newWatchService();

        ioService.startBatch( new FileSystem[]{ f1.getFileSystem() } );
        ioService.write( f1, "f1-u1!" );
        assertNull( ws.poll() );
        ioService.write( f2, "f2-u1!" );
        assertNull( ws.poll() );
        ioService.write( f3, "f3-u1!" );
        assertNull( ws.poll() );
        ioService.endBatch();

        {
            List<WatchEvent<?>> events = ws.poll().pollEvents();
            assertEquals( 3, events.size() ); //adds files

            final VersionAttributeView v = ioService.getFileAttributeView( f1, VersionAttributeView.class );
            assertNotNull( v );
            assertEquals( 2, v.readAttributes().history().records().size() );

            final VersionAttributeView v2 = ioService.getFileAttributeView( f2, VersionAttributeView.class );
            assertNotNull( v2 );
            assertEquals( 2, v2.readAttributes().history().records().size() );

            final VersionAttributeView v3 = ioService.getFileAttributeView( f3, VersionAttributeView.class );
            assertNotNull( v3 );
            assertEquals( 1, v3.readAttributes().history().records().size() );
        }

        ioService.startBatch( new FileSystem[]{ f1.getFileSystem() } );
        ioService.write( f1, "f1-u1!" );
        assertNull( ws.poll() );
        ioService.write( f2, "f2-u2!" );
        assertNull( ws.poll() );
        ioService.write( f3, "f3-u2!" );
        assertNull( ws.poll() );
        ioService.endBatch();

        {
            List<WatchEvent<?>> events = ws.poll().pollEvents();
            assertEquals( 2, events.size() ); //adds files

            final VersionAttributeView v = ioService.getFileAttributeView( f1, VersionAttributeView.class );
            assertNotNull( v );
            assertEquals( 2, v.readAttributes().history().records().size() );
View Full Code Here

Examples of org.uberfire.java.nio.file.WatchService

            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() );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.