@Override public <T extends Entity> T createEntity(EntitySpec<T> spec) { if (isInitialManagementContextReal()) { return initialManagementContext.getEntityManager().createEntity(spec); } else { throw new IllegalStateException("Non-deployment context "+this+" (with no initial management context supplied) is not valid for this operation."); } }
protected final <T extends Entity> T createEntity(EntitySpec<T> spec) { checkDuringManage(); EntityManager entityManager = managementContext.getEntityManager(); return entityManager.createEntity(spec); }
/** * Builds and manages the application, calling the user's {@link #doBuild()} method. * * @throws IllegalStateException If already managed, or if called during {@link #doBuild()}, or if * multiple concurrent calls */ public final StartableApplication manage(ManagementContext managementContext) { if (!inManage.compareAndSet(false, true)) { throw new IllegalStateException("Concurrent and re-entrant calls to manage() forbidden on "+this); } try { checkNotManaged(); this.app = managementContext.getEntityManager().createEntity(appSpec); this.managementContext = managementContext; doBuild(); Entities.startManagement(app, managementContext); managed = true; return app; } finally { inManage.set(false); } }
/** * 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 && !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()); } return addChild(getEntityManager().createEntity(spec)); }
private Entity newEntity(EntityMemento memento, Reflections reflections) { String entityId = memento.getId(); String entityType = checkNotNull(memento.getType(), "entityType of "+entityId); Class<?> entityClazz = reflections.loadClass(entityType); Map<String,Object> flags = Maps.newLinkedHashMap(); flags.put("id", entityId); if (AbstractApplication.class.isAssignableFrom(entityClazz)) flags.put("mgmt", managementContext); if (InternalEntityFactory.isNewStyleEntity(managementContext, entityClazz)) { Class<?> entityInterface = managementContext.getEntityManager().getEntityTypeRegistry().getEntityTypeOf((Class)entityClazz); EntitySpec<?> entitySpec = EntitySpec.create((Class)entityInterface).impl((Class)entityClazz).configure("id", entityId); return managementContext.getEntityManager().createEntity(entitySpec); } else { // There are several possibilities for the constructor; find one that works. // Prefer passing in the flags because required for Application to set the management context // TODO Feels very hacky! return (Entity) invokeConstructor(reflections, entityClazz, new Object[] {flags}, new Object[] {flags, null}, new Object[] {null}, new Object[0]); } }
instance = (Application) mgmt.getEntityManager().createEntity(coreSpec); for (EntitySpec entitySpec : entities) { log.info("REST creating instance for entity {}", entitySpec.getType()); instance.addChild(mgmt.getEntityManager().createEntity(toCoreEntitySpec(entitySpec))); instance = (Application) mgmt.getEntityManager().createEntity(coreSpec); instance.addChild(mgmt.getEntityManager().createEntity(toCoreEntitySpec(eclazz, name, configO)));
brooklyn.entity.proxying.EntitySpec<?> coreSpec = toCoreEntitySpec(clazz, name, configO); configureRenderingMetadata(spec, coreSpec); instance = (Application) mgmt.getEntityManager().createEntity(coreSpec); for (EntitySpec entitySpec : entities) { log.info("REST creating instance for entity {}", entitySpec.getType()); instance.addChild(mgmt.getEntityManager().createEntity(toCoreEntitySpec(entitySpec))); configureRenderingMetadata(spec, coreSpec); instance = (Application) mgmt.getEntityManager().createEntity(coreSpec); Entity soleChild = mgmt.getEntityManager().createEntity(toCoreEntitySpec(eclazz, name, configO)); instance.addChild(soleChild); instance.addEnricher(SensorPropagatingEnricher.newInstanceListeningToAllSensors(soleChild));