@Override public <R> R invoke(Function<T, R> invocation) { try { return executeWithResult(() -> invocation.apply(aggregateRoot)); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new AggregateInvocationException("Exception occurred while invoking an aggregate", e); } }
/** * Executes the given task. While the task is being executed the current aggregate will be registered with the * current thread as the 'current' aggregate. * * @param task the task to execute on the aggregate */ protected void execute(Runnable task) { try { executeWithResult(() -> { task.run(); return null; }); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new AggregateInvocationException("Exception while invoking a task for an aggregate", e); } }