com.hazelcast.spi.impl.operationservice.OperationService Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2021, 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;
import com.hazelcast.cluster.Address;
import com.hazelcast.internal.management.dto.SlowOperationDTO;
import com.hazelcast.spi.impl.PartitionSpecificRunnable;
import com.hazelcast.spi.impl.operationservice.impl.InvocationFuture;
import java.util.BitSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
* The OperationService is responsible for executing operations.
*
* A single operation can be executed locally using {@link #run(Operation)}
* and {@link #execute(Operation)}. Or it can executed remotely using one of
* the send methods.
*
* It also is possible to execute multiple operation on multiple partitions
* using one of the invoke methods.
*/
@SuppressWarnings("checkstyle:MethodCount")
public interface OperationService {
String SERVICE_NAME = "hz:impl:operationService";
/**
* Returns the size of the response queue.
*
* @return the size of the response queue.
*/
int getResponseQueueSize();
int getOperationExecutorQueueSize();
int getPriorityOperationExecutorQueueSize();
int getRunningOperationsCount();
int getRemoteOperationsCount();
/**
* Returns the number of executed operations.
*
* @return the number of executed operations.
*/
long getExecutedOperationCount();
/**
* Returns the number of partition threads.
*
* @return the number of partition threads.
*/
int getPartitionThreadCount();
/**
* Returns the number of generic threads.
*
* @return number of generic threads.
*/
int getGenericThreadCount();
/**
* Runs an operation in the calling thread.
*
* @param op the operation to execute in the calling thread
*/
void run(Operation op);
/**
* Executes an operation in the operation executor pool.
*
* @param op the operation to execute in the operation executor pool.
*/
void execute(Operation op);
/**
* Executes a PartitionSpecificRunnable.
*
* This method is typically used by the {@link com.hazelcast.client.impl.ClientEngine}
* when it has received a Packet containing a request that needs to be processed.
*
* @param task the task to execute
*/
void execute(PartitionSpecificRunnable task);
/**
* Executes for each of the partitions, a task created by the
* taskFactory.
*
* For more info see the
* {@link com.hazelcast.spi.impl.operationexecutor.OperationExecutor#executeOnPartitions(PartitionTaskFactory, BitSet)}
*
* @param taskFactory the PartitionTaskFactory used to create
* operations.
* @param partitions the partitions to execute an operation on.
* @throws NullPointerException if taskFactory or partitions is null.
*/
void executeOnPartitions(PartitionTaskFactory taskFactory, BitSet partitions);
InvocationFuture invokeOnPartition(String serviceName, Operation op, int partitionId);
InvocationFuture invokeOnPartitionAsync(String serviceName, Operation op, int partitionId);
InvocationFuture invokeOnPartitionAsync(String serviceName, Operation op, int partitionId, int replicaIndex);
/**
* Executes an operation on a partition.
*
* @param op the operation
* @param the return type of the operation response
* @return the future.
*/
InvocationFuture invokeOnPartition(Operation op);
InvocationFuture invokeOnTarget(String serviceName, Operation op, Address target);
InvocationBuilder createInvocationBuilder(String serviceName, Operation op, int partitionId);
InvocationBuilder createInvocationBuilder(String serviceName, Operation op, Address target);
/**
* Invokes a set of operations on each partition.
*
* This method blocks until the operations complete.
*
* If the operations have sync backups, this method will not wait for their completion.
* Instead, it will return once the operations are completed on primary replicas of the
* given {@code partitions}.
*
* @param serviceName the name of the service.
* @param operationFactory the factory responsible for creating operations
* @return a Map with partitionId as a key and the outcome of the operation
* as a value.
* @throws Exception
*/
Map invokeOnAllPartitions(String serviceName, OperationFactory operationFactory)
throws Exception;
/**
* Invokes a set of operations on selected set of all partitions in an async way.
*
* If the operations have sync backups, the returned {@link CompletableFuture} does not
* wait for their completion. Instead, the {@link CompletableFuture} is completed once the
* operations are completed on primary replicas of the given {@code partitions}.
*
* @param serviceName the name of the service
* @param operationFactory the factory responsible for creating operations
* @param type of result of operations returned by {@code operationFactory}
* @return a future returning a Map with partitionId as a key and the
* outcome of the operation as a value.
*/
CompletableFuture