/** * Invoked by {@link EntityManagementSupport} when this entity is becoming managed (i.e. it has a working * management context, but before the entity is visible to other entities). */ public void onManagementStarting() { if (isLegacyConstruction()) { entityType.setName(getEntityTypeName()); if (displayNameAutoGenerated) displayName.set(getEntityType().getSimpleName()+":"+id.substring(0, 4)); } }
@SuppressWarnings("unchecked") public <T> T getConfig(ConfigKey<T> key, T defaultValue) { // FIXME What about inherited task in config?! // alex says: think that should work, no? // FIXME What if someone calls getConfig on a task, before setting parent app? // alex says: not supported (throw exception, or return the task) // In case this entity class has overridden the given key (e.g. to set default), then retrieve this entity's key // TODO If ask for a config value that's not in our configKeys, should we really continue with rest of method and return key.getDefaultValue? // e.g. SshBasedJavaAppSetup calls setAttribute(JMX_USER), which calls getConfig(JMX_USER) // but that example doesn't have a default... ConfigKey<T> ownKey = entity!=null ? (ConfigKey<T>)elvis(entity.getEntityType().getConfigKey(key.getName()), key) : key; ExecutionContext exec = entity.getExecutionContext(); // Don't use groovy truth: if the set value is e.g. 0, then would ignore set value and return default! if (ownKey instanceof ConfigKeySelfExtracting) { if (((ConfigKeySelfExtracting<T>)ownKey).isSet(ownConfig)) { return ((ConfigKeySelfExtracting<T>)ownKey).extractValue(ownConfig, exec); } else if (((ConfigKeySelfExtracting<T>)ownKey).isSet(inheritedConfig)) { return ((ConfigKeySelfExtracting<T>)ownKey).extractValue(inheritedConfig, exec); } } else { LOG.warn("Config key {} of {} is not a ConfigKeySelfExtracting; cannot retrieve value; returning default", ownKey, this); } return TypeCoercions.coerce((defaultValue != null) ? defaultValue : ownKey.getDefaultValue(), key.getTypeToken()); }
public void setManagementContext(ManagementContextInternal managementContext) { getManagementSupport().setManagementContext(managementContext); entityType.setName(getEntityTypeName()); if (displayNameAutoGenerated) displayName.set(getEntityType().getSimpleName()+":"+id.substring(0, 4));