]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server.ui/src/org/simantics/maps/server/ui/Activator.java
Enhancements to district functionalities and code
[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 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 public class Activator implements BundleActivator {
11
12     private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
13     
14     public static final String PLUGIN_ID = "org.simantics.maps.server.ui";
15     
16     private static BundleContext context;
17
18     static BundleContext getContext() {
19         return context;
20     }
21
22     /*
23      * (non-Javadoc)
24      * 
25      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
26      * BundleContext)
27      */
28     public void start(BundleContext bundleContext) throws Exception {
29         Activator.context = bundleContext;
30         
31         // Let's see if server should be automatically started
32         if (MapsServerPreferences.startAutomatically()) {
33             // execute in a separate thread to not slow down the startup process
34             new Thread(() -> {
35                 try {
36                     TileserverMapnikInstance.get().start();
37                 } catch (Throwable t) {
38                     LOGGER.error("Could not start integrated tile server", t);
39                 }
40             }).start();
41         }
42     }
43
44     /*
45      * (non-Javadoc)
46      * 
47      * @see
48      * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
49      */
50     public void stop(BundleContext bundleContext) throws Exception {
51         // Stop the server
52         TileserverMapnikInstance.get().stop();
53         Activator.context = null;
54     }
55
56 }