final State currentDesiredState = getDesiredState(); doAfter(beforeDelete(), this::deleteChildren).then(this::onDelete) .then(() -> { final State currentState = getState(); setState(State.DELETED); notifyStateChanged(currentState, State.DELETED); changeAttribute(ConfiguredObject.DESIRED_STATE, State.DELETED); attributeSet(ConfiguredObject.DESIRED_STATE, currentDesiredState, State.DELETED); unregister(true); getName()); return Futures.immediateFuture(null); }); addFutureCallback(future, new FutureCallback<Void>()
@Override public final ListenableFuture<Void> deleteAsync() { final State currentDesiredState = getDesiredState(); if (currentDesiredState == State.DELETED) { return Futures.immediateFuture(null); } Map<String, Object> attributes = Collections.singletonMap(ConfiguredObject.DESIRED_STATE, State.DELETED); ConfiguredObject<?> proxyForValidation = createProxyForValidation(attributes); authoriseSetAttributes(proxyForValidation, attributes); validateChange(proxyForValidation, attributes.keySet()); checkReferencesOnDelete(getHierarchyRoot(this), this); // for DELETED state we should invoke transition method first to make sure that object can be deleted. // If method results in exception being thrown due to various integrity violations // then object cannot be deleted without prior resolving of integrity violations. // The state transition should be disallowed. if(_parent instanceof AbstractConfiguredObject<?>) { ((AbstractConfiguredObject<?>)_parent).validateChildDelete(AbstractConfiguredObject.this); } else if (_parent instanceof AbstractConfiguredObjectProxy) { ((AbstractConfiguredObjectProxy)_parent).validateChildDelete(AbstractConfiguredObject.this); } return deleteNoChecks(); }
@Override protected ListenableFuture<Void> onDelete() { removeDeleteTask(_deleteModelTask); return super.onDelete(); }
protected ListenableFuture<Void> attainState() { return attainState(getDesiredState()); }
private ListenableFuture<Void> attainStateIfOpenedOrReopenFailed() { if (_openComplete || getDesiredState() == State.DELETED) { return attainState(); } else if (_openFailed) { return openAsync(); } return Futures.immediateFuture(null); }
protected final <C extends ConfiguredObject<?>> void authoriseCreateChild(Class<C> childClass, Map<String, Object> attributes) throws AccessControlException { ConfiguredObject<?> configuredObject = createProxyForAuthorisation(childClass, attributes, this); authorise(configuredObject, null, Operation.CREATE, Collections.emptyMap()); }
@Override public ListenableFuture<Void> execute() final State state = getState(); final State currentDesiredState = getDesiredState(); if(desiredState == currentDesiredState && desiredState != state) return doAfter(attainStateIfOpenedOrReopenFailed(), new Runnable() return deleteAsync(); ConfiguredObject<?> proxyForValidation = createProxyForValidation(attributes); authoriseSetAttributes(proxyForValidation, attributes); validateChange(proxyForValidation, attributes.keySet()); attributeSet(ConfiguredObject.DESIRED_STATE, currentDesiredState, desiredState); return attainStateIfOpenedOrReopenFailed();
protected void changeAttributes(final Map<String, Object> attributes) Collection<String> names = getAttributeNames(); Set<String> updatedAttributes = new HashSet<>(attributes.size()); try bulkChangeStart(); for (Map.Entry<String, Object> entry : attributes.entrySet()) Object expected = getAttribute(attributeName); if (changeAttribute(attributeName, desired)) attributeSet(attributeName, expected, desired); updatedAttributes.add(attributeName); postSetAttributes(updatedAttributes); bulkChangeEnd();
if (managesChildStorage()) applyToChildren(child -> { childDeleteFuture = ((AbstractConfiguredObject<?>) child).deleteNoChecks(); addFutureCallback(childDeleteFuture, new FutureCallback<Void>() child.getClass().getSimpleName(), child.getName(), t); }, getTaskExecutor()); childDeleteFutures.add(childDeleteFuture); }); return Futures.transform(combinedFuture, input -> null, getTaskExecutor());
@Override public void onValidate() { super.onValidate(); if(!isDurable()) { throw new IllegalArgumentException(getClass().getSimpleName() + " must be durable"); } }
@Override public ListenableFuture<Void> execute() LOGGER.debug("Closing " + AbstractConfiguredObject.this.getClass().getSimpleName() + " : " + getName()); final SettableFuture<Void> returnFuture = SettableFuture.create(); DynamicStateWithFuture desiredStateWithFuture = new DynamicStateWithFuture(DynamicState.CLOSED, returnFuture); doAfter(beforeClose(), new Callable<ListenableFuture<Void>>() addFutureCallback(future, new FutureCallback<Void>()
private ListenableFuture<Void> attainState(State desiredState) final State currentState = getState(); ListenableFuture<Void> returnVal; Method stateChangingMethod = getStateChangeMethod(currentState, desiredState); if(stateChangingMethod != null) addFutureCallback(stateTransitionFuture, new FutureCallback<Void>() stateTransitionResult.setException(t); }, getTaskExecutor()); returnVal = stateTransitionResult;
@Override protected void validateChange(final ConfiguredObject<?> proxyForValidation, final Set<String> changedAttributes) { super.validateChange(proxyForValidation, changedAttributes); final CloudFoundryDashboardManagementGroupProvider<?> validationProxy = (CloudFoundryDashboardManagementGroupProvider<?>) proxyForValidation; validateSecureEndpoint(validationProxy); validateMapping(validationProxy); }
onOpen(); notifyStateChanged(State.UNINITIALIZED, getState()); applyToChildren(new Action<ConfiguredObject<?>>()
onResolve(); postResolve(); applyToChildren(new Action() postResolveChildren();
@Override public void onSuccess(final A result) { try { final ListenableFuture<V> future = second.call(result); addFutureCallback(future, new FutureCallback<V>() { @Override public void onSuccess(final V result) { returnVal.set(result); } @Override public void onFailure(final Throwable t) { returnVal.setException(t); } }, executor); } catch (Throwable e) { returnVal.setException(e); } }
addFutureCallback(future, new FutureCallback<V>()
applyToChildren(new Action<ConfiguredObject<?>>() addFutureCallback(combinedChildStateFuture, new FutureCallback<List<Void>>() }, getTaskExecutor());
addFutureCallback(attainState(), new FutureCallback<Void>() }, getTaskExecutor());
@Override public void performAction(final ConfiguredObject<?> child) { ListenableFuture<Void> childCloseFuture = child.closeAsync(); addFutureCallback(childCloseFuture, new FutureCallback<Void>() { @Override public void onSuccess(final Void result) { } @Override public void onFailure(final Throwable t) { LOGGER.error("Exception occurred while closing {} : {}", child.getClass().getSimpleName(), child.getName(), t); } }, getTaskExecutor()); childCloseFutures.add(childCloseFuture); } });