@Override public void onFailure(Throwable throwable) throws Exception { failureHandler.invoke(throwable); } });
/** * Calls the given handler for each superclass of the given one. * <p> * Calls the handler for the given class and each of its superclasses until {@code Object} is reached. * * @param clazz the class to start from * @param handler the handler to call for each superclass * @throws Exception thrown if the handler throws an exception */ public static void walkHierarchy(@Nonnull Class<?> clazz, @Nonnull Callback<Class<?>> handler) throws Exception { Class<?> current = clazz; while (current != null && !Object.class.equals(current)) { handler.invoke(current); current = current.getSuperclass(); } }
@Override public void onSuccess(V value) throws Exception { try { successHandler.invoke(value); } catch (Exception t) { fail(t); } }
@Override public void onSuccess(V value) throws Exception { try { successHandler.invoke(value); } catch (Exception e) { promise.fail(e); } }
@Override @SuppressWarnings("unchecked") public void onRemoval(RemovalNotification<Object, Object> notification) { if (removeListener != null) { try { CacheEntry<K, V> entry = (CacheEntry<K, V>) notification.getValue(); removeListener.invoke(Tuple.create(entry.getKey(), entry.getValue())); } catch (Exception e) { Exceptions.handle(e); } } } }
/** * Tries to apply the given changes and to save the resulting entity. * <p> * Tries to perform the given modifications and then to update the entity. If an optimistic lock error occurs, * the entity is refreshed and the modifications are re-executed along with another update. * * @param entity the entity to update * @param preSaveModifier the changes to perform on the entity * @param <E> the type of the entity to update * @throws HandledException if either any other exception occurs, or if all three attempts fail with an optimistic * lock error. */ public <E extends Entity> void retryUpdate(E entity, Callback<E> preSaveModifier) { Monoflop mf = Monoflop.create(); retry(() -> { E entityToUpdate = entity; if (mf.successiveCall()) { entityToUpdate = refreshIfPossible(entity); } preSaveModifier.invoke(entityToUpdate); tryUpdate(entityToUpdate); }); }
/** * Tries to apply the given changes and to save the resulting entity without running the entities save checks and handlers. * <p> * Tries to perform the given modifications and then to update the entity. If an optimistic lock error occurs, * the entity is refreshed and the modifications are re-executed along with another update. * * @param entity the entity to update * @param preSaveModifier the changes to perform on the entity * @param <E> the type of the entity to update * @throws HandledException if either any other exception occurs, or if all three attempts fail with an optimistic * lock error. */ public <E extends Entity> void retryUpdateUnchecked(E entity, Callback<E> preSaveModifier) { Monoflop mf = Monoflop.create(); retry(() -> { E entityToUpdate = entity; if (mf.successiveCall()) { entityToUpdate = refreshIfPossible(entity); } preSaveModifier.invoke(entityToUpdate); tryUpdateUnchecked(entityToUpdate); }); }