【发布时间】:2018-04-13 23:38:47
【问题描述】:
我有两个班级 A 和 B ,像这样:
class A {
public Integer fetchMax() {
// Make a network call & return result
}
}
class B {
public Double fetchPercentile(Integer input) {
// Make a network call & return result
}
}
现在我需要为fetchMax() 和fetchPercentile(Integer) 两种方法提供retry 机制。我想使用helper 类提供此行为,其中retry 方法可以采用(A 或B)的instance、method-name 和method-arguments。重试基本上会重新尝试提供的对象方法。
类似这样的:
class Retry {
public static R retry(T obj, Function<T, R> method, Object... arguments) {
// Retry logic
while(/* retry condition */)
{
obj.method(arguments);
}
}
}
【问题讨论】:
标签: java design-patterns lambda java-8