/** * Execute the given task at some time in the future. * * @param <T> the return type for the task * @param task the task. * @return a worker that can be used to check the state of the task and * receive the result of it. */ public <T> Worker<T> submit(final Task<T> task) { return submit(ConcurrentUtils.createService(task)); }
default void setCancelable(boolean cancelable){ getStateHandler().setCancelable(cancelable); } }
default void updateTaskMessage(String message){ getStateHandler().updateTaskMessage(message); }
@Override protected void executeTask(Task<V> task) { cancelable.unbind(); if (task instanceof DataFxTask) { cancelable.bind(((DataFxTask<V>) task).cancelableProperty()); } Executor e = getExecutor(); if (e != null) { e.execute(task); } else { ObservableExecutor.getDefaultInstance().execute(task); } }
/** * Defines a new {@link FlowAsyncTaskAction} instance that task is defined by a class that extends * {@link Runnable}. Whenever a action is triggered a new instance of the given class will be created. Therefore the * class needs a default constructor. All injection that is working in a controller class will work in the given * class that defines the task, too. The task of the action will run on a background thread. Therefore the default * instance of the {@link ObservableExecutor} will be used. * * @param runnableClass the class that defines the task */ public FlowAsyncTaskAction(Class<? extends Runnable> runnableClass) { this(runnableClass, ObservableExecutor.getDefaultInstance()); }
public static <T> DataFxService<T> createService(Callable<T> callable) { return createService(new CallableBasedDataFxTask<T>(callable)); }
public default void updateTaskTitle(String title) { getStateHandler().updateTaskTitle(title); }
default void updateTaskProgress(long workDone, long max){ getStateHandler().updateTaskProgress(workDone, max); }
/** * Execute the given runnable at some time in the future. * * @param runnable the runnable. If a <code>DataFxRunnable</code> is used * here a <code>TaskStateHandler</code> will be injected. */ public void execute(Runnable runnable) { submit(runnable); }
/** * Returns the default executor. This one uses an internal cached thread pool. * @return the default executor */ public static synchronized ObservableExecutor getDefaultInstance() { if(defaultInstance == null) { //TODO: support of system properties to define the inner executor defaultInstance = new ObservableExecutor(); } return defaultInstance; } }
public RunnableBasedDataFxTask(Runnable runnable) { this.runnable = runnable; if (this.runnable instanceof DataFxRunnable) { ((DataFxRunnable) this.runnable).injectStateHandler(this); } }
/** * Creates a new ObservableExecutor that uses a cached thread pool to handle * all commited tasks. */ public ObservableExecutor() { this(ThreadPoolExecutorFactory.getThreadPoolExecutor()); }
/** * Returns the <tt>TaskStateHandler</tt> for this instance * @return the <tt>TaskStateHandler</tt> for this instance */ default TaskStateHandler getStateHandler() { return TaskStateHandlerManager.get(this); }
public CallableBasedDataFxTask(Callable<V> callable) { this.callable = callable; if (this.callable instanceof DataFxCallable) { ((DataFxCallable<V>) this.callable).injectStateHandler(this); } }
/** * This method will be called by DataFX to inject a * <code>TaskStateHandler</code> in this callable. The handler can be used * to provide some more feedback of this callable. * * @param stateHandler the injected TaskStateHandler */ default void injectStateHandler(TaskStateHandler stateHandler) { TaskStateHandlerManager.add(this, stateHandler); }
/** * Creates a new <tt>ProcessChain</tt> that uses this executor as the executor for all background tasks. * @return a new <tt>ProcessChain</tt> * * @see ProcessChain */ public ProcessChain<Void> createProcessChain() { return new ProcessChain<>(this); }
/** * Execute the given callable at some time in the future. * * @param <T> the return type for the worker * @param callable the callable. If a <code>DataFxCallable</code> is used * here a <code>TaskStateHandler</code> will be injected. * @return a worker that can be used to check the state of the callable and * receive the result of it. */ public <T> Worker<T> submit(final Callable<T> callable) { return submit(ConcurrentUtils.createService(callable)); }
/** * Defines a new {@link FlowAsyncTaskAction} instance that task is defined by a {@link Runnable} instance. The task * of the action will run on a background thread. Therefore the default instance of the {@link ObservableExecutor} * will be used. * * @param runnable defines the task and will be called whenever the action is triggered. */ public FlowAsyncTaskAction(Runnable runnable) { this(runnable, ObservableExecutor.getDefaultInstance()); }
/** * Execute the given runnable at some time in the future. * * @param runnable the runnable. If a <code>DataFxRunnable</code> is used * here a <code>TaskStateHandler</code> will be injected. * @return a worker that can be used to check the state of the runnable */ public Worker<Void> submit(final Runnable runnable) { return submit(ConcurrentUtils.createService(runnable)); }
public CrudObjectProperty(S entity, CrudListProperty<S, T> listProperty, CrudService<S, T> crudService) { this(entity, crudService, ObservableExecutor.getDefaultInstance()); this.listProperty = listProperty; }