@Test public void testAwait() throws Exception { final Host host = new Host(new TestProtocol(), "localhost", new Credentials("u", "p")); final Transfer transfer = new UploadTransfer(host, new Path("/t", EnumSet.of(Path.Type.directory)), new NullLocal("l")); final LoginConnectionService connection = new TestLoginConnectionService(); final ConcurrentTransferWorker worker = new ConcurrentTransferWorker( new DefaultSessionPool(connection, new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), PathCache.empty(), new DisabledTranscriptListener(), host), SessionPool.DISCONNECTED, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt(), new DisabledTransferErrorCallback(), new DisabledLoginCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledNotificationService() ); int workers = 1000; final CountDownLatch entry = new CountDownLatch(workers); for(int i = 0; i < workers; i++) { worker.submit(new TransferWorker.TransferCallable() { @Override public TransferStatus call() { entry.countDown(); return new TransferStatus().complete(); } }); } worker.await(); assertEquals(0, entry.getCount()); worker.cleanup(true); }
@Override public void await() throws BackgroundException { while(size.get() > 0) { try { if(log.isInfoEnabled()) { log.info(String.format("Await completion for %d submitted tasks in queue", size.get())); } final TransferStatus status = completion.take().get(); if(log.isInfoEnabled()) { log.info(String.format("Finished task with return value %s", status)); } } catch(InterruptedException e) { log.warn(String.format("Unhandled failure %s", e)); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new DefaultExceptionMappingService().map(e.getCause()); } finally { size.decrementAndGet(); } } }
ConcurrentTransferWorker extends AbstractTransferWorker { @Override public void await() throws BackgroundException { while(size.get() > 0) { try { if(log.isInfoEnabled()) { log.info(String.format("Await completion for %d submitted tasks in queue", size.get())); } final TransferStatus status = completion.take().get(); if(log.isInfoEnabled()) { log.info(String.format("Finished task with return value %s", status)); } } catch(InterruptedException e) { log.warn(String.format("Unhandled failure %s", e)); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new DefaultExceptionMappingService().map(e.getCause()); } finally { size.decrementAndGet(); } } } }
ConcurrentTransferWorker extends AbstractTransferWorker { @Override public void await() throws BackgroundException { while(size.get() > 0) { try { if(log.isInfoEnabled()) { log.info(String.format("Await completion for %d submitted tasks in queue", size.get())); } final TransferStatus status = completion.take().get(); if(log.isInfoEnabled()) { log.info(String.format("Finished task with return value %s", status)); } } catch(InterruptedException e) { log.warn(String.format("Unhandled failure %s", e)); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new DefaultExceptionMappingService().map(e.getCause()); } finally { size.decrementAndGet(); } } } ConcurrentTransferWorker(final SessionPool source,
                                    final SessionPool destination,
                                    final Transfer transfer,
                                    final TransferOptions options,
                                    final TransferSpeedometer meter,
                                    final TransferPrompt prompt,
                                    final TransferErrorCallback error,
                                    final ConnectionCallback connect,
                                    final ProgressListener progressListener,
                                    final StreamListener streamListener,
                                    final NotificationService notification);  ConcurrentTransferWorker(final SessionPool source,
                                    final SessionPool destination,
                                    final Transfer transfer,
                                    final ThreadPool.Priority priority,
                                    final TransferOptions options,
                                    final TransferSpeedometer meter,
                                    final TransferPrompt prompt,
                                    final TransferErrorCallback error,
                                    final ConnectionCallback connect,
                                    final ProgressListener progressListener,
                                    final StreamListener streamListener,
                                    final NotificationService notification); }
ConcurrentTransferWorker extends AbstractTransferWorker { @Override public void await() throws BackgroundException { while(size.get() > 0) { try { if(log.isInfoEnabled()) { log.info(String.format("Await completion for %d submitted tasks in queue", size.get())); } final TransferStatus status = completion.take().get(); if(log.isInfoEnabled()) { log.info(String.format("Finished task with return value %s", status)); } } catch(InterruptedException e) { log.warn(String.format("Unhandled failure %s", e)); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new DefaultExceptionMappingService().map(e.getCause()); } finally { size.decrementAndGet(); } } } ConcurrentTransferWorker(final SessionPool source,
                                    final SessionPool destination,
                                    final Transfer transfer,
                                    final TransferOptions options,
                                    final TransferSpeedometer meter,
                                    final TransferPrompt prompt,
                                    final TransferErrorCallback error,
                                    final ConnectionCallback connect,
                                    final ProgressListener progressListener,
                                    final StreamListener streamListener,
                                    final NotificationService notification);  ConcurrentTransferWorker(final SessionPool source,
                                    final SessionPool destination,
                                    final Transfer transfer,
                                    final ThreadPool.Priority priority,
                                    final TransferOptions options,
                                    final TransferSpeedometer meter,
                                    final TransferPrompt prompt,
                                    final TransferErrorCallback error,
                                    final ConnectionCallback connect,
                                    final ProgressListener progressListener,
                                    final StreamListener streamListener,
                                    final NotificationService notification); @Override Future<TransferStatus> submit(final TransferCallable callable); @Override void await(); @Override void cleanup(final Boolean result); @Override String toString(); }
ConcurrentTransferWorker extends AbstractTransferWorker { @Override public void await() throws BackgroundException { while(size.get() > 0) { try { if(log.isInfoEnabled()) { log.info(String.format("Await completion for %d submitted tasks in queue", size.get())); } final TransferStatus status = completion.take().get(); if(log.isInfoEnabled()) { log.info(String.format("Finished task with return value %s", status)); } } catch(InterruptedException e) { log.warn(String.format("Unhandled failure %s", e)); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new DefaultExceptionMappingService().map(e.getCause()); } finally { size.decrementAndGet(); } } } ConcurrentTransferWorker(final SessionPool source,
                                    final SessionPool destination,
                                    final Transfer transfer,
                                    final TransferOptions options,
                                    final TransferSpeedometer meter,
                                    final TransferPrompt prompt,
                                    final TransferErrorCallback error,
                                    final ConnectionCallback connect,
                                    final ProgressListener progressListener,
                                    final StreamListener streamListener,
                                    final NotificationService notification);  ConcurrentTransferWorker(final SessionPool source,
                                    final SessionPool destination,
                                    final Transfer transfer,
                                    final ThreadPool.Priority priority,
                                    final TransferOptions options,
                                    final TransferSpeedometer meter,
                                    final TransferPrompt prompt,
                                    final TransferErrorCallback error,
                                    final ConnectionCallback connect,
                                    final ProgressListener progressListener,
                                    final StreamListener streamListener,
                                    final NotificationService notification); @Override Future<TransferStatus> submit(final TransferCallable callable); @Override void await(); @Override void cleanup(final Boolean result); @Override String toString();  }