]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server.ui/src/org/simantics/maps/server/ui/Activator.java
cd46e1a517f5c57dcaf64acef5cfe6d8a5570740
[simantics/district.git] / org.simantics.maps.server.ui / src / org / simantics / maps / server / ui / Activator.java
1 package org.simantics.maps.server.ui;
2
3 import org.osgi.framework.BundleActivator;
4 import org.osgi.framework.BundleContext;
5 import org.simantics.district.maps.server.TileserverMapnikInstance;
6 import org.simantics.district.maps.server.prefs.MapsServerPreferences;
7
8 public class Activator implements BundleActivator {
9
10     public static final String PLUGIN_ID = "org.simantics.maps.server.ui";
11     
12     private static BundleContext context;
13
14     static BundleContext getContext() {
15         return context;
16     }
17
18     /*
19      * (non-Javadoc)
20      * 
21      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
22      * BundleContext)
23      */
24     public void start(BundleContext bundleContext) throws Exception {
25         Activator.context = bundleContext;
26         
27         // Let's see if server should be automatically started
28         if (MapsServerPreferences.startAutomatically()) {
29             // execute in a separate thread to not slow down the startup process
30             new Thread(() -> {
31                 try {
32                     TileserverMapnikInstance.get().start();
33                 } catch (Exception e) {
34                     e.printStackTrace();
35                 }
36             }).start();
37         }
38     }
39
40     /*
41      * (non-Javadoc)
42      * 
43      * @see
44      * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
45      */
46     public void stop(BundleContext bundleContext) throws Exception {
47         // Stop the server
48         TileserverMapnikInstance.get().stop();
49         Activator.context = null;
50     }
51
52 }