public void park(BlockingOperation op) { long timeout = op.getWaitTimeout(); WaitSetEntry entry = new WaitSetEntry(queue, op); entry.setNodeEngine(nodeEngine); queue.offer(entry); if (timeout > -1 && timeout < TIMEOUT_UPPER_BOUND) { delayQueue.offer(entry); } }
public void cancelAll(String callerUuid, Throwable cause) { for (WaitSetEntry entry : queue) { if (!entry.isValid()) { continue; } Operation op = entry.getOperation(); if (callerUuid.equals(op.getCallerUuid())) { entry.cancel(cause); } } }
@Override public int compareTo(Delayed other) { // compare zero ONLY if same object if (other == this) { return 0; } long d = (getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS)); return (d == 0) ? 0 : ((d < 0) ? -1 : 1); }
public boolean needsInvalidation() { return isExpired() || isCancelled() || isCallTimedOut(); }
@Override public void run() throws Exception { if (!valid) { return; } boolean expired = isExpired(); boolean cancelled = isCancelled(); if (!expired && !cancelled) { return; } if (!queue.remove(this)) { return; } valid = false; if (expired) { onExpire(); } else { onCancel(); } }
public void unpark(Notifier notifier, WaitNotifyKey key) { WaitSetEntry entry = queue.peek(); while (entry != null) { Operation op = entry.getOperation(); if (notifier == op) { throw new IllegalStateException("Found cyclic wait-notify! -> " + notifier); if (entry.isValid()) { if (entry.isExpired()) { entry.onExpire(); } else if (entry.isCancelled()) { entry.onCancel(); } else { if (entry.shouldWait()) { return; operationService.run(op); entry.setValid(false);
public void invalidateAll(String callerUuid) { for (WaitSetEntry entry : queue) { if (!entry.isValid()) { continue; } Operation op = entry.getOperation(); if (callerUuid.equals(op.getCallerUuid())) { entry.setValid(false); } } }
public boolean isCallTimedOut() { final NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine(); InternalOperationService operationService = nodeEngine.getOperationService(); if (operationService.isCallTimedOut(op)) { cancel(new CallTimeoutResponse(op.getCallId(), op.isUrgent())); return true; } return false; }
WaitSetEntry(Queue<WaitSetEntry> queue, BlockingOperation blockingOperation) { this.op = (Operation) blockingOperation; this.blockingOperation = blockingOperation; this.queue = queue; this.expirationTimeMs = getExpirationTimeMs(blockingOperation); setPartitionId(op.getPartitionId()); }
public void cancelAll(String serviceName, Object objectId, Throwable cause) { for (WaitSetEntry entry : queue) { if (!entry.isValid()) { continue; } WaitNotifyKey wnk = entry.blockingOperation.getWaitKey(); if (serviceName.equals(wnk.getServiceName()) && objectId.equals(wnk.getObjectName())) { entry.cancel(cause); } } }
public void onShutdown() { Object response = new HazelcastInstanceNotActiveException(); Address thisAddress = nodeEngine.getThisAddress(); for (WaitSetEntry entry : queue) { if (!entry.isValid()) { continue; } Operation op = entry.getOperation(); // only for local invocations, remote ones will be expired via #onMemberLeft() if (thisAddress.equals(op.getCallerAddress())) { try { OperationResponseHandler responseHandler = op.getOperationResponseHandler(); responseHandler.sendResponse(op, response); } catch (Exception e) { logger.finest("While sending HazelcastInstanceNotActiveException response...", e); } } queue.clear(); } }
@Override public void populate(LiveOperations liveOperations) { for (WaitSetEntry entry : queue) { // we need to read out the data from the BlockedOperation; not from the WaitSetEntry Operation operation = entry.getOperation(); liveOperations.add(operation.getCallerAddress(), operation.getCallId()); } }
@Override public void logError(Throwable e) { ILogger logger = getLogger(); if (e instanceof RetryableException) { logger.warning("Op: " + op + ", " + e.getClass().getName() + ": " + e.getMessage()); } else if (e instanceof OutOfMemoryError) { try { logger.severe(e.getMessage(), e); } catch (Throwable ignored) { ignore(ignored); } } else { logger.severe("Op: " + op + ", Error: " + e.getMessage(), e); } }
public void unpark(Notifier notifier, WaitNotifyKey key) { WaitSetEntry entry = queue.peek(); while (entry != null) { Operation op = entry.getOperation(); if (notifier == op) { throw new IllegalStateException("Found cyclic wait-notify! -> " + notifier); if (entry.isValid()) { if (entry.isExpired()) { entry.onExpire(); } else if (entry.isCancelled()) { entry.onCancel(); } else { if (entry.shouldWait()) { return; operationService.run(op); entry.setValid(false);
public void invalidateAll(String callerUuid) { for (WaitSetEntry entry : queue) { if (!entry.isValid()) { continue; } Operation op = entry.getOperation(); if (callerUuid.equals(op.getCallerUuid())) { entry.setValid(false); } } }
@Override public void run() throws Exception { if (!valid) { return; } boolean expired = isExpired(); boolean cancelled = isCancelled(); if (!expired && !cancelled) { return; } if (!queue.remove(this)) { return; } valid = false; if (expired) { onExpire(); } else { onCancel(); } }
public boolean needsInvalidation() { return isExpired() || isCancelled() || isCallTimedOut(); }
public boolean isCallTimedOut() { final NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine(); InternalOperationService operationService = nodeEngine.getOperationService(); if (operationService.isCallTimedOut(op)) { cancel(new CallTimeoutResponse(op.getCallId(), op.isUrgent())); return true; } return false; }
WaitSetEntry(Queue<WaitSetEntry> queue, BlockingOperation blockingOperation) { this.op = (Operation) blockingOperation; this.blockingOperation = blockingOperation; this.queue = queue; this.expirationTimeMs = getExpirationTimeMs(blockingOperation); setPartitionId(op.getPartitionId()); }
public void cancelAll(String serviceName, Object objectId, Throwable cause) { for (WaitSetEntry entry : queue) { if (!entry.isValid()) { continue; } WaitNotifyKey wnk = entry.blockingOperation.getWaitKey(); if (serviceName.equals(wnk.getServiceName()) && objectId.equals(wnk.getObjectName())) { entry.cancel(cause); } } }