]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server.ui/src/org/simantics/maps/server/ui/Activator.java
14d121013b48e0a725da838014263128da45990e
[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             if (LOGGER.isDebugEnabled())
35                 LOGGER.debug("Starting tileserver mapnik automatically");
36             new TileserverMapnikStartJob(status -> {}).schedule();
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         if (LOGGER.isDebugEnabled())
49             LOGGER.debug("Stopping tileserver mapnik");
50         TileserverMapnikInstance.get().stop();
51         Activator.context = null;
52     }
53
54 }