/** * Tries to modify the State by executing {@code work} on it. * * @param work Work that modifies the State * * @return The result of executing {@code work}, or * null if the State is null * @since 2.15 */ default <Result> Result tryModify(IUnitOfWork<Result, State> work) { return tryModify(work, () -> null); }
@Override public void setCancelIndicator(final CancelIndicator cancelIndicator) { super.setCancelIndicator(cancelIndicator); ((CancelableUnitOfWork<Result, State>) work).setCancelIndicator(cancelIndicator); }
@Override public final Object exec(T state) throws Exception { process(state); return null; }
@Override public <Result> Result modify(IUnitOfWork<Result, State> work) { acquireWriteLock(); State state = null; Result exec = null; try { state = getState(); beforeModify(state, work); exec = work.exec(state); return exec; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new WrappedException(e); } finally { releaseWriteLock(); try { acquireReadLock(); afterModify(state, exec, work); } finally { releaseReadLock(); } } }
public <T> T readOnly(IUnitOfWork<T, P> work) { acquireReadLock(); try { P state = getState(); beforeReadOnly(state, work); T exec = work.exec(state); afterReadOnly(state, exec, work); return exec; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new WrappedException(e); } finally { releaseReadLock(); } }
@Override public Result exec(final State state, final CancelIndicator cancelIndicator) throws Exception { if (state == null) { return defaultResult.get(); } return work.exec(state); } }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * * @param work Work to execute on the State * @param defaultResult Supplies a result in case the State is null * * @return The result of executing {@code work}, or * the result of querying {@code defaultResult} if the State is null * @since 2.14 */ default <Result> Result tryReadOnly( IUnitOfWork<Result, State> work, Supplier<? extends Result> defaultResult ) { // Some implementations rely on the type of {@code work} if (work instanceof CancelableUnitOfWork<?, ?>) { return readOnly(new WrappingCancelableUnitOfWork<>(defaultResult, work)); } return readOnly((state) -> { if (state == null) { return defaultResult.get(); } return work.exec(state); }); }
/** * Tries to modify the State by executing {@code work} on it. * * @param work Work that modifies the State * @param defaultResult Supplies a result in case the State is null * * @return The result of executing {@code work}, or * the result of querying {@code defaultResult} if the State is null * @since 2.14 */ default <Result> Result tryModify( IUnitOfWork<Result, State> work, Supplier<? extends Result> defaultResult ) { // Some implementations rely on the type of {@code work} if (work instanceof CancelableUnitOfWork<?, ?>) { return modify(new WrappingCancelableUnitOfWork<>(defaultResult, work)); } return modify((state) -> { if (state == null) { return defaultResult.get(); } return work.exec(state); }); }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * Cancels all cancelable readers before executing the {@link IUnitOfWork}. * For interactive jobs that need fastest possible execution. * * @param work Work to execute on the State * @param defaultResult Supplies a result in case the State is null * * @return The result of executing {@code work}, or * the result of querying {@code defaultResult} if the State is null * @since 2.14 * @see CancelableUnitOfWork */ default <Result> Result tryPriorityReadOnly( IUnitOfWork<Result, State> work, Supplier<? extends Result> defaultResult ) { // Some implementations rely on the type of {@code work} if (work instanceof CancelableUnitOfWork<?, ?>) { return priorityReadOnly(new WrappingCancelableUnitOfWork<>(defaultResult, work)); } return priorityReadOnly((state) -> { if (state == null) { return defaultResult.get(); } return work.exec(state); }); }
public abstract R exec(P state, CancelIndicator cancelIndicator) throws Exception; }
public List<Issue> createIssues(final IProgressMonitor monitor) { final List<Issue> issues = xtextDocument .readOnly(new IUnitOfWork<List<Issue>, XtextResource>() { public List<Issue> exec(XtextResource resource) throws Exception { if (resource == null || resource.isValidationDisabled()) return Collections.emptyList(); return resourceValidator.validate(resource, getCheckMode(), new CancelIndicator() { public boolean isCanceled() { return monitor.isCanceled(); } }); } }); return issues; }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * * @param work Work to execute on the State * * @return The result of executing {@code work}, or * null if the State is null * @since 2.15 */ default <Result> Result tryReadOnly(IUnitOfWork<Result, State> work) { return tryReadOnly(work, () -> null); }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * Cancels all cancelable readers before executing the {@link IUnitOfWork}. * For interactive jobs that need fastest possible execution. * * @param work Work to execute on the State * * @return The result of executing {@code work}, or * null if the State is null * @since 2.15 * @see CancelableUnitOfWork */ default <Result> Result tryPriorityReadOnly(IUnitOfWork<Result, State> work) { return tryPriorityReadOnly(work, () -> null); }
@Override public <Result> Result readOnly(IUnitOfWork<Result, State> work) { acquireReadLock(); try { State state = getState(); beforeReadOnly(state, work); Result exec = work.exec(state); afterReadOnly(state, exec, work); return exec; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new WrappedException(e); } finally { releaseReadLock(); } }
@Override public <Result extends Object> Result execute(final IUnitOfWork<Result, ? super JavaResource> unit) throws Exception { synchronized (this.getLock()) { return unit.exec(this); } }
public final Object exec(T state) throws Exception { process(state); return null; }
/** * {@inheritDoc} * * @since 2.4 */ /* @Nullable */ @Override public <Result> Result execute(/* @NonNull */ IUnitOfWork<Result, ? super TypeResource> unit) throws Exception { synchronized (getLock()) { return unit.exec(this); } }
public R exec(XtextResource state) throws Exception { ResourceSet localContext = state.getResourceSet(); if (localContext != null) return work.exec(localContext); return null; } });
/** * {@inheritDoc} * * @since 2.4 */ /* @Nullable */ @Override public <Result> Result execute(/* @NonNull */ IUnitOfWork<Result, ? super BatchLinkableResource> unit) throws Exception { synchronized (getLock()) { return unit.exec(this); } }
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) { try { return work.exec(resourceSet); } catch(Exception exc) { throw new WrappedException(exc); } }