use of ch.cyberduck.core.brick.io.swagger.client.api.FileMigrationsApi in project cyberduck by iterate-ch.
the class BrickFileMigrationFeature method poll.
protected void poll(final BrickApiClient client, final FileActionEntity entity) throws BackgroundException {
final CountDownLatch signal = new CountDownLatch(1);
final ScheduledThreadPool scheduler = new ScheduledThreadPool();
final long timeout = preferences.getLong("brick.migration.interrupt.ms");
final long start = System.currentTimeMillis();
final AtomicReference<BackgroundException> failure = new AtomicReference<>();
try {
scheduler.repeat(() -> {
try {
if (System.currentTimeMillis() - start > timeout) {
failure.set(new ConnectionCanceledException(String.format("Interrupt polling for migration key after %d", timeout)));
signal.countDown();
return;
}
// Poll status
final FileMigrationEntity.StatusEnum migration = new FileMigrationsApi(client).getFileMigrationsId(entity.getFileMigrationId()).getStatus();
switch(migration) {
case COMPLETE:
signal.countDown();
return;
default:
log.warn(String.format("Wait for copy to complete with current status %s", migration));
break;
}
} catch (ApiException e) {
log.warn(String.format("Failure processing scheduled task. %s", e.getMessage()), e);
failure.set(new BrickExceptionMappingService().map(e));
signal.countDown();
}
}, preferences.getLong("brick.migration.interval.ms"), TimeUnit.MILLISECONDS);
Uninterruptibles.awaitUninterruptibly(signal);
if (null != failure.get()) {
throw failure.get();
}
} finally {
scheduler.shutdown();
}
}
Aggregations