Invocation(Context context, Operation op, Runnable taskDoneCallback, int tryCount, long tryPauseMillis, long callTimeoutMillis, boolean deserialize) { this.context = context; this.op = op; this.taskDoneCallback = taskDoneCallback; this.tryCount = tryCount; this.tryPauseMillis = tryPauseMillis; this.callTimeoutMillis = getCallTimeoutMillis(callTimeoutMillis); this.future = new InvocationFuture(this, deserialize); }
private void complete(Object value) { future.complete(value); if (context.invocationRegistry.deregister(this) && taskDoneCallback != null) { context.asyncExecutor.execute(taskDoneCallback); } }
@Override protected E resolveAndThrowIfException(Object unresolved) throws ExecutionException, InterruptedException { Object value = resolve(unresolved); if (value == null || !(value instanceof Throwable)) { return (E) value; } else if (value instanceof CancellationException) { throw (CancellationException) value; } else if (value instanceof ExecutionException) { throw (ExecutionException) value; } else if (value instanceof InterruptedException) { throw (InterruptedException) value; } else if (value instanceof Error) { throw (Error) value; } else { throw new ExecutionException((Throwable) value); } }
@Override @SuppressWarnings("unchecked") public <V> void asyncInvokeOnPartition(String serviceName, Operation op, int partitionId, ExecutionCallback<V> callback) { op.setServiceName(serviceName).setPartitionId(partitionId).setReplicaIndex(DEFAULT_REPLICA_INDEX); InvocationFuture future = new PartitionInvocation(invocationContext, op, invocationMaxRetryCount, invocationRetryPauseMillis, DEFAULT_CALL_TIMEOUT, DEFAULT_DESERIALIZE_RESULT, failOnIndeterminateOperationState).invokeAsync(); if (callback != null) { future.andThen(callback); } }
private CallsPerMember populate() { calls.clear(); ClusterService clusterService = nodeEngine.getClusterService(); calls.ensureMember(thisAddress); for (Member member : clusterService.getMembers()) { calls.ensureMember(member.getAddress()); } for (LiveOperationsTracker tracker : serviceManager.getServices(LiveOperationsTracker.class)) { tracker.populate(calls); } for (Invocation invocation : invocationRegistry) { if (invocation.future.isCancelled()) { calls.addOpToCancel(invocation.invTarget, invocation.op.getCallId()); } } return calls; }
private Object newOperationTimeoutException(boolean heartbeatTimeout) { StringBuilder sb = new StringBuilder(); if (heartbeatTimeout) { sb.append(invocation.op.getClass().getSimpleName()) .append(" invocation failed to complete due to operation-heartbeat-timeout. "); sb.append("Current time: ").append(timeToString(currentTimeMillis())).append(". "); sb.append("Start time: ").append(timeToString(invocation.firstInvocationTimeMillis)).append(". "); sb.append("Total elapsed time: ") .append(currentTimeMillis() - invocation.firstInvocationTimeMillis).append(" ms. "); long lastHeartbeatMillis = invocation.lastHeartbeatMillis; sb.append("Last operation heartbeat: "); appendHeartbeat(sb, lastHeartbeatMillis); long lastHeartbeatFromMemberMillis = invocation.context.invocationMonitor .getLastMemberHeartbeatMillis(invocation.getTargetAddress()); sb.append("Last operation heartbeat from member: "); appendHeartbeat(sb, lastHeartbeatFromMemberMillis); } else { sb.append(invocation.op.getClass().getSimpleName()) .append(" got rejected before execution due to not starting within the operation-call-timeout of: ") .append(invocation.callTimeoutMillis).append(" ms. "); sb.append("Current time: ").append(timeToString(currentTimeMillis())).append(". "); sb.append("Start time: ").append(timeToString(invocation.firstInvocationTimeMillis)).append(". "); sb.append("Total elapsed time: ") .append(currentTimeMillis() - invocation.firstInvocationTimeMillis).append(" ms. "); } sb.append(invocation); String msg = sb.toString(); return new ExecutionException(msg, new OperationTimeoutException(msg)); }
return new InterruptedException(invocation.op.getClass().getSimpleName() + " was interrupted. " + invocation); } else if (unresolved == CALL_TIMEOUT) { return newOperationTimeoutException(false); } else if (unresolved == HEARTBEAT_TIMEOUT) { return newOperationTimeoutException(true); } else if (unresolved.getClass() == Packet.class) { NormalResponse response = invocation.context.serializationService.toObject(unresolved);
@Override @SuppressWarnings("unchecked") public <V> void asyncInvokeOnPartition(String serviceName, Operation op, int partitionId, ExecutionCallback<V> callback) { op.setServiceName(serviceName).setPartitionId(partitionId).setReplicaIndex(DEFAULT_REPLICA_INDEX); InvocationFuture future = new PartitionInvocation(invocationContext, op, invocationMaxRetryCount, invocationRetryPauseMillis, DEFAULT_CALL_TIMEOUT, DEFAULT_DESERIALIZE_RESULT, failOnIndeterminateOperationState).invokeAsync(); if (callback != null) { future.andThen(callback); } }
private CallsPerMember populate() { calls.clear(); ClusterService clusterService = nodeEngine.getClusterService(); calls.ensureMember(thisAddress); for (Member member : clusterService.getMembers()) { calls.ensureMember(member.getAddress()); } for (LiveOperationsTracker tracker : serviceManager.getServices(LiveOperationsTracker.class)) { tracker.populate(calls); } for (Invocation invocation : invocationRegistry) { if (invocation.future.isCancelled()) { calls.addOpToCancel(invocation.getTargetAddress(), invocation.op.getCallId()); } } return calls; }
private Object newOperationTimeoutException(boolean heartbeatTimeout) { StringBuilder sb = new StringBuilder(); if (heartbeatTimeout) { sb.append(invocation.op.getClass().getSimpleName()) .append(" invocation failed to complete due to operation-heartbeat-timeout. "); sb.append("Current time: ").append(timeToString(currentTimeMillis())).append(". "); sb.append("Start time: ").append(timeToString(invocation.firstInvocationTimeMillis)).append(". "); sb.append("Total elapsed time: ") .append(currentTimeMillis() - invocation.firstInvocationTimeMillis).append(" ms. "); long lastHeartbeatMillis = invocation.lastHeartbeatMillis; sb.append("Last operation heartbeat: "); appendHeartbeat(sb, lastHeartbeatMillis); long lastHeartbeatFromMemberMillis = invocation.context.invocationMonitor .getLastMemberHeartbeatMillis(invocation.invTarget); sb.append("Last operation heartbeat from member: "); appendHeartbeat(sb, lastHeartbeatFromMemberMillis); } else { sb.append(invocation.op.getClass().getSimpleName()) .append(" got rejected before execution due to not starting within the operation-call-timeout of: ") .append(invocation.callTimeoutMillis).append(" ms. "); sb.append("Current time: ").append(timeToString(currentTimeMillis())).append(". "); sb.append("Start time: ").append(timeToString(invocation.firstInvocationTimeMillis)).append(". "); sb.append("Total elapsed time: ") .append(currentTimeMillis() - invocation.firstInvocationTimeMillis).append(" ms. "); } sb.append(invocation); String msg = sb.toString(); return new ExecutionException(msg, new OperationTimeoutException(msg)); }
return new InterruptedException(invocation.op.getClass().getSimpleName() + " was interrupted. " + invocation); } else if (unresolved == CALL_TIMEOUT) { return newOperationTimeoutException(false); } else if (unresolved == HEARTBEAT_TIMEOUT) { return newOperationTimeoutException(true); } else if (unresolved.getClass() == Packet.class) { NormalResponse response = invocation.context.serializationService.toObject(unresolved);
private void complete(Object value) { future.complete(value); if (context.invocationRegistry.deregister(this) && taskDoneCallback != null) { context.asyncExecutor.execute(taskDoneCallback); } }
@Override protected E resolveAndThrowIfException(Object unresolved) throws ExecutionException, InterruptedException { Object value = resolve(unresolved); if (value == null || !(value instanceof Throwable)) { return (E) value; } else if (value instanceof CancellationException) { throw (CancellationException) value; } else if (value instanceof ExecutionException) { throw (ExecutionException) value; } else if (value instanceof InterruptedException) { throw (InterruptedException) value; } else if (value instanceof Error) { throw (Error) value; } else { throw new ExecutionException((Throwable) value); } }
Invocation(Context context, Operation op, Runnable taskDoneCallback, int tryCount, long tryPauseMillis, long callTimeoutMillis, boolean deserialize) { this.context = context; this.op = op; this.taskDoneCallback = taskDoneCallback; this.tryCount = tryCount; this.tryPauseMillis = tryPauseMillis; this.callTimeoutMillis = getCallTimeoutMillis(callTimeoutMillis); this.future = new InvocationFuture(this, deserialize); }