@Override public synchronized SubscriptionContext getSubscriptionContext(Entity entity) { if (!this.entity.equals(entity)) throw new IllegalStateException("Non-deployment context "+this+" can only use a single Entity: has "+this.entity+", but passed "+entity); if (mode==NonDeploymentManagementContextMode.MANAGEMENT_STOPPED) throw new IllegalStateException("Entity "+entity+" is no longer managed; subscription context not available"); return subscriptionContext; }
@Override public ExecutionContext getExecutionContext(Entity entity) { if (!this.entity.equals(entity)) throw new IllegalStateException("Non-deployment context "+this+" can only use a single Entity: has "+this.entity+", but passed "+entity); if (mode==NonDeploymentManagementContextMode.MANAGEMENT_STOPPED) throw new IllegalStateException("Entity "+entity+" is no longer managed; execution context not available"); checkInitialManagementContextReal(); return initialManagementContext.getExecutionContext(entity); }
/** * @deprecated since 0.5; instead use no-arg constructor with EntityManager().createEntity(spec) */ @Deprecated public AbstractEntity(@SuppressWarnings("rawtypes") Map flags, Entity parent) { super(checkConstructorFlags(flags, parent)); // TODO Don't let `this` reference escape during construction entityType = new EntityDynamicType(this); if (isLegacyConstruction()) { AbstractEntity checkWeGetThis = configure(flags); assert this.equals(checkWeGetThis) : this+" configure method does not return itself; returns "+checkWeGetThis+" instead of "+this; boolean deferConstructionChecks = (flags.containsKey("deferConstructionChecks") && TypeCoercions.coerce(flags.get("deferConstructionChecks"), Boolean.class)); if (!deferConstructionChecks) { FlagUtils.checkRequiredFields(this); } } }
if (this.equals(entity)) throw new IllegalStateException("entity "+this+" cannot own itself");
/** * Creates an entity using the given spec, and adds it as a child of this entity. * * @see #addChild(Entity) * @see EntityManager#createEntity(EntitySpec) * * @throws IllegalArgumentException If {@code spec.getParent()} is set and is different from this entity */ @Override public <T extends Entity> T addChild(EntitySpec<T> spec) { if (spec.getParent()==null) { spec = EntitySpec.create(spec).parent(getProxyIfAvailable()); } if (!this.equals(spec.getParent())) { throw new IllegalArgumentException("Attempt to create child of "+this+" with entity spec "+spec+ " failed because spec has different parent: "+spec.getParent()); } // The spec now includes this as the parent, so no need to call addChild; // that is done by InternalEntityFactory. return getEntityManager().createEntity(spec); }
@Override public <T extends Feed> T addFeed(T feed) { Feed old = findApparentlyEqualAndWarnIfNotSameUniqueTag(feedsInternal, feed); if (old != null) { if (old == feed) { if (!BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_FEED_REGISTRATION_PROPERTY)) { LOG.debug("Feed " + feed + " already added, not adding a second time."); } // else expected to be added a second time through addFeed, ignore return feed; } else { // Different feed object with (seemingly) same functionality, remove previous one, will stop it. LOG.debug("Removing "+old+" when adding "+feed+" to "+this); removeFeed(old); } } CatalogUtils.setCatalogItemIdOnAddition(AbstractEntity.this, feed); feedsInternal.add(feed); if (!AbstractEntity.this.equals(((AbstractFeed)feed).getEntity())) ((AbstractFeed)feed).setEntity(AbstractEntity.this); getManagementContext().getRebindManager().getChangeListener().onManaged(feed); getManagementSupport().getEntityChangeListener().onFeedAdded(feed); // TODO Could add equivalent of AbstractEntity.POLICY_ADDED for feeds; no use-case for that yet return feed; }