View Javadoc

1   /* This file is part of COPAL (COntext Provisioning for All).
2    *
3    * COPAL is a part of SM4All (Smart hoMes for All) project.
4    *
5    * COPAL is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * COPAL is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with COPAL. If not, see <http://www.gnu.org/licenses/>.
17   */
18  package at.ac.tuwien.infosys.sm4all.copal.esper.internal;
19  
20  import org.osgi.framework.BundleActivator;
21  import org.osgi.framework.BundleContext;
22  import at.ac.tuwien.infosys.sm4all.copal.api.service.PublishingService;
23  import com.espertech.esper.client.Configuration;
24  import com.espertech.esper.client.EPServiceProvider;
25  import com.espertech.esper.client.EPServiceProviderManager;
26  
27  /**
28   * The OSGi {@link BundleActivator} for COPAL Esper services. This class
29   * registers implementation of {@link PublishingService} interfaces.
30   * 
31   * @author fei
32   * @author sanjin
33   */
34  public class Activator implements BundleActivator {
35  
36      private final DeadLetterListener deadLetterListener;
37      private final EsperPublishing esperPublishing;
38      private final NotifiersActivator notifiersActivator;
39  
40      /**
41       * Creates an instance of the {@link Activator} for COPAL Esper services.
42       */
43      public Activator() {
44          super();
45  
46          final Configuration config = new Configuration();
47          // turn off view sharing
48          config.getEngineDefaults().getViewResources().setShareViews(false);
49          // turn off delivery order guarantees
50          config.getEngineDefaults().getThreading().setListenerDispatchPreserveOrder(
51                  false);
52          config.getEngineDefaults().getThreading().setInsertIntoDispatchPreserveOrder(
53                  false);
54  
55          final EPServiceProvider serviceProvider = EPServiceProviderManager.getDefaultProvider(config);
56          serviceProvider.initialize();
57  
58          this.deadLetterListener = new DeadLetterListener(serviceProvider);
59          this.esperPublishing = new EsperPublishing(serviceProvider);
60          this.notifiersActivator = new NotifiersActivator(serviceProvider,
61                  this.esperPublishing);
62      }
63  
64      @Override
65      public void start(final BundleContext bundleContext) throws Exception {
66          this.deadLetterListener.start(bundleContext);
67          this.esperPublishing.start(bundleContext);
68          this.notifiersActivator.start(bundleContext);
69      }
70  
71      @Override
72      public void stop(final BundleContext bundleContext) throws Exception {
73          this.notifiersActivator.stop(bundleContext);
74          this.esperPublishing.stop(bundleContext);
75          this.deadLetterListener.stop(bundleContext);
76      }
77  }