Java Code Examples for org.apache.brooklyn.core.entity.Entities#UNCHANGED

The following examples show how to use org.apache.brooklyn.core.entity.Entities#UNCHANGED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Transformer.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private U resolveImmediately(Object rawVal, Sensor<U> targetSensor) {
    if (rawVal == Entities.UNCHANGED || rawVal == Entities.REMOVE) {
        // If it's a special marker-object, then don't try to transform it
        return (U) rawVal;
    }

    // evaluate immediately, or return null.
    // For vals that implement ImmediateSupplier, we'll use that to get the value
    // (or Maybe.absent) without blocking.
    // Otherwise, the Tasks.resolving will give it its best shot at resolving without
    // blocking on external events (such as waiting for another entity's sensor).
    return (U) Tasks.resolving(rawVal).as(targetSensor.getTypeToken())
            .context(entity)
            .description("Computing sensor "+targetSensor+" from "+rawVal)
            .deep(true, false)
            .immediately(true)
            .getMaybe().orNull();
}
 
Example 2
Source File: UpdatingMap.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/**
 * Called whenever the values for the set of producers changes (e.g. on an event, or on a member added/removed).
 */
@SuppressWarnings("unchecked")
protected void onUpdated() {
    try {
        Object v = computing.apply(producer.getAttribute(sourceSensor));
        if (v == null && Boolean.TRUE.equals(removingIfResultIsNull)) {
            v = Entities.REMOVE;
        }
        if (v == Entities.UNCHANGED) {
            // nothing
        } else {
            TKey key = this.key;
            if (key==null) key = (TKey) sourceSensor.getName();

            ServiceStateLogic.updateMapSensorEntry(entity, targetSensor, key, (TVal) v);
        }
    } catch (Throwable t) {
        LOG.warn("Error calculating map update for enricher "+this, t);
        throw Exceptions.propagate(t);
    }
}
 
Example 3
Source File: ServiceStateLogic.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void setActualState(Maybe<Lifecycle> state) {
    if (log.isTraceEnabled()) log.trace("{} setting actual state {}", this, state);
    if (((EntityInternal)entity).getManagementSupport().isNoLongerManaged()) {
        // won't catch everything, but catches some
        BrooklynLogging.log(log, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity),
            entity+" is no longer managed when told to set actual state to "+state+"; suppressing");
        return;
    }
    Object newVal = (state.isAbsent() ? Entities.UNCHANGED : (state.get() == null ? Entities.REMOVE : state.get()));
    emit(SERVICE_STATE_ACTUAL, newVal);
}
 
Example 4
Source File: AbstractEnricher.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected <T> void emit(Sensor<T> sensor, Object val) {
    checkState(entity != null, "entity must first be set");
    if (val == Entities.UNCHANGED) {
        return;
    }
    if (val == Entities.REMOVE) {
        ((EntityInternal)entity).sensors().remove((AttributeSensor<T>) sensor);
        return;
    }
    
    T newVal = TypeCoercions.coerce(val, sensor.getTypeToken());
    Maybe<T> published = Maybe.of(newVal);
    if (sensor instanceof AttributeSensor) {
        AttributeSensor<T> attribute = (AttributeSensor<T>)sensor;
        if (Boolean.TRUE.equals(suppressDuplicates)) {
            DeduplicatingAttributeModifier<T> modifier = DeduplicatingAttributeModifier.create(newVal);
            entity.sensors().modify(attribute, modifier);
            published = modifier.getLastValue();
        } else {
            entity.sensors().set(attribute, newVal);
        }
    } else { 
        entity.sensors().emit(sensor, newVal);
    }
    if (published!=null && published.isPresent()) {
        highlightActionPublishSensor(sensor, published.get());
    }
}