@Test public void testRun() throws Exception { final Host host = new Host(new TestProtocol()); final Session<?> session = new NullSession(host) { @Override public AttributedList<Path> list(final Path file, final ListProgressListener listener) { return new AttributedList<>(Collections.singletonList(new Path("/home/jenkins/f", EnumSet.of(Path.Type.file)))); } }; final PathCache cache = new PathCache(1); final SessionListWorker worker = new SessionListWorker(cache, new Path("/home/jenkins", EnumSet.of(Path.Type.directory)), new DisabledListProgressListener()); final AttributedList<Path> list = worker.run(session); assertFalse(list.isEmpty()); assertFalse(cache.containsKey(new Path("/home/jenkins", EnumSet.of(Path.Type.directory)))); worker.cleanup(list); assertTrue(cache.containsKey(new Path("/home/jenkins", EnumSet.of(Path.Type.directory)))); }
@Override public AttributedList<Path> run(final Session<?> session) throws BackgroundException { try { if(this.isCached()) { final AttributedList<Path> list = cache.get(directory); listener.chunk(directory, list); return list; } final ListService service = session.getFeature(ListService.class).withCache(cache); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", service)); } return service.list(directory, listener); } catch(ListCanceledException e) { return e.getChunk(); } }
SessionListWorker extends Worker<AttributedList<Path>> { @Override public AttributedList<Path> run(final Session<?> session) throws BackgroundException { try { if(this.isCached()) { final AttributedList<Path> list = cache.get(directory); listener.chunk(directory, list); return list; } final ListService service = session.getFeature(ListService.class).withCache(cache); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", service)); } return service.list(directory, listener); } catch(ListCanceledException e) { return e.getChunk(); } } }
SessionListWorker extends Worker<AttributedList<Path>> { @Override public AttributedList<Path> run(final Session<?> session) throws BackgroundException { try { if(this.isCached()) { final AttributedList<Path> list = cache.get(directory); listener.chunk(directory, list); return list; } final ListService service = session.getFeature(ListService.class).withCache(cache); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", service)); } return service.list(directory, listener); } catch(ListCanceledException e) { return e.getChunk(); } } SessionListWorker(final Cache<Path> cache, final Path directory, final ListProgressListener listener); }
SessionListWorker extends Worker<AttributedList<Path>> { @Override public AttributedList<Path> run(final Session<?> session) throws BackgroundException { try { if(this.isCached()) { final AttributedList<Path> list = cache.get(directory); listener.chunk(directory, list); return list; } final ListService service = session.getFeature(ListService.class).withCache(cache); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", service)); } return service.list(directory, listener); } catch(ListCanceledException e) { return e.getChunk(); } } SessionListWorker(final Cache<Path> cache, final Path directory, final ListProgressListener listener); @Override AttributedList<Path> run(final Session<?> session); @Override void cleanup(final AttributedList<Path> list); @Override String getActivity(); @Override AttributedList<Path> initialize(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
SessionListWorker extends Worker<AttributedList<Path>> { @Override public AttributedList<Path> run(final Session<?> session) throws BackgroundException { try { if(this.isCached()) { final AttributedList<Path> list = cache.get(directory); listener.chunk(directory, list); return list; } final ListService service = session.getFeature(ListService.class).withCache(cache); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", service)); } return service.list(directory, listener); } catch(ListCanceledException e) { return e.getChunk(); } } SessionListWorker(final Cache<Path> cache, final Path directory, final ListProgressListener listener); @Override AttributedList<Path> run(final Session<?> session); @Override void cleanup(final AttributedList<Path> list); @Override String getActivity(); @Override AttributedList<Path> initialize(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }