Java Code Examples for org.apache.brooklyn.api.location.Location#setParent()

The following examples show how to use org.apache.brooklyn.api.location.Location#setParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public boolean removeChild(Location child) {
    boolean removed;
    synchronized (children) {
        removed = children.remove(child);
    }
    if (removed) {
        if (child instanceof Closeable) {
            Streams.closeQuietly((Closeable)child);
        }
        child.setParent(null);
        
        if (isManaged() && Locations.isManaged(child)) {
            // This is called as part of child's LocalLocationManager.unmanage; don't try to 
            // unmanage it yet again as then would get a log.warn!
            getManagementContext().getLocationManager().unmanage(child);
        }
    }
    onChanged();
    return removed;
}
 
Example 2
Source File: AbstractLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public void addChild(Location child) {
    // Previously, setParent delegated to addChildLocation and we sometimes ended up with
    // duplicate entries here. Instead this now uses a similar scheme to 
    // AbstractLocation.setParent/addChild (with any weaknesses for distribution that such a 
    // scheme might have...).
    // 
    // We continue to use a list to allow identical-looking locations, but they must be different 
    // instances.
    
    synchronized (children) {
        for (Location contender : children) {
            if (contender == child) {
                // don't re-add; no-op
                return;
            }
        }

        children.add(child);
    }
    
    if (isManaged()) {
        if (!getManagementContext().getLocationManager().isManaged(child)) {
            Locations.manage(child, getManagementContext());
        }
    } else if (getManagementContext() != null) {
        if (((LocalLocationManager)getManagementContext().getLocationManager()).getLocationEvenIfPreManaged(child.getId()) == null) {
            ((ManagementContextInternal)getManagementContext()).prePreManage(child);
        }
    }

    children.add(child);
    child.setParent(this);
    
    onChanged();
}
 
Example 3
Source File: AbstractLocationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSettingParentLocation() {
    Location location = createConcrete();
    Location locationSub = createConcrete();
    locationSub.setParent(location);
    
    assertEquals(ImmutableList.copyOf(location.getChildren()), ImmutableList.of(locationSub));
    assertEquals(locationSub.getParent(), location);
}
 
Example 4
Source File: AbstractLocationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearingParentLocation() {
    Location location = createConcrete();
    Location locationSub = createConcrete();
    locationSub.setParent(location);
    
    locationSub.setParent(null);
    assertEquals(ImmutableList.copyOf(location.getChildren()), Collections.emptyList());
    assertEquals(locationSub.getParent(), null);
}
 
Example 5
Source File: AbstractLocationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsLocation() {
    Location location = createConcrete();
    Location locationSub = createConcrete();
    locationSub.setParent(location);
    
    assertTrue(location.containsLocation(location));
    assertTrue(location.containsLocation(locationSub));
    assertFalse(locationSub.containsLocation(location));
}
 
Example 6
Source File: AbstractLocationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void setParentLocationReturnsExpectedLocation() {
    Location parent = createConcrete(MutableMap.of("name", "Middle Earth"));
    Location child = createConcrete(MutableMap.of("name", "The Shire"));
    child.setParent(parent);
    assertEquals(child.getParent(), parent);
    assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child));
}