1   package com.atlassian.plugin.osgi.container;
2   
3   import org.osgi.framework.Bundle;
4   import org.osgi.framework.ServiceReference;
5   import org.osgi.util.tracker.ServiceTracker;
6   
7   import java.io.File;
8   import java.util.List;
9   
10  import com.atlassian.plugin.osgi.hostcomponents.HostComponentRegistration;
11  
12  /**
13   * Manages the OSGi container and handles any interactions with it
14   */
15  public interface OsgiContainerManager
16  {
17      /**
18       * Starts the OSGi container
19       *
20       * @throws OsgiContainerException If the container cannot be started
21       */
22      void start() throws OsgiContainerException;
23  
24      /**
25       * Stops the OSGi container
26       *
27       * @throws OsgiContainerException If the container cannot be stopped
28       */
29      void stop() throws OsgiContainerException;
30  
31      /**
32       * Installs a bundle into a running OSGI container
33       * @param file The bundle file to install
34       * @return The created bundle
35       * @throws OsgiContainerException If the bundle cannot be loaded
36       */
37      Bundle installBundle(File file) throws OsgiContainerException;
38  
39      /**
40       * @return If the container is running or not
41       */
42      boolean isRunning();
43  
44      /**
45       * Gets a list of installed bundles
46       *
47       * @return An array of bundles
48       */
49      Bundle[] getBundles();
50  
51      /**
52       * Gets a list of service references
53       * @return An array of service references
54       */
55      ServiceReference[] getRegisteredServices();
56  
57      /**
58       * Gets a list of host component registrations
59       *
60       * @return A list of host component registrations
61       */
62      List<HostComponentRegistration> getHostComponentRegistrations();
63  
64      /**
65       * Gets a service tracker to follow a service registered under a certain interface
66       *
67       * @param interfaceClassName The interface class as a String
68       * @return A service tracker to follow all instances of that interface
69       * @throws IllegalStateException If the OSGi container is not running
70       * @since 2.1
71       */
72      ServiceTracker getServiceTracker(String interfaceClassName);
73  }