1 package com.atlassian.plugin.osgi.container;
2
3 import com.atlassian.plugin.ReferenceMode;
4 import com.atlassian.plugin.osgi.hostcomponents.HostComponentRegistration;
5 import org.osgi.framework.Bundle;
6 import org.osgi.framework.BundleListener;
7 import org.osgi.framework.ServiceReference;
8 import org.osgi.util.tracker.ServiceTracker;
9 import org.osgi.util.tracker.ServiceTrackerCustomizer;
10
11 import java.io.File;
12 import java.util.List;
13
14 /**
15 * Manages the OSGi container and handles any interactions with it
16 */
17 public interface OsgiContainerManager {
18 /**
19 * Starts the OSGi container
20 *
21 * @throws OsgiContainerException If the container cannot be started
22 */
23 void start() throws OsgiContainerException;
24
25 /**
26 * Stops the OSGi container
27 *
28 * @throws OsgiContainerException If the container cannot be stopped
29 */
30 void stop() throws OsgiContainerException;
31
32 /**
33 * Installs a bundle into a running OSGI container.
34 *
35 * @param file The bundle file to install.
36 * @param referenceMode specifies whether the container may install a reference to, rather than copy, the bundle file.
37 * @return The installed bundle.
38 * @throws OsgiContainerException If the bundle cannot be loaded
39 * @since 4.0.0
40 */
41 Bundle installBundle(File file, ReferenceMode referenceMode) throws OsgiContainerException;
42
43 /**
44 * @return If the container is running or not
45 */
46 boolean isRunning();
47
48 /**
49 * Gets a list of installed bundles
50 *
51 * @return An array of bundles
52 */
53 Bundle[] getBundles();
54
55 /**
56 * Gets a list of service references
57 *
58 * @return An array of service references
59 */
60 ServiceReference[] getRegisteredServices();
61
62 /**
63 * Gets a list of host component registrations
64 *
65 * @return A list of host component registrations
66 */
67 List<HostComponentRegistration> getHostComponentRegistrations();
68
69 /**
70 * Gets a service tracker to follow a service registered under a certain interface. Will return a new
71 * {@link ServiceTracker} instance for every call, so don't call more than necessary. Any provided
72 * {@link ServiceTracker} instances will be opened before returning and automatically closed on shutdown.
73 *
74 * @param interfaceClassName The interface class as a String
75 * @return A service tracker to follow all instances of that interface
76 * @throws IllegalStateException If the OSGi container is not running
77 * @since 2.1
78 */
79 ServiceTracker getServiceTracker(String interfaceClassName);
80
81 /**
82 * Gets a service tracker to follow a service registered under a certain interface with a
83 * {@link ServiceTrackerCustomizer} attached for customizing tracked service objects. Will return a new
84 * {@link ServiceTracker} instance for every call, so don't call more than necessary. Any provided
85 * {@link ServiceTracker} instances will be opened before returning and automatically closed on shutdown.
86 *
87 * @param interfaceClassName The interface class as a String
88 * @param serviceTrackerCustomizer service tracker customizer for the created service tracker
89 * @return A service tracker to follow all instances of that interface
90 * @throws IllegalStateException If the OSGi container is not running
91 * @since 2.13
92 */
93 ServiceTracker getServiceTracker(String interfaceClassName, ServiceTrackerCustomizer serviceTrackerCustomizer);
94
95 /**
96 * That is shortcut to access SystemBundle.
97 */
98 void addBundleListener(BundleListener listener);
99
100 /**
101 * That is shortcut to access SystemBundle.
102 */
103 void removeBundleListener(BundleListener listener);
104 }