他社が発行した Web サービス用の Java クライアント コードを作成する必要があります。そのクライアント コードでは、タイムアウトが発生した場合に、指定された回数だけ再試行するオプションを指定する必要があります。
Web サービス呼び出しで非永続オブジェクトを渡したので、再試行プロセスでこれらのオブジェクトを保存する必要があると思います。
コードサンプルは非常に役に立ちます。
他社が発行した Web サービス用の Java クライアント コードを作成する必要があります。そのクライアント コードでは、タイムアウトが発生した場合に、指定された回数だけ再試行するオプションを指定する必要があります。
Web サービス呼び出しで非永続オブジェクトを渡したので、再試行プロセスでこれらのオブジェクトを保存する必要があると思います。
コードサンプルは非常に役に立ちます。
AOPとJavaアノテーションはそれを行う正しい方法です。jcabi-aspectsからの既製のメカニズムをお勧めします(私は開発者です):
import com.jcabi.aspects.RetryOnFailure;
@RetryOnFailure(attempts = 4)
public String load(URL url) {
// sensitive operation that may throw an exception
return url.openConnection().getContent();
}
これはあなたが始めるのに役立つはずです(しかし、確かに生産品質ではありません)。実際のWebサービス呼び出しはCallable<T>
、TがWebサービスから期待される応答のタイプである場合を実装するクラス内にある必要があります。
import java.util.List;
import java.util.concurrent.Callable;
public class RetryHelper<T>
{
// Number of times to retry before giving up.
private int numTries;
// Delay between retries.
private long delay;
// The actual callable that call the webservice and returns the response object.
private Callable<T> callable;
// List of exceptions expected that should result in a null response
// being returned.
private List<Class<? extends Exception>> allowedExceptions;
public RetryHelper(
int numTries,
long delay,
Callable<T> callable,
List<Class<? extends Exception>> allowedExceptions)
{
this.numTries = numTries;
this.delay = delay;
this.callable = callable;
this.allowedExceptions = allowedExceptions;
}
public T run()
{
int count = 0;
while (count < numTries)
{
try
{
return callable.call();
}
catch (Exception e)
{
if (allowedExceptions.contains(e.getClass()))
{
return null;
}
}
count++;
try
{
Thread.sleep(delay);
}
catch (InterruptedException ie)
{
// Ignore this for now.
}
}
return null;
}
}