public static <T> Callable<T> buildManagedTask(Callable<T> task, String identityName) { Map<String, String> properties = new HashMap<>(2); properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); } }
public static <T> Callable<T> buildManagedTask(Callable<T> task, String identityName) { Map<String, String> properties = new HashMap<>(2); properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); } }
public static Runnable buildManagedTask(Runnable task, String identityName) { Map<String, String> properties; if (task instanceof SchedulingAwareRunnable) { properties = new HashMap<>(4); properties.put(ManagedTask.LONGRUNNING_HINT, Boolean.toString(((SchedulingAwareRunnable) task).isLongLived())); } else { properties = new HashMap<>(2); } properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); }
public static Runnable buildManagedTask(Runnable task, String identityName) { Map<String, String> properties; if (task instanceof SchedulingAwareRunnable) { properties = new HashMap<>(4); properties.put(ManagedTask.LONGRUNNING_HINT, Boolean.toString(((SchedulingAwareRunnable) task).isLongLived())); } else { properties = new HashMap<>(2); } properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); }
/** * Returns a {@link Callable} object that also implements {@link ManagedTask} * interface so it can receive notification of lifecycle events with the * provided {@link ManagedTaskListener} when the task is submitted * to a {@link ManagedExecutorService} or a {@link ManagedScheduledExecutorService}. * * @param task the task to have the given ManagedTaskListener associated with * @param taskListener (optional) the {@code ManagedTaskListener} to receive * lifecycle events notification when the task is submitted. If {@code task} * implements {@code ManagedTask}, and {@code taskListener} is not * {@code null}, the {@code ManagedTaskListener} interface methods of the * task will not be called. * @return a Callable object * @throws IllegalArgumentException if {@code task} is {@code null} */ public static <V> Callable<V> managedTask(Callable<V> task, ManagedTaskListener taskListener) throws IllegalArgumentException { return managedTask(task, null, taskListener); }
/** * Returns a {@link Callable} object that also implements {@link ManagedTask} * interface so it can receive notification of lifecycle events with the * provided {@link ManagedTaskListener} when the task is submitted * to a {@link ManagedExecutorService} or a {@link ManagedScheduledExecutorService}. * * @param task the task to have the given ManagedTaskListener associated with * @param taskListener (optional) the {@code ManagedTaskListener} to receive * lifecycle events notification when the task is submitted. If {@code task} * implements {@code ManagedTask}, and {@code taskListener} is not * {@code null}, the {@code ManagedTaskListener} interface methods of the * task will not be called. * @return a Callable object * @throws IllegalArgumentException if {@code task} is {@code null} */ public static <V> Callable<V> managedTask(Callable<V> task, ManagedTaskListener taskListener) throws IllegalArgumentException { return managedTask(task, null, taskListener); }
/** * Returns a {@link Runnable} object that also implements {@link ManagedTask} * interface so it can receive notification of lifecycle events with the * provided {@link ManagedTaskListener} when the task is submitted * to a {@link ManagedExecutorService} or a {@link ManagedScheduledExecutorService}. * <p> * Example: * <pre> * Runnable task = ...; * ManagedTaskListener myTaskListener = ...; * ManagedExecutorService executor = ...; * * Runnable taskWithListener = ManagedExecutors.managedTask(task, myTaskListener); * executor.submit(taskWithListener); * </pre> * @param task the task to have the given ManagedTaskListener associated with * @param taskListener (optional) the {@code ManagedTaskListener} to receive * lifecycle events notification when the task is submitted. If {@code task} * implements {@code ManagedTask}, and {@code taskListener} is not * {@code null}, the {@code ManagedTaskListener} interface methods of the * task will not be called. * @return a Runnable object * @throws IllegalArgumentException if {@code task} is {@code null} */ public static Runnable managedTask(Runnable task, ManagedTaskListener taskListener) throws IllegalArgumentException { return managedTask(task, null, taskListener); }
/** * Returns a {@link Runnable} object that also implements {@link ManagedTask} * interface so it can receive notification of lifecycle events with the * provided {@link ManagedTaskListener} when the task is submitted * to a {@link ManagedExecutorService} or a {@link ManagedScheduledExecutorService}. * <p> * Example: * <pre> * Runnable task = ...; * ManagedTaskListener myTaskListener = ...; * ManagedExecutorService executor = ...; * * Runnable taskWithListener = ManagedExecutors.managedTask(task, myTaskListener); * executor.submit(taskWithListener); * </pre> * @param task the task to have the given ManagedTaskListener associated with * @param taskListener (optional) the {@code ManagedTaskListener} to receive * lifecycle events notification when the task is submitted. If {@code task} * implements {@code ManagedTask}, and {@code taskListener} is not * {@code null}, the {@code ManagedTaskListener} interface methods of the * task will not be called. * @return a Runnable object * @throws IllegalArgumentException if {@code task} is {@code null} */ public static Runnable managedTask(Runnable task, ManagedTaskListener taskListener) throws IllegalArgumentException { return managedTask(task, null, taskListener); }
public static <T> Callable<T> buildManagedTask(Callable<T> task, String identityName) { Map<String, String> properties = new HashMap<>(2); properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); } }
/** * Builds the managed task. * * @param <T> the generic type * @param task the task * @param identityName the identity name * @return the callable */ public static <T> Callable<T> buildManagedTask(Callable<T> task, String identityName) { Map<String, String> properties = new HashMap<String, String>(1); properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); } }
/** * Builds the managed task. * * @param task the task * @param identityName the identity name * @return the runnable */ public static Runnable buildManagedTask(Runnable task, String identityName) { Map<String, String> properties = new HashMap<String, String>(2); if (task instanceof SchedulingAwareRunnable) { properties.put(ManagedTask.LONGRUNNING_HINT, Boolean.toString(((SchedulingAwareRunnable) task).isLongLived())); } properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); }
/** * Delegate that wraps a given Runnable/Callable with a JSR-236 ManagedTask, * exposing a long-running hint based on {@link SchedulingAwareRunnable} * and a given identity name. */ protected static class ManagedTaskBuilder { public static Runnable buildManagedTask(Runnable task, String identityName) { Map<String, String> properties; if (task instanceof SchedulingAwareRunnable) { properties = new HashMap<>(4); properties.put(ManagedTask.LONGRUNNING_HINT, Boolean.toString(((SchedulingAwareRunnable) task).isLongLived())); } else { properties = new HashMap<>(2); } properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); } public static <T> Callable<T> buildManagedTask(Callable<T> task, String identityName) { Map<String, String> properties = new HashMap<>(2); properties.put(ManagedTask.IDENTITY_NAME, identityName); return ManagedExecutors.managedTask(task, properties, null); } }