@Override public ConfigMapImpl submap(Predicate<ConfigKey<?>> filter) { ConfigMapImpl m = new ConfigMapImpl(adjunct); for (Map.Entry<ConfigKey<?>,Object> entry: ownConfig.entrySet()) if (filter.apply(entry.getKey())) m.ownConfig.put(entry.getKey(), entry.getValue()); return m; }
public Map<ConfigKey<?>, Object> getAllConfig() { return configsInternal.getAllConfig(); }
@Override public <T> T getConfig(ConfigKey<T> key) { return getConfig(key, null); }
@SuppressWarnings("unchecked") @Override public <T> T setConfig(ConfigKey<T> key, T val) { if (entity != null && isRunning()) { doReconfigureConfig(key, val); } return (T) configsInternal.setConfig(key, val); }
@Override public void setEntity(EntityLocal entity) { if (configsInternal.getRawConfig(RESIZE_OPERATOR) == null) { Preconditions.checkArgument(entity instanceof Resizable, "Provided entity must be an instance of Resizable, because no custom-resizer operator supplied"); } super.setEntity(entity); this.poolEntity = entity; if (getMetric() != null) { Entity entityToSubscribeTo = (getEntityWithMetric() != null) ? getEntityWithMetric() : entity; subscribe(entityToSubscribeTo, getMetric(), metricEventHandler); } subscribe(poolEntity, getPoolColdSensor(), utilizationEventHandler); subscribe(poolEntity, getPoolHotSensor(), utilizationEventHandler); subscribe(poolEntity, getPoolOkSensor(), utilizationEventHandler); }
public <T> T getConfig(ConfigKey<T> key) { return configsInternal.getConfig(key); }
@Override public <T> T getConfig(HasConfigKey<T> key) { return getConfig(key.getConfigKey(), null); }
@SuppressWarnings("unchecked") @Override 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 = adjunct!=null ? (ConfigKey<T>)elvis(adjunct.getAdjunctType().getConfigKey(key.getName()), key) : key; // 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)) { // FIXME Should we support config from futures? How to get execution context before setEntity? EntityLocal entity = adjunct.entity; ExecutionContext exec = (entity != null) ? ((EntityInternal)entity).getExecutionContext() : null; return ((ConfigKeySelfExtracting<T>)ownKey).extractValue(ownConfig, 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()); }