/** * Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket * deletion succeeds or {@code timeout} expires. To allow for the timeout, this method uses a * separate thread to send the delete requests. Use {@link #forceDelete(Storage storage, String * bucket)} if spawning an additional thread is undesirable, such as in the App Engine production * runtime. * * @param storage the storage service to be used to issue requests * @param bucket the bucket to be deleted * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @param userProject the project to bill for requester-pays buckets (or "") * @return true if deletion succeeded, false if timeout expired * @throws InterruptedException if the thread deleting the bucket is interrupted while waiting * @throws ExecutionException if an exception was thrown while deleting bucket or bucket objects */ public static Boolean forceDelete( Storage storage, String bucket, long timeout, TimeUnit unit, String userProject) throws InterruptedException, ExecutionException { ExecutorService executor = Executors.newSingleThreadExecutor(); Future<Boolean> future = executor.submit(new DeleteBucketTask(storage, bucket, userProject)); try { return future.get(timeout, unit); } catch (TimeoutException ex) { return false; } finally { executor.shutdown(); } }
/** * Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket * deletion succeeds or {@code timeout} expires. To allow for the timeout, this method uses a * separate thread to send the delete requests. Use {@link #forceDelete(Storage storage, String * bucket)} if spawning an additional thread is undesirable, such as in the App Engine production * runtime. * * @param storage the storage service to be used to issue requests * @param bucket the bucket to be deleted * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @param userProject the project to bill for requester-pays buckets (or "") * @return true if deletion succeeded, false if timeout expired * @throws InterruptedException if the thread deleting the bucket is interrupted while waiting * @throws ExecutionException if an exception was thrown while deleting bucket or bucket objects */ public static Boolean forceDelete( Storage storage, String bucket, long timeout, TimeUnit unit, String userProject) throws InterruptedException, ExecutionException { ExecutorService executor = Executors.newSingleThreadExecutor(); Future<Boolean> future = executor.submit(new DeleteBucketTask(storage, bucket, userProject)); try { return future.get(timeout, unit); } catch (TimeoutException ex) { return false; } finally { executor.shutdown(); } }
/** * Deletes a bucket, even if non-empty. This method blocks until the deletion completes or fails. * * @param storage the storage service to be used to issue requests * @param bucket the bucket to be deleted * @throws StorageException if an exception is encountered during bucket deletion */ public static void forceDelete(Storage storage, String bucket) { new DeleteBucketTask(storage, bucket).call(); }
/** * Deletes a bucket, even if non-empty. This method blocks until the deletion completes or fails. * * @param storage the storage service to be used to issue requests * @param bucket the bucket to be deleted * @throws StorageException if an exception is encountered during bucket deletion */ public static void forceDelete(Storage storage, String bucket) { new DeleteBucketTask(storage, bucket).call(); }