次のコード・サンプルでは、検索キーのsports_news
とlocal_news
を使用しているオブジェクトを失効化します。この2つの検索キーをセレクタ基準に追加し、検索キーに基づいて失効化リクエストを発行し、リクエストの完了を5秒間待機します。リクエストが完了した場合は、失効化されたオブジェクトの数が表示されます。リクエストがタイムアウトになった場合は、エラー・メッセージが表示されます。
/*
The initial search key is "sports_news".
*/
SearchKeySelector selector = new SearchKeySelector("sports_news");
/*
Add the search key "local_news" to the selector.
*/
selector.add("local_news");
/*
Now invalidate all the fragments that have both "sports_news" and
"local_news" as search keys.
*/
Invalidator.invalidate(selector);
try
{
/*
Wait for the completion of the invalidation.
The maximum time to wait is 5 seconds.
*/
OperationResult result = selector.getResult(5000);
/*
Do whatever you want with the result.
*/
System.err.println("Number of objects invalidated = " +
result.getDocumentCount());
}
catch (TimeoutException ex)
{
/*
Deal with time out.
*/
System.err.println("Timed out.");
}
Copyright © 1997, 2007, Oracle. All rights reserved.