Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.spi.impl.operationservice.impl;
import com.hazelcast.core.ExecutionCallback;
import com.hazelcast.logging.ILogger;
import com.hazelcast.nio.Address;
import com.hazelcast.spi.ExecutionTracingService;
import com.hazelcast.spi.Operation;
import com.hazelcast.spi.TraceableOperation;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.hazelcast.spi.impl.operationexecutor.OperationExecutor;
import com.hazelcast.spi.impl.operationexecutor.OperationRunner;
import com.hazelcast.spi.impl.operationservice.impl.operations.IsStillExecutingOperation;
import com.hazelcast.spi.impl.operationservice.impl.operations.TraceableIsStillExecutingOperation;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static com.hazelcast.spi.ExecutionService.SYSTEM_EXECUTOR;
/**
* Checks if an Operation is still running. This is useful when an operation isn't executed (e.g. got lost due to an
* OOME on the remote side) and no response is ever send.
*
* The behavior needs to be cleaned up.
*
* Currently we only detect if an operation is actually running, not if it is in a queue somewhere. So it can mean that you
* assume an operation isn't running, even though it is queued. Another issue is that the actual IsStillRunningOperation
* isn't executed quick enough and then the system still decides that the operation isn't running.
*
* Instead of letting every invocation ask the remote system if an operation is still running, let the remote system
* send a batch of all the call-id's for a particular member of the operations that are running.
*/
public class IsStillRunningService {
private static final int IS_EXECUTING_CALL_TIMEOUT = 5000;
private final ILogger logger;
//private final OperationServiceImpl operationService;
private final NodeEngineImpl nodeEngine;
private final OperationExecutor operationExecutor;
public IsStillRunningService(OperationExecutor operationExecutor, NodeEngineImpl nodeEngine, ILogger logger) {
this.operationExecutor = operationExecutor;
this.logger = logger;
this.nodeEngine = nodeEngine;
}
/**
* Checks if an operation is still running.
* @param invocation The invocation for this operation.
* @return true if the operation is running, false otherwise.
*/
public boolean isOperationExecuting(Invocation invocation) {
if (isStillRunningOperation(invocation)) {
// we don't want to is-still-running-operations; it can lead to a explosion of such invocations
return false;
}
// ask if op is still being executed?
Boolean executing = Boolean.FALSE;
try {
Operation isStillExecuting = createCheckOperation(invocation);
Invocation inv = new TargetInvocation(
invocation.nodeEngine, invocation.serviceName, isStillExecuting,
invocation.getTarget(), 0, 0, IS_EXECUTING_CALL_TIMEOUT, null, true);
Future f = inv.invoke();
invocation.logger.finest("Asking if operation execution has been started: " + invocation);
executing = (Boolean) invocation.nodeEngine.toObject(f.get(IS_EXECUTING_CALL_TIMEOUT, TimeUnit.MILLISECONDS));
} catch (Exception e) {
invocation.logger.warning("While asking 'is-executing': " + invocation, e);
}
invocation.logger.finest("'is-executing': " + executing + " -> " + invocation);
return executing;
}
/**
* Checks if the Invocation is pointing to a IsStillExecutingOperation/TraceableIsStillExecutingOperation.
*/
private boolean isStillRunningOperation(Invocation invocation) {
Operation op = invocation.op;
return op instanceof IsStillExecutingOperation || op instanceof TraceableIsStillExecutingOperation;
}
/**
* Sets operation timeout to invocation result if the operation is not running.
*
* @param invocation The invocation to check
*/
public void timeoutInvocationIfNotExecuting(Invocation invocation) {
if (isStillRunningOperation(invocation)) {
// timeout the original invocation since IsStillExecutingOperation is timed out
final InvocationFuture future = invocation.invocationFuture;
future.set(false);
return;
}
try {
final Operation isStillExecuting = createCheckOperation(invocation);
final ExecutionCallback