本文整理了Java中org.apache.brooklyn.api.entity.Entity.addChild()
方法的一些代码示例,展示了Entity.addChild()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.addChild()
方法的具体详情如下:
包路径:org.apache.brooklyn.api.entity.Entity
类名称:Entity
方法名:addChild
[英]Add a child Entity, and set this entity as its parent, returning the added child.
As with #addChild(EntitySpec) the child is not brought under management as part of this call. It should not be managed prior to this call either.
[中]添加子实体,并将此实体设置为其父实体,返回添加的子实体。
与#addChild(EntitySpec)一样,此调用不会将子项置于管理之下。也不应在此调用之前对其进行管理。
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
suppliedParent.addChild(getProxyIfAvailable());
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
/** adds entities from the given yaml, under the given parent; but does not start them */
public static List<Entity> addChildrenUnstarted(final Entity parent, String yaml) {
log.debug("Creating child of "+parent+" from yaml:\n{}", yaml);
ManagementContext mgmt = parent.getApplication().getManagementContext();
EntitySpec<? extends Application> specA = createEntitySpecForApplication(mgmt, yaml);
// see whether we can promote children
List<EntitySpec<?>> specs = MutableList.of();
if (!canUnwrapEntity(specA)) {
// if not promoting, set a nice name if needed
if (Strings.isEmpty(specA.getDisplayName())) {
int size = specA.getChildren().size();
String childrenCountString = size+" "+(size!=1 ? "children" : "child");
specA.displayName("Dynamically added "+childrenCountString);
}
}
specs.add(unwrapEntity(specA));
final List<Entity> children = MutableList.of();
for (EntitySpec<?> spec: specs) {
Entity child = parent.addChild(spec);
children.add(child);
}
return children;
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testIsDescendant() {
Entity e = app.addChild(EntitySpec.create(TestEntity.class));
Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
assertTrue(Entities.isDescendant(app, e));
assertTrue(Entities.isDescendant(app, e2));
assertFalse(Entities.isDescendant(e2, e));
assertFalse(Entities.isDescendant(e2, e2));
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
entity.addChild(child);
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
entity.addChild(getProxyIfAvailable());
config().refreshInheritedConfig();
previouslyOwned = true;
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testIsAncestor() {
Entity e = app.addChild(EntitySpec.create(TestEntity.class));
Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
assertTrue(Entities.isAncestor(e2, app));
assertTrue(Entities.isAncestor(e2, e));
assertFalse(Entities.isAncestor(e2, e2));
assertFalse(Entities.isAncestor(e, e2));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testChildingOneselfForbidden() {
Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
try {
e.addChild(e);
Asserts.shouldHaveFailedPreviously();
} catch (Exception ex) {
Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class);
if (cause == null || !cause.toString().contains("cannot own itself")) {
throw ex;
}
}
assertNull(e.getParent());
assertEquals(e.getChildren(), ImmutableList.of());
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testHierarchyOfOwners() {
Entity e = app.addChild(EntitySpec.create(TestEntity.class));
Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
Entity e3 = e2.addChild(EntitySpec.create(TestEntity.class));
assertEquals(app.getParent(), null);
assertEquals(e.getParent(), app);
assertEquals(e2.getParent(), e);
assertEquals(e3.getParent(), e2);
assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
assertEqualsIgnoringOrder(e.getChildren(), ImmutableList.of(e2));
assertEqualsIgnoringOrder(e2.getChildren(), ImmutableList.of(e3));
assertEqualsIgnoringOrder(e3.getChildren(), ImmutableList.of());
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testParentalLoopForbiddenViaAddChild() {
Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
try {
e2.addChild(e);
Asserts.shouldHaveFailedPreviously();
} catch (Exception ex) {
Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class);
if (cause == null || !cause.toString().contains("loop detected trying to add child")) {
throw ex;
}
}
assertEqualsIgnoringOrder(e.getChildren(), ImmutableList.of(e2));
assertEqualsIgnoringOrder(e2.getChildren(), ImmutableList.of());
assertEquals(e.getParent(), null);
assertEquals(e2.getParent(), e);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testParentalLoopForbiddenViaSetParent() {
Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
try {
e.setParent(e2);
Asserts.shouldHaveFailedPreviously();
} catch (Exception ex) {
Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class);
if (cause == null || !cause.toString().contains("loop detected trying to set parent")) {
throw ex;
}
}
assertEqualsIgnoringOrder(e.getChildren(), ImmutableList.of(e2));
assertEqualsIgnoringOrder(e2.getChildren(), ImmutableList.of());
assertEquals(e.getParent(), null);
assertEquals(e2.getParent(), e);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testMoreEntitiesV1() throws Exception {
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V1_PATH);
RegisteredType c2 = addMoreEntityV1(mgmt, TEST_VERSION);
// test load and instantiate
Entity me = addItemFromCatalog(c2);
Assert.assertEquals(me.getCatalogItemId(), CatalogUtils.getVersionedId(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY, TEST_VERSION));
assertV1MethodCall(me);
assertV1EffectorCall(me);
// test adding a child gets the right type; this time by entity parent hierarchy
@SuppressWarnings({ "unchecked" })
Entity me2 = me.addChild( mgmt.getTypeRegistry().createSpec(c2, null, EntitySpec.class) );
Assert.assertEquals(me2.getCatalogItemId(), CatalogUtils.getVersionedId(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY, TEST_VERSION));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testInheritedDefault() {
final Entity e1 = app.addChild(EntitySpec.create(MyBaseEntity.class));
final Entity e2 = e1.addChild(EntitySpec.create(BasicEntity.class));
Assert.assertEquals(e2.config().get(MyBaseEntity.SUPER_KEY_1), MyBaseEntity.SUPER_KEY_1.getDefaultValue());
Assert.assertEquals(e2.config().get(ConfigKeys.newStringConfigKey(MyBaseEntity.SUPER_KEY_1.getName())), MyBaseEntity.SUPER_KEY_1.getDefaultValue());
}
内容来源于网络,如有侵权,请联系作者删除!