org.elasticsearch.cluster.ClusterService Maven / Gradle / Ivy
The newest version!
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.cluster;
import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.OperationRouting;
import org.elasticsearch.cluster.service.PendingClusterTask;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.tasks.TaskManager;
import java.util.List;
/**
* The cluster service allowing to both register for cluster state events ({@link ClusterStateListener})
* and submit state update tasks ({@link ClusterStateUpdateTask}.
*/
public interface ClusterService extends LifecycleComponent {
/**
* The local node.
*/
DiscoveryNode localNode();
/**
* The current state.
*/
ClusterState state();
/**
* Adds an initial block to be set on the first cluster state created.
*/
void addInitialStateBlock(ClusterBlock block) throws IllegalStateException;
/**
* Remove an initial block to be set on the first cluster state created.
*/
void removeInitialStateBlock(ClusterBlock block) throws IllegalStateException;
/**
* The operation routing.
*/
OperationRouting operationRouting();
/**
* Adds a priority listener for updated cluster states.
*/
void addFirst(ClusterStateListener listener);
/**
* Adds last listener.
*/
void addLast(ClusterStateListener listener);
/**
* Adds a listener for updated cluster states.
*/
void add(ClusterStateListener listener);
/**
* Removes a listener for updated cluster states.
*/
void remove(ClusterStateListener listener);
/**
* Add a listener for on/off local node master events
*/
void add(LocalNodeMasterListener listener);
/**
* Remove the given listener for on/off local master events
*/
void remove(LocalNodeMasterListener listener);
/**
* Adds a cluster state listener that will timeout after the provided timeout,
* and is executed after the clusterstate has been successfully applied ie. is
* in state {@link org.elasticsearch.cluster.ClusterState.ClusterStateStatus#APPLIED}
* NOTE: a {@code null} timeout means that the listener will never be removed
* automatically
*/
void add(@Nullable TimeValue timeout, TimeoutClusterStateListener listener);
/**
* Submits a cluster state update task; submitted updates will be
* batched across the same instance of executor. The exact batching
* semantics depend on the underlying implementation but a rough
* guideline is that if the update task is submitted while there
* are pending update tasks for the same executor, these update
* tasks will all be executed on the executor in a single batch
*
* @param source the source of the cluster state update task
* @param task the state needed for the cluster state update task
* @param config the cluster state update task configuration
* @param executor the cluster state update task executor; tasks
* that share the same executor will be executed
* batches on this executor
* @param listener callback after the cluster state update task
* completes
* @param the type of the cluster state update task state
*/
void submitStateUpdateTask(final String source, final T task,
final ClusterStateTaskConfig config,
final ClusterStateTaskExecutor executor,
final ClusterStateTaskListener listener);
/**
* Submits a cluster state update task; unlike {@link #submitStateUpdateTask(String, Object, ClusterStateTaskConfig, ClusterStateTaskExecutor, ClusterStateTaskListener)},
* submitted updates will not be batched.
*
* @param source the source of the cluster state update task
* @param updateTask the full context for the cluster state update
* task
*/
void submitStateUpdateTask(final String source, final ClusterStateUpdateTask updateTask);
/**
* Returns the tasks that are pending.
*/
List pendingTasks();
/**
* Returns the number of currently pending tasks.
*/
int numberOfPendingTasks();
/**
* Returns the maximum wait time for tasks in the queue
*
* @return A zero time value if the queue is empty, otherwise the time value oldest task waiting in the queue
*/
TimeValue getMaxTaskWaitTime();
/**
* Returns task manager created in the cluster service
*/
TaskManager getTaskManager();
}