@Override public void setParent(Location newParent) { setParent(newParent, true); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private synchronized void unmanageNonRecursiveClearItsFields(Location loc, ManagementTransitionMode mode) { if (mode.isDestroying()) { ((AbstractLocation)loc).setParent(null, true); Location parent = ((AbstractLocation)loc).getParent(); if (parent instanceof ProvisioningLocation<?>) { try { ((ProvisioningLocation)parent).release(loc); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.debug("Error releasing "+loc+" in its parent "+parent+": "+e); } } } else { // if not destroying, don't change the parent's children list ((AbstractLocation)loc).setParent(null, false); } // clear config to help with GC; everyone says you're not supposed to, but this really seems to help, // else config bag is littered with refs to entities etc and some JVMs seem to keep them around much longer ((AbstractLocation)loc).config().removeAllLocalConfig(); }
@Test public void testClearingParentLocation() { AbstractLocation location = new ConcreteLocation(); AbstractLocation locationSub = new ConcreteLocation(); locationSub.setParent(location); locationSub.setParent(null); assertEquals(ImmutableList.copyOf(location.getChildren()), Collections.emptyList()); assertEquals(locationSub.getParent(), null); }
@Test public void testSettingParentLocation() { AbstractLocation location = new ConcreteLocation(); AbstractLocation locationSub = new ConcreteLocation(); locationSub.setParent(location); assertEquals(ImmutableList.copyOf(location.getChildren()), ImmutableList.of(locationSub)); assertEquals(locationSub.getParent(), location); }
@Test public void testContainsLocation() { AbstractLocation location = new ConcreteLocation(); AbstractLocation locationSub = new ConcreteLocation(); locationSub.setParent(location); assertTrue(location.containsLocation(location)); assertTrue(location.containsLocation(locationSub)); assertFalse(locationSub.containsLocation(location)); }
protected void setParent(RebindContext rebindContext, LocationMemento memento) { Location parent = (memento.getParent() != null) ? rebindContext.lookup().lookupLocation(memento.getParent()) : null; if (parent != null) { location.setParent(parent); } else if (memento.getParent() != null) { LOG.warn("Ignoring parent {} of location {}({}), as cannot be found", new Object[] {memento.getParent(), memento.getType(), memento.getId()}); } } }
@Test public void setParentLocationReturnsExpectedLocation() { AbstractLocation parent = new ConcreteLocation(MutableMap.of("name", "Middle Earth")); AbstractLocation child = new ConcreteLocation(MutableMap.of("name", "The Shire")); child.setParent(parent); assertEquals(child.getParent(), parent); assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child)); }
setParent(config().get(PARENT_LOCATION));