1 package com.atlassian.plugin.spring.scanner.dynamic.contexts;
2
3 import com.atlassian.event.api.EventPublisher;
4 import org.osgi.framework.BundleContext;
5 import org.springframework.context.ApplicationContext;
6 import org.springframework.context.ConfigurableApplicationContext;
7
8 /**
9 * This class can install new Spring application contexts into a running Atlassian plugin
10 */
11 public class DynamicContext {
12 public interface Installer {
13 /**
14 * This method will create and install a new child application context into the plugin.
15 * <p>
16 * As a side effect a {@link com.atlassian.plugin.event.events.PluginRefreshedEvent} will be generated for this new
17 * child context.
18 * <p>
19 * By calling this method you are able to have the plugin auto-wire components such as actions and web-items from
20 * the child context instead of the originating parent context. This will allow you to dynamically grow and shrink
21 * the components that your plugin gives off to the world based on external events such as licencing or memory
22 * passivisation.
23 *
24 * @param springConfigPaths the paths to find spring configuration files on the class path
25 * @param parentContext the parent context, typically the context that came with your plugin
26 * @return the newly created child context
27 */
28 ConfigurableApplicationContext useContext(String[] springConfigPaths, ApplicationContext parentContext);
29
30 /**
31 * This method can "close" a child application context (typically one created with {@link #useContext(String[],
32 * org.springframework.context.ApplicationContext)} and set in the replacement application context instead.
33 * Typically the replacement would be the parent of the child context to be closed but it doesnt always have to be.
34 *
35 * @param childContext the child context to close.
36 * @param replacementContext the context to replace the child context with. Typically this can be its parent
37 */
38 void closeAndUseContext(ConfigurableApplicationContext childContext, ApplicationContext replacementContext);
39 }
40
41 /**
42 * Creates a new installer that can create and install {@link ApplicationContext}s into a running plugin
43 *
44 * @param eventPublisher the event publisher
45 * @param bundleContext the current plugins bundle context
46 * @param pluginKey the key of the current plugin
47 * @return a new installer
48 */
49 public static Installer installer(final EventPublisher eventPublisher, final BundleContext bundleContext, final String pluginKey) {
50 return new ApplicationContextInstallerImpl(eventPublisher, bundleContext, pluginKey);
51 }
52 }