@Override public void addChild(Location child) { super.addChild(child); machines.add((T)child); }
protected void addChildren(RebindContext rebindContext, LocationMemento memento) { for (String childId : memento.getChildren()) { Location child = rebindContext.lookup().lookupLocation(childId); if (child != null) { location.addChild(child); } else { LOG.warn("Ignoring child {} of location {}({}), as cannot be found", new Object[] {childId, memento.getType(), memento.getId()}); } } }
@Test public void testAddChildToParentLocationReturnsExpectedLocation() { AbstractLocation parent = new ConcreteLocation(MutableMap.of("id", "1")); AbstractLocation child = new ConcreteLocation(MutableMap.of("id", "2")); parent.addChild(child); assertEquals(child.getParent(), parent); assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child)); }
public void setParent(Location newParent, boolean updateChildListParents) { if (newParent == this) { throw new IllegalArgumentException("Location cannot be its own parent: "+this); } if (newParent == parent.get()) { return; // no-op; already have desired parent } if (parent.get() != null) { Location oldParent = parent.get(); parent.set(null); if (updateChildListParents) ((AbstractLocation)oldParent).removeChild(this); } // TODO Should we support a location changing parent? The resulting unmanage/manage might cause problems. // The code above suggests we do, but maybe we should warn or throw error, or at least test it! parent.set(newParent); if (newParent != null) { if (updateChildListParents) ((AbstractLocation)newParent).addChild(this); } onChanged(); }
@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); } }