]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/Activator.java
Speeding up platform startup time
[simantics/platform.git] / bundles / org.simantics.scl.osgi / src / org / simantics / scl / osgi / internal / Activator.java
1 package org.simantics.scl.osgi.internal;
2
3 import java.util.Hashtable;
4 import java.util.concurrent.ForkJoinPool;
5
6 import org.osgi.framework.BundleActivator;
7 import org.osgi.framework.BundleContext;
8 import org.simantics.scl.compiler.errors.Failable;
9 import org.simantics.scl.compiler.module.Module;
10 import org.simantics.scl.compiler.module.repository.ModuleRepository;
11 import org.simantics.scl.compiler.module.repository.UpdateListener;
12 import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;
13 import org.simantics.scl.compiler.source.repository.ProceduralModuleSourceRepository;
14 import org.simantics.scl.compiler.source.repository.SourceRepositories;
15 import org.simantics.scl.osgi.SCLOsgi;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class Activator implements BundleActivator {
20
21     private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
22
23     public static final String PLUGIN_ID = "org.simantics.scl.osgi";
24
25     private static BundleContext context;
26
27     public static BundleContext getContext() {
28         return context;
29     }
30
31     @SuppressWarnings({ "rawtypes", "unchecked" })
32     public void start(BundleContext bundleContext) throws Exception {
33         Activator.context = bundleContext;
34
35         Hashtable properties = new Hashtable();
36         bundleContext.registerService(ModuleSourceRepository.class,
37                 SourceRepositories.BUILTIN_SOURCE_REPOSITORY,
38                 properties);
39         bundleContext.registerService(ModuleSourceRepository.class,
40                 new ProceduralModuleSourceRepository() {
41                     @Override
42                     protected ModuleRepository getModuleRepository(UpdateListener listener) {
43                         return SCLOsgi.MODULE_REPOSITORY;
44                     }
45                 },
46                 properties);
47         // Let's try to compile StandardLibrary asynchronously to speed up
48         // the compilation when we actually need it the first time
49         LOGGER.info("Warming up SCL-compiler with StandardLibrary");
50         ForkJoinPool.commonPool().submit(() -> {
51             Failable<Module> module = SCLOsgi.MODULE_REPOSITORY.getModule("StandardLibrary");
52             LOGGER.info("StandardLibrary compiled {}", module);
53         });
54     }
55
56     public void stop(BundleContext bundleContext) throws Exception {
57         Activator.context = null;
58     }
59
60 }