Skip to content

Commit

Permalink
Add asynchronous execution support for all S3 service operations.
Browse files Browse the repository at this point in the history
Fixes minio#397
  • Loading branch information
balamurugana committed Jun 22, 2016
1 parent cd84287 commit bdf0523
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
import com.google.common.io.ByteStreams;
import java.nio.file.StandardCopyOption;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;


/**
* <p>
Expand Down Expand Up @@ -1076,6 +1080,44 @@ public ObjectStat statObject(String bucketName, String objectName)
}


/**
* Returns a {@link Future} task of meta data information of given object in given bucket.
*
* </p><b>Example:</b><br>
* <pre>{@code ExecutorService executor = Executors.newFixedThreadPool(3);
* Future<ObjectStat> future = minioClient.statObject(executor, "my-bucketname", "my-objectname");
* while (!future.isDone()) {
* System.out.println("Task is not completed yet. Retrying after 1 millisecond...");
* Thread.sleep(1);
* }
* System.out.println("Task is completed");
* System.out.println(Future.get()); }</pre>
*
* @param executor thread pool.
* @param bucketName Bucket name.
* @param objectName Object name in the bucket.
*
* @return {@link Future} task.
*
* @see ObjectStat
*/
public Future<ObjectStat> statObject(ExecutorService executor, final String bucketName, final String objectName) {
final MinioClient thisClient = this;

Callable<ObjectStat> task = new Callable<ObjectStat>() {
@Override
public ObjectStat call()
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException {
return thisClient.statObject(bucketName, objectName);
}
};

return executor.submit(task);
}


/**
* Gets entire object's data as {@link InputStream} in given bucket. The InputStream must be closed
* after use else the connection will remain open.
Expand Down

0 comments on commit bdf0523

Please sign in to comment.