/** * Adds the given {@link ConfigKey} to this entity. */ public void addConfigKeys(Iterable<ConfigKey<?>> newKeys) { for (ConfigKey<?> newKey : newKeys) { addConfigKey(newKey); } }
@Test public void testAddConfigKey() throws Exception{ entity.getMutableEntityType().addConfigKey(NEW_CONFIG); assertEquals(entity.getEntityType().getConfigKeys(), ImmutableSet.builder().addAll(DEFAULT_CONFIG_KEYS).add(NEW_CONFIG).build()); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(AbstractEntity.CONFIG_KEY_ADDED, entity, NEW_CONFIG))); }
@Test public void testConfigKeysInheritance() throws Exception { Entity child = setupBasicInheritanceTest(); Assert.assertNotNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.HERITABLE_BY_DEFAULT)); Assert.assertNotNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.ALWAYS_HERITABLE)); Assert.assertNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.NEVER_INHERIT)); // it's reinheritable unless explicitly declared Assert.assertNotNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.NOT_REINHERITABLE)); app.getMutableEntityType().addConfigKey(MyEntityWithPartiallyHeritableConfig.NOT_REINHERITABLE); Assert.assertNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.NOT_REINHERITABLE)); }
@Override @SuppressWarnings("unchecked") protected void addCustoms(RebindContext rebindContext, EntityMemento memento) { for (ConfigKey<?> key : memento.getDynamicConfigKeys()) { entity.getMutableEntityType().addConfigKey(key); } for (Effector<?> eff : memento.getEffectors()) { entity.getMutableEntityType().addEffector(eff); } for (Map.Entry<AttributeSensor<?>, Object> entry : memento.getAttributes().entrySet()) { try { AttributeSensor<?> key = entry.getKey(); Object value = entry.getValue(); @SuppressWarnings("unused") // just to ensure we can load the declared type? or maybe not needed Class<?> type = (key.getType() != null) ? key.getType() : rebindContext.loadClass(key.getTypeName()); entity.sensors().setWithoutPublishing((AttributeSensor<Object>)key, value); } catch (Exception e) { LOG.warn("Error adding custom sensor "+entry+" when rebinding "+entity+" (rethrowing): "+e); throw Exceptions.propagate(e); } } setParent(rebindContext, memento); addChildren(rebindContext, memento); addMembers(rebindContext, memento); addLocations(rebindContext, memento); }
private void addSpecParameters(EntitySpec<?> spec, EntityDynamicType edType) { // if coming from a catalog item, parsed by CAMP, then the spec list of parameters is canonical, // the parent item has had its config keys set as parameters here with those non-inheritable // via type definition removed, so wipe those on the EDT to make sure non-inheritable ones are removed; // OTOH if item is blank, it was set as a java type, not inheriting it, // and the config keys on the dynamic type are the correct ones to use, and usually there is nothing in spec.parameters, // except what is being added programmatically. // (this logic could get confused if catalog item ID referred to some runtime-inherited context, // but those semantics should no longer be used -- https://issues.apache.org/jira/browse/BROOKLYN-445) if (Strings.isNonBlank(spec.getCatalogItemId())) { edType.clearConfigKeys(); } for (SpecParameter<?> param : spec.getParameters()) { edType.addConfigKey(param.getConfigKey()); if (param.getSensor()!=null) edType.addSensor(param.getSensor()); } }
Assert.assertEquals(Iterables.getOnlyElement(rawHierarchy).getContainer(), app); app.getMutableEntityType().addConfigKey(MyEntityWithPartiallyHeritableConfig.NOT_REINHERITABLE);