org.apache.brooklyn.api.mgmt.ExecutionManager Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.brooklyn.api.mgmt;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import org.apache.brooklyn.api.entity.Entity;
/**
* This class manages the execution of a number of jobs with tags.
*
* It is like an executor service (and it ends up delegating to one) but adds additional support
* where jobs can be:
*
* - Tracked with tags/buckets
*
- Be {@link Runnable}s, {@link Callable}s, or {@link groovy.lang.Closure}s
*
- Remembered after completion
*
- Treated as {@link Task} instances (see below)
*
- Given powerful synchronization capabilities
*
*
* The advantage of treating them as {@link Task} instances include:
*
* - Richer status information
*
- Started-by, contained-by relationships automatically remembered
*
- Runtime metadata (start, stop, etc)
*
- Grid and multi-machine support)
*
*
* For usage instructions see {@link #submit(Map, TaskAdaptable)}, and for examples see the various
* {@code ExecutionTest} and {@code TaskTest} instances.
*
* It has been developed for multi-location provisioning and management to track work being
* done by each {@link Entity}.
*
* Note the use of the environment variable {@code THREAD_POOL_SIZE} which is used to size
* the {@link ExecutorService} thread pool. The default is calculated as twice the number
* of CPUs in the system plus two, giving 10 for a four core system, 18 for an eight CPU
* server and so on.
*/
public interface ExecutionManager {
public boolean isShutdown();
/** returns the task with the given ID, or null if none */
public Task> getTask(String id);
/** returns all tasks with the given tag (immutable) */
public Set> getTasksWithTag(Object tag);
/** returns all tasks that have any of the given tags (immutable) */
public Set> getTasksWithAnyTag(Iterable> tags);
/** returns all tasks that have all of the given tags (immutable) */
public Set> getTasksWithAllTags(Iterable> tags);
/** returns all tags known to this manager (immutable) */
public Set