/** * 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); } }