public Worker<S> save() { return ConcurrentUtils.executeService(executor, ConcurrentUtils.createService(() -> { try { S updatedData = crudService.save(get()); ConcurrentUtils.runAndWait(() -> set(updatedData)); return updatedData; } catch (Exception e) { throw new RuntimeException("TODO", e); } })); }
public Worker<S> update() { return ConcurrentUtils.executeService(executor, ConcurrentUtils.createService(() -> { try { T id = ConcurrentUtils.runCallableAndWait(() -> get().getId()); S updatedData = crudService.getById(id); ConcurrentUtils.runAndWait(() -> set(updatedData)); return updatedData; } catch (Exception e) { throw new RuntimeException("TODO", e); } })); }
public void then(Consumer<V> consumer) { ConcurrentUtils.then(this, consumer); } }
return ConcurrentUtils.executeService(executor, ConcurrentUtils.createService(runner));
/** * 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)); }
@Override public Worker<T> retrieve() { final Service<T> retriever = createService(objectProperty); return ConcurrentUtils.executeService(executor, retriever); }
public void setException(Throwable exception) { if(Platform.isFxApplicationThread()) { exceptionProperty().set(exception); } else { try { ConcurrentUtils.runAndWait(() -> exceptionProperty().set(exception)); } catch (InterruptedException | ExecutionException e) { LOGGER.log(Level.SEVERE, "Can't handle exception in JavaFX Application Thread!", e); LOGGER.log(Level.SEVERE, "Initial exception: ", exception); } } }
@SuppressWarnings("unchecked") private <U, V> V execute(U inputParameter, ProcessDescription<U, V> processDescription, Executor executorService) throws InterruptedException, ExecutionException { if (processDescription.getThreadType().equals(ThreadType.EXECUTOR)) { FutureTask<V> task = new FutureTask<V>(() -> { return processDescription.getFunction().apply(inputParameter); }); executorService.execute(task); return task.get(); } else { return ConcurrentUtils.runCallableAndWait(() -> { return processDescription.getFunction().apply(inputParameter); }); } }
public static <T> void then(Worker<T> worker, Consumer<T> consumer) { ReadOnlyBooleanProperty doneProperty = createIsDoneProperty(worker); ChangeListener<Boolean> listener = (o, oldValue, newValue) -> { if (newValue) { consumer.accept(worker.getValue()); } }; doneProperty.addListener(listener); }
/** * 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)); }
@Override public Worker<ObservableList<T>> retrieve() { final Service<ObservableList<T>> retriever = createService(observableList); return ConcurrentUtils.executeService(executor, retriever); } // private static Map<ObservableList, ListChangeListener> addListeners = new HashMap<ObservableList, ListChangeListener>();
ConcurrentUtils.runAndWait(() -> { ObservableList<Consumer<Event>> eventConsumers = consumers.get(address); if (eventConsumers != null) {
private Worker<List<CrudObjectProperty<S, T>>> innerReload(Callable<List<S>> supplier) { return ConcurrentUtils.executeService(executor, ConcurrentUtils.createService(() -> { try { List<CrudObjectProperty<S, T>> newProperties = FXCollections.observableArrayList(); List<S> dataList = supplier.call(); for (S data : dataList) { newProperties.add(new CrudObjectProperty<S, T>(data, CrudListProperty.this, crudService, executor)); } ConcurrentUtils.runAndWait(() -> setAll(newProperties)); return newProperties; } catch (Exception e) { throw new RuntimeException("TODO", e); } })); }
/** * 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 Worker<Void> delete() { return ConcurrentUtils.executeService(executor, ConcurrentUtils.createService(() -> { try { crudService.delete(get()); ConcurrentUtils.runAndWait(() -> { set(null); if (listProperty != null) { listProperty.remove(this); } }); } catch (Exception e) { throw new RuntimeException("TODO", e); } })); }
public static DataFxService<Void> createService(Runnable runnable) { return createService(new RunnableBasedDataFxTask(runnable)); }
public static <T> DataFxService<T> createService(Callable<T> callable) { return createService(new CallableBasedDataFxTask<T>(callable)); }