仍然是Scala中的新手,我现在正在寻找一种方法来实现以下代码:
@Override
public void store(InputStream source, String destination, long size) {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(size);
final PutObjectRequest request = new PutObjectRequest(
this.configuration.getBucket(), destination, source, metadata);
new RetryableService(3) {
@Override
public void call() throws Exception {
getClient().putObject(request);
}
};
}
Run Code Online (Sandbox Code Playgroud)
在Scala中实现RetryableService实现的相同功能的最佳方法是什么?
它基本上调用了N次调用方法,如果所有这些都失败,则会引发异常,如果它们成功则继续运行.这个没有返回任何东西但是我有另一个版本允许返回一个值(所以,我有两个Java类)我相信我可以用Scala中的单个类/函数.
有任何想法吗?
编辑
java中的当前实现如下:
public abstract class RetryableService {
private static final JobsLogger log = JobsLogger
.getLogger(RetryableService.class);
private int times;
public RetryableService() {
this(3);
}
public RetryableService(int times) {
this.times = times;
this.run();
}
private void …Run Code Online (Sandbox Code Playgroud)