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 EsperActivator 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 EsperActivator} for COPAL Esper
42       * services.
43       */
44      public EsperActivator() {
45          super();
46  
47          final Configuration config = new Configuration();
48          // turn off view sharing
49          config.getEngineDefaults().getViewResources().setShareViews(false);
50          // turn off delivery order guarantees
51          config.getEngineDefaults().getThreading().setListenerDispatchPreserveOrder(
52                  false);
53          config.getEngineDefaults().getThreading().setInsertIntoDispatchPreserveOrder(
54                  false);
55  
56          final EPServiceProvider serviceProvider = EPServiceProviderManager.getDefaultProvider(config);
57          serviceProvider.initialize();
58  
59          this.deadLetterListener = new DeadLetterListener(serviceProvider);
60          this.esperPublishing = new EsperPublishing(serviceProvider);
61          this.notifiersActivator = new NotifiersActivator(serviceProvider,
62                  this.esperPublishing);
63      }
64  
65      @Override
66      public void start(final BundleContext bundleContext) {
67          this.deadLetterListener.start(bundleContext);
68          this.esperPublishing.start(bundleContext);
69          this.notifiersActivator.start(bundleContext);
70      }
71  
72      @Override
73      public void stop(final BundleContext bundleContext) {
74          this.notifiersActivator.stop(bundleContext);
75          this.esperPublishing.stop(bundleContext);
76          this.deadLetterListener.stop(bundleContext);
77      }
78  }