/** * Unmaps a mount path from the application. Throws an exception if the mount path doesn't exist * * @param mountPath * @return the application that's unmapped from the mount path */ public Application<ApplicationConfiguration> removeApplication(String mountPath) { mountPath = structureUrl(mountPath); String path = getAbsolutePath(mountPath); if (! applications.containsKey(path)) { throw new IllegalArgumentException("Mount path - " + mountPath+ " doesn't exist"); } return applications.remove(path); }
public Collection<Application<ApplicationConfiguration>> getApplications() { return applicationMapping.getApplications(); }
/** * Resolves the request to an application by mapping the request url to the application path. * * @param request * @return the application that this request resolves to */ public Application<ApplicationConfiguration> resolve(HttpRequest request) { String path = request.getUri(); for (Entry<String, Application<ApplicationConfiguration>> entry : getSortedApplications().entrySet()) { if (path.startsWith(entry.getKey())) { return entry.getValue(); } } return null; }
/** * Unmounts an application from the given mount url * * @param mountUrl */ protected void unMount(String mountUrl) { logger.info("Unmounting the mount path {}", mountUrl); Application<ApplicationConfiguration> application = applicationMapping.removeApplication(mountUrl); for (ContainerLifecycleListener listener : listeners) { listener.preUnMount(application); } application.stop(); for (ContainerLifecycleListener listener : listeners) { listener.postUnMount(application); } }
public Container(ContainerConfiguration configuration) { this.configuration = configuration; this.applicationMapping = new ApplicationMapping(configuration.getBasePath()); router = new Router(applicationMapping); router.registerListener(messageObserver); }
/** * Mounts the application on the container * * @param application */ protected void mount(Application<ApplicationConfiguration> application) { logger.info("Mounting the application {} on the mount path {}", application, application.getConfiguration().getBasePath()); application.getConfiguration().setParent(configuration); for (ContainerLifecycleListener listener : listeners) { listener.preMount(application); } application.init(); applicationMapping.addApplication(application); for (ContainerLifecycleListener listener : listeners) { listener.postMount(application); } }
logger.trace("Routing the context {}", context); Application<ApplicationConfiguration> application = applicationMapping.resolve(context.getRequest()); if (application == null) { throw new NotFoundException("Request path not found");
public void stop() { logger.info("Stopping the container"); for (ContainerLifecycleListener listener : listeners) { listener.beforeStop(this); } for (Bundle<BundleConfiguration> bundle : bundles) { bundle.stop(); } // FIXME What will application do on stop? for (Application<ApplicationConfiguration> application : applicationMapping.getApplications()) { application.stop(); } for (ContainerLifecycleListener listener : listeners) { listener.afterStop(this); } }
/** * Maps application to its mount path. If the mount path already exists or if the application is already mapped to another mount path, * throws an exception * * @param application * @param mountPath */ public void addApplication(Application<ApplicationConfiguration> application) { String mountPath = structureUrl(application.getConfiguration().getBasePath()); String path = getAbsolutePath(mountPath); if (applications.containsKey(path)) { throw new IllegalArgumentException("Mount path - " + mountPath + " already exists. Either change the application base path or override it in container"); } if (applications.containsValue(application)) { throw new IllegalArgumentException("Application - " + application + " is already mounted on a different mount path"); } application.setPath(HttpUtil.createURI(path)); applications.put(path, application); }
public void start() { logger.info("Starting the container"); for (ContainerLifecycleListener listener : listeners) { listener.beforeStart(this); } for (Bundle<BundleConfiguration> bundle : bundles) { bundle.start(); } for (Application<ApplicationConfiguration> application : applicationMapping.getApplications()) { application.start(); } for (ContainerLifecycleListener listener : listeners) { listener.afterStart(this); } }