public synchronized void destroy() { if (_instance == null) { return; // Already destroyed. } java.util.HashSet<RetryTask> keep = new java.util.HashSet<RetryTask>(); for (RetryTask task : _requests) { if (!task.destroy()) { keep.add(task); } } _requests = keep; _instance = null; // // Wait for the tasks to be executed, it shouldn't take long // since they couldn't be canceled. If interrupted, we // preserve the interrupt. // boolean interrupted = false; while (!_requests.isEmpty()) { try { wait(); } catch (InterruptedException ex) { interrupted = true; } } if (interrupted) { Thread.currentThread().interrupt(); } }
public synchronized void add(ProxyOutgoingAsyncBase outAsync, int interval) { if (_instance == null) { throw new Ice.CommunicatorDestroyedException(); } RetryTask task = new RetryTask(_instance, this, outAsync); outAsync.cancelable(task); // This will throw if the request is canceled task.setFuture( _instance.timer().schedule(task, interval, java.util.concurrent.TimeUnit.MILLISECONDS)); _requests.add(task); }
/** * Reset error searches. Clear cache only if true is passed to argument * * @param clearCaches */ protected void resetErrorSearches(boolean clearCaches) { Hashtable tmpReqList = new Hashtable(); tmpReqList.putAll(_requestList); int[] ids = _msgQueue.getMessageIDs(); if (ids != null) { for (int i = 0; i < ids.length; i++) { String reqID = Integer.toString(ids[i]); tmpReqList.remove(reqID); } } Collection reqList = tmpReqList.values(); for (Iterator iter = reqList.iterator(); iter.hasNext(); ) { Request req = (Request) iter.next(); _requestList.remove(req.getRequestID()); } _retryInterval = getPropertyIntValue(EVENT_CONNECTION_RETRY_INTERVAL, _retryInterval); RetryTask task = new RetryTask(tmpReqList); task.clearCache(clearCaches); SystemTimer.getTimer() .schedule(task, new Date(((System.currentTimeMillis() + _retryInterval) / 1000) * 1000)); }
@Override public void run() { initialWait(); int retryCount = 0; while (true) { if (retryCount >= maxRetryCount) { return; } retryCount++; try { if (retryTask.execute()) return; } catch (Exception ex) { logger.error(String.format("Error executing task: %s", ex.getMessage())); } sleepFor(retryInterval); } }