key = (ConfigKey<?>) f.get(objectOfField); } else if (HasConfigKey.class.isAssignableFrom(f.getType())) { key = ((HasConfigKey<?>) f.get(objectOfField)).getConfigKey();
((HasConfigKey<?>)f.get(optionalEntity)).getConfigKey();
Map.Entry entry = fi.next(); Object k = entry.getKey(); if (k instanceof HasConfigKey) k = ((HasConfigKey)k).getConfigKey(); if (k instanceof ConfigKey) { setConfigEvenIfOwned((ConfigKey)k, entry.getValue());
((HasConfigKey<?>)f.get(optionalInstance)).getConfigKey();
Object keyO = entry.getKey(); String key = keyO instanceof HasConfigKey ? ((HasConfigKey)keyO).getConfigKey().getName() : keyO instanceof ConfigKey ? ((ConfigKey)keyO).getName() : keyO == null ? 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()); }
@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 <T> T setConfigEvenIfOwned(HasConfigKey<T> key, T val) { return setConfigEvenIfOwned(key.getConfigKey(), val); }
public <T> T setConfig(HasConfigKey<T> key, DeferredSupplier val) { return setConfig(key.getConfigKey(), val); }
/** returns the given field as a config key, if it is an accessible config key, otherwise null */ private static ConfigKey<?> getFieldAsConfigKey(Object instance, Field f) { if (instance==null) { if ((f.getModifiers() & Modifier.STATIC)==0) // non-static field on null instance, can't be set return null; } if (ConfigKey.class.isAssignableFrom(f.getType())) { return (ConfigKey<?>) getField(instance, f); } else if (HasConfigKey.class.isAssignableFrom(f.getType())) { return ((HasConfigKey<?>)getField(instance, f)).getConfigKey(); } return null; }
public boolean containsKey(HasConfigKey<?> key) { return config.containsKey(key.getConfigKey()); }
public EnricherSpec<T> configure(Map<?,?> val) { for (Map.Entry<?, ?> entry: val.entrySet()) { if (entry.getKey()==null) throw new NullPointerException("Null key not permitted"); if (entry.getKey() instanceof CharSequence) flags.put(entry.getKey().toString(), entry.getValue()); else if (entry.getKey() instanceof ConfigKey<?>) config.put((ConfigKey<?>)entry.getKey(), entry.getValue()); else if (entry.getKey() instanceof HasConfigKey<?>) config.put(((HasConfigKey<?>)entry.getKey()).getConfigKey(), entry.getValue()); else { log.warn("Spec "+this+" ignoring unknown config key "+entry.getKey()); } } return this; }
public EntitySpec<T> configure(Map<?,?> val) { checkMutable(); for (Map.Entry<?, ?> entry: val.entrySet()) { if (entry.getKey()==null) throw new NullPointerException("Null key not permitted"); if (entry.getKey() instanceof CharSequence) flags.put(entry.getKey().toString(), entry.getValue()); else if (entry.getKey() instanceof ConfigKey<?>) config.put((ConfigKey<?>)entry.getKey(), entry.getValue()); else if (entry.getKey() instanceof HasConfigKey<?>) config.put(((HasConfigKey<?>)entry.getKey()).getConfigKey(), entry.getValue()); else { log.warn("Spec "+this+" ignoring unknown config key "+entry.getKey()); } } return this; }
@Override public <T> T setConfig(HasConfigKey<T> key, Task<T> val) { return (T) setConfig(key.getConfigKey(), val); }
@Override public <T> T setConfig(HasConfigKey<T> key, T val) { return setConfig(key.getConfigKey(), val); }
public LocationSpec<T> configure(Map<?,?> val) { for (Map.Entry<?, ?> entry: val.entrySet()) { if (entry.getKey()==null) throw new NullPointerException("Null key not permitted"); if (entry.getKey() instanceof CharSequence) flags.put(entry.getKey().toString(), entry.getValue()); else if (entry.getKey() instanceof ConfigKey<?>) config.put((ConfigKey<?>)entry.getKey(), entry.getValue()); else if (entry.getKey() instanceof HasConfigKey<?>) config.put(((HasConfigKey<?>)entry.getKey()).getConfigKey(), entry.getValue()); else { log.warn("Spec "+this+" ignoring unknown config key "+entry.getKey()); } } return this; }
public <T> T getConfig(HasConfigKey<T> key) { return getConfig(key.getConfigKey(), null); }
public PolicySpec<T> configure(Map<?,?> val) { for (Map.Entry<?, ?> entry: val.entrySet()) { if (entry.getKey()==null) throw new NullPointerException("Null key not permitted"); if (entry.getKey() instanceof CharSequence) flags.put(entry.getKey().toString(), entry.getValue()); else if (entry.getKey() instanceof ConfigKey<?>) config.put((ConfigKey<?>)entry.getKey(), entry.getValue()); else if (entry.getKey() instanceof HasConfigKey<?>) config.put(((HasConfigKey<?>)entry.getKey()).getConfigKey(), entry.getValue()); else { log.warn("Spec "+this+" ignoring unknown config key "+entry.getKey()); } } return this; }
public <V> EntitySpec<T> configure(HasConfigKey<V> key, Task<? extends V> val) { checkMutable(); config.put(checkNotNull(key, "key").getConfigKey(), val); return this; }
public <V> EntitySpec<T> configure(HasConfigKey<V> key, V val) { checkMutable(); config.put(checkNotNull(key, "key").getConfigKey(), val); return this; }