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.core.internal;
19  
20  import org.apache.log4j.Logger;
21  import at.ac.tuwien.infosys.sm4all.copal.api.helpers.AbstractGenericActivator;
22  import at.ac.tuwien.infosys.sm4all.copal.service.copal.ContextEventTypeRegistry;
23  import at.ac.tuwien.infosys.sm4all.copal.service.event.EventTypeRegistry;
24  
25  /**
26   * Automatic activator of {@link ContextEventTypeRegistry} service. This service
27   * tracker registers and unregisters {@link ContextEventTypeRegistry} service as
28   * {@link EventTypeRegistry} service, on which it depends, changes its
29   * availability.
30   * 
31   * @author sanjin
32   */
33  public class ContextEventTypeActivator extends AbstractGenericActivator {
34  
35      private static final Logger LOGGER = Logger.getLogger(ContextEventTypeActivator.class);
36  
37      private ContextEventTypeRegistryImpl contextEventTypeRegistry;
38  
39      /**
40       * Creates instance of OSGi Activator for {@link ContextEventTypeRegistry}
41       * service.
42       */
43      public ContextEventTypeActivator() {
44          super(EventTypeRegistry.class.getName());
45      }
46  
47      @Override
48      protected void start() {
49          final EventTypeRegistry eventTypeRegistry = getDependency(EventTypeRegistry.class.getName());
50  
51          this.contextEventTypeRegistry = new ContextEventTypeRegistryImpl(
52                  eventTypeRegistry);
53          if (register(ContextEventTypeRegistry.class,
54                  this.contextEventTypeRegistry))
55              LOGGER.info("Successfully registered ContextEventTypeRegistry service!");
56          else {
57              LOGGER.error("Failed to register ContextEventTypeRegistry service!");
58              this.contextEventTypeRegistry.shutdown();
59              this.contextEventTypeRegistry = null;
60          }
61      }
62  
63      @Override
64      protected void stop() {
65          if (this.contextEventTypeRegistry != null) {
66              unregister(ContextEventTypeRegistry.class);
67              LOGGER.info("Successfully unregistered ContextEventTypeRegistry service!");
68  
69              this.contextEventTypeRegistry.shutdown();
70              this.contextEventTypeRegistry = null;
71          }
72      }
73  }