org.apache.brooklyn.api.entity.Entity.getParent()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中org.apache.brooklyn.api.entity.Entity.getParent()方法的一些代码示例,展示了Entity.getParent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.getParent()方法的具体详情如下:
包路径:org.apache.brooklyn.api.entity.Entity
类名称:Entity
方法名:getParent

Entity.getParent介绍

[英]The parent of this entity, null if no parent. The parent is normally the entity responsible for creating/destroying/managing this entity.
[中]此实体的父级,如果没有父级,则为null。父实体通常是负责创建/销毁/管理该实体的实体。

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
protected Entity getParentOfContainer(Entity container) {
  if (container==null) return null;
  return container.getParent();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/**
 * Returns true if the given descendant includes the given ancestor in its chain.
 * Does <i>NOT</i> count a node as its ancestor.
 */
public static boolean isAncestor(Entity descendant, Entity potentialAncestor) {
  Entity ancestor = descendant.getParent();
  while (ancestor != null) {
    if (ancestor.equals(potentialAncestor)) return true;
    ancestor = ancestor.getParent();
  }
  return false;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/** Returns the entity's parent, its parent's parent, and so on. */
public static Iterable<Entity> ancestorsWithoutSelf(Entity root) {
  Set<Entity> result = Sets.newLinkedHashSet();
  Entity parent = (root != null) ? root.getParent() : null;
  while (parent != null) {
    result.add(parent);
    parent = parent.getParent();
  }
  return result;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
  public boolean apply(@Nullable Entity input) {
    return (input != null) && Objects.equal(input.getParent(), parent);
  }
};

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
public boolean apply(@Nullable Entity input) {
  return (input != null) && Objects.equal(input.getParent(), parent);
}
@Override

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public static Entity catalogItemScopeRoot(Entity entity) {
  Entity root = entity;
  while (root.getParent() != null &&
      root != root.getParent() &&
      Objects.equal(root.getParent().getCatalogItemId(), root.getCatalogItemId())) {
    root = root.getParent();
  }
  return root;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/** if no locations are supplied, returns locations on the entity, or in the ancestors, until it finds a non-empty set,
 * or ultimately the empty set if no locations are anywhere */ 
public static Collection<? extends Location> getLocationsCheckingAncestors(Collection<? extends Location> locations, Entity entity) {
  // look in ancestors if location not set here
  Entity ancestor = entity;
  while ((locations==null || locations.isEmpty()) && ancestor!=null) {
    locations = ancestor.getLocations();
    ancestor = ancestor.getParent();
  }
  return locations;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
  public boolean apply(SensorEvent<T> input) {
    return parent != null && input.getSource() != null && parent.equals(input.getSource().getParent());
  }
};

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public static Set<Location> getAllInheritedLocations(Entity entity) {
  Set<Location> result = MutableSet.of();
  while (entity!=null) {
    result.addAll(entity.getLocations());
    entity = entity.getParent();
  }
  return result;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testAddChildUsingSpec() {
  Entity e = app.addChild(EntitySpec.create(TestEntity.class));
  
  assertEquals(e.getParent(), app);
  assertEquals(app.getChildren(), ImmutableList.of(e));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testSetParentInConstructorArgument() {
  Entity e = new AbstractEntity(app) {};
  
  assertEquals(e.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
  assertEquals(e.getApplication(), app);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testParentCanHaveMultipleChildren() {
  Entity e = app.addChild(EntitySpec.create(TestEntity.class));
  Entity e2 = app.addChild(EntitySpec.create(TestEntity.class));
  
  assertEquals(e.getParent(), app);
  assertEquals(e2.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e,e2));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testSetOwnerInConstructorMap() {
  Entity e = new AbstractEntity(MutableMap.of("owner", app)) {};
  
  assertEquals(e.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
  assertEquals(e.getApplication(), app);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testCreatesEntity() throws Exception {
  EntitySpec<TestApplication> spec = EntitySpec.create(TestApplication.class);
  TestApplicationImpl app = (TestApplicationImpl) factory.createEntity(spec, Optional.absent());
  
  Entity proxy = app.getProxy();
  assertTrue(proxy instanceof Application, "proxy="+app);
  assertFalse(proxy instanceof TestApplicationImpl, "proxy="+app);
  
  assertEquals(proxy.getParent(), null);
  assertSame(proxy.getApplication(), proxy);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test(enabled = false) // FIXME fails currently
public void testRemoveChild() {
  Entity e = app.addChild(EntitySpec.create(TestEntity.class));
  app.removeChild(e);
  
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of());
  assertEquals(e.getParent(), null);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testAddChildWhenMatchesParentSetInSpec() {
  Entity e = app.addChild(EntitySpec.create(TestEntity.class).parent(app));
  
  assertEquals(e.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testUnmanageEntityRemovedAsChild() {
  Entity e = app.addChild(EntitySpec.create(TestEntity.class));
  Entities.unmanage(e);
  
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of());
  assertEquals(e.getParent(), null);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testSpecDeclaresParent() {
  Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app));
  
  assertEquals(e.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testSetParentInSetterMethod() {
  Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
  e.setParent(app);
  
  assertEquals(e.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
  assertEquals(e.getApplication(), app);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testSetParentWhenMatchesParentSetInSpec() {
  Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app));
  e.setParent(app);
  
  assertEquals(e.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
}

相关文章