diff --git a/core/src/main/java/ch/cyberduck/core/shared/AbstractSchedulerFeature.java b/core/src/main/java/ch/cyberduck/core/shared/AbstractSchedulerFeature.java index e74571ad5a7..d997e4a79b6 100644 --- a/core/src/main/java/ch/cyberduck/core/shared/AbstractSchedulerFeature.java +++ b/core/src/main/java/ch/cyberduck/core/shared/AbstractSchedulerFeature.java @@ -43,11 +43,38 @@ public AbstractSchedulerFeature(final long period) { @Override public Void repeat(final SessionPool pool, final PasswordCallback callback) { - scheduler.repeat(() -> { + scheduler.repeat(new PoolOperator(pool, callback), period, TimeUnit.MILLISECONDS); + return null; + } + + public Void single(final Session session, final PasswordCallback callback, final Path file) { + scheduler.schedule(new SessionOperator(session, callback, file), 0L, TimeUnit.MILLISECONDS); + return null; + } + + protected abstract R operate(Session session, PasswordCallback callback, Path file) throws BackgroundException; + + @Override + public void shutdown() { + log.debug("Shutting down scheduler thread pool"); + scheduler.shutdown(); + } + + private class PoolOperator implements Runnable { + private final SessionPool pool; + private final PasswordCallback callback; + + public PoolOperator(final SessionPool pool, final PasswordCallback callback) { + this.pool = pool; + this.callback = callback; + } + + @Override + public void run() { try { final Session session = pool.borrow(BackgroundActionState.running); try { - this.operate(session, callback, null); + AbstractSchedulerFeature.this.operate(session, callback, null); } finally { pool.release(session, null); @@ -55,24 +82,41 @@ public Void repeat(final SessionPool pool, final PasswordCallback callback) { } catch(LoginFailureException | ConnectionCanceledException e) { log.warn("Cancel processing scheduled task after failure {}", e.getMessage()); - this.shutdown(); + AbstractSchedulerFeature.this.shutdown(); } catch(BackgroundException e) { log.warn("Failure processing scheduled task. {}", e.getMessage(), e); } catch(Exception e) { log.error("Failure processing scheduled task {}", e.getMessage(), e); - this.shutdown(); + AbstractSchedulerFeature.this.shutdown(); } - }, period, TimeUnit.MILLISECONDS); - return null; + } } - protected abstract R operate(Session session, PasswordCallback callback, Path file) throws BackgroundException; + private class SessionOperator implements Runnable { + private final Session session; + private final PasswordCallback callback; + private final Path file; - @Override - public void shutdown() { - log.debug("Shutting down scheduler thread pool"); - scheduler.shutdown(); + public SessionOperator(final Session session, final PasswordCallback callback, final Path file) { + this.session = session; + this.callback = callback; + this.file = file; + } + + @Override + public void run() { + try { + AbstractSchedulerFeature.this.operate(session, callback, file); + } + catch(BackgroundException e) { + log.warn("Failure processing scheduled task. {}", e.getMessage(), e); + } + catch(Exception e) { + log.error("Failure processing scheduled task {}", e.getMessage(), e); + AbstractSchedulerFeature.this.shutdown(); + } + } } } diff --git a/dracoon/src/main/java/ch/cyberduck/core/sds/SDSEncryptionBulkFeature.java b/dracoon/src/main/java/ch/cyberduck/core/sds/SDSEncryptionBulkFeature.java index 47bd5f9e690..f1c309014db 100644 --- a/dracoon/src/main/java/ch/cyberduck/core/sds/SDSEncryptionBulkFeature.java +++ b/dracoon/src/main/java/ch/cyberduck/core/sds/SDSEncryptionBulkFeature.java @@ -99,7 +99,7 @@ public void post(final Transfer.Type type, final Map