All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 or {@link Callable}s, (support for {@link groovy.lang.Closure} is deprecated) *
  • 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 getTaskTags(); // /** returns all tasks known to this manager (immutable) */ // public Set> getAllTasks(); /** see {@link #submit(Map, TaskAdaptable)} * @deprecated since 1.0.0 pass displayName or map */ @Deprecated public Task submit(Runnable r); /** see {@link #submit(Map, TaskAdaptable)} * @deprecated since 1.0.0 pass displayName or map */ @Deprecated public Task submit(Callable r); /** see {@link #submit(Map, TaskAdaptable)} */ public Task submit(String displayName, Runnable c); /** see {@link #submit(Map, TaskAdaptable)} */ public Task submit(String displayName, Callable c); /** see {@link #submit(Map, TaskAdaptable)} */ public Task submit(TaskAdaptable task); /** see {@link #submit(Map, TaskAdaptable)} */ public Task submit(Map flags, Runnable r); /** see {@link #submit(Map, TaskAdaptable)} */ public Task submit(Map flags, Callable c); /** * Submits the given {@link Task} for execution in the context associated with this manager. * * The following optional flags supported (in the optional map first arg): *
    *
  • tag - A single object to be used as a tag for looking up the task *
  • tags - A {@link Collection} of object tags each of which the task should be associated, * used for associating with contexts, mutex execution, and other purposes *
  • synchId - A string, or {@link Collection} of strings, representing a category on which an object should own a synch lock *
  • synchObj - A string, or {@link Collection} of strings, representing a category on which an object should own a synch lock *
  • newTaskStartCallback - A callback that will be invoked just before the task starts if it starts as a result of this call. *
  • newTaskEndCallback - A callback that will be invoked when the task completes if it starts as a result of this call *
* * Callbacks run in the task's thread. It can be one of the following types: *
    *
  • {@link Runnable} *
  • {@link Callable} *
  • {@link com.google.common.base.Function} that matches the generics {@code } *
  • Support for {@link groovy.lang.Closure} is deprecated. *
*

* If a Map is supplied it must be modifiable (currently; may allow immutable maps in future). */ public Task submit(Map flags, TaskAdaptable task); }