Remove blueprint XML from mapping service implementation
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / LispMappingService.java
index b8ba330f03af125418d422d9f341dc328b5db271..bec9825fe8cb02d4be545f640b6a75bf2d0b3802 100644 (file)
@@ -11,6 +11,9 @@ package org.opendaylight.lispflowmapping.implementation;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.List;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.apache.commons.lang3.tuple.MutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.opendaylight.lispflowmapping.config.ConfigIni;
@@ -27,6 +30,7 @@ import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServic
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
 import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
@@ -57,18 +61,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.OdlLi
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapReplyInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestInputBuilder;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
+@Component(service = {IFlowMapping.class, IMapRequestResultHandler.class, IMapNotifyHandler.class},
+        immediate = true, property = "type=default")
 public class LispMappingService implements IFlowMapping, IMapRequestResultHandler,
         IMapNotifyHandler, OdlLispProtoListener, AutoCloseable, ClusterSingletonService {
     private static final String LISPFLOWMAPPING_ENTITY_NAME = "lispflowmapping";
     private static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER = ServiceGroupIdentifier.create(
             LISPFLOWMAPPING_ENTITY_NAME);
 
-
     private static final Logger LOG = LoggerFactory.getLogger(LispMappingService.class);
-    private final ClusterSingletonServiceProvider clusterSingletonService;
 
     private volatile boolean smr = ConfigIni.getInstance().smrIsSet();
     private volatile String elpPolicy = ConfigIni.getInstance().getElpPolicy();
@@ -77,22 +87,39 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
     private ThreadLocal<Pair<MapNotify, List<TransportAddress>>> tlsMapNotify = new ThreadLocal<>();
     private ThreadLocal<Pair<MapRequest, TransportAddress>> tlsMapRequest = new ThreadLocal<>();
 
-    private final OdlLispSbService lispSB;
     private IMapResolverAsync mapResolver;
     private IMapServerAsync mapServer;
 
     private final IMappingService mapService;
+    private final OdlLispSbService lispSB;
+    private final ClusterSingletonServiceProvider clusterSingletonService;
+    private final RpcProviderService rpcProviderService;
     private final NotificationService notificationService;
-
-    public LispMappingService(final NotificationService notificationService,
-            final IMappingService mappingService,
-            final OdlLispSbService odlLispService, final ClusterSingletonServiceProvider clusterSingletonService) {
-
-        this.notificationService = notificationService;
+    private final Registration rpcRegistration;
+    private final Registration listenerRegistration;
+
+    @Inject
+    @Activate
+    public LispMappingService(@Reference final IMappingService mappingService,
+            @Reference final OdlLispSbService odlLispService,
+            @Reference final ClusterSingletonServiceProvider clusterSingletonService,
+            @Reference final RpcProviderService rpcProviderService,
+            @Reference final NotificationService notificationService) {
         this.mapService = mappingService;
         this.lispSB = odlLispService;
         this.clusterSingletonService = clusterSingletonService;
-        LOG.debug("LispMappingService Module constructed!");
+        this.rpcProviderService = rpcProviderService;
+        this.notificationService = notificationService;
+
+        // initialize
+        listenerRegistration = notificationService.registerNotificationListener(this);
+        rpcRegistration = rpcProviderService.registerRpcImplementation(OdlLispSbService.class, lispSB);
+
+        mapResolver = new MapResolver(mapService, smr, elpPolicy, this);
+        mapServer = new MapServer(mapService, smr, this, notificationService);
+        clusterSingletonService.registerClusterSingletonService(this);
+        mapResolver.setSmrNotificationListener((ISmrNotificationListener) mapServer);
+        LOG.info("LISP (RFC6830) Mapping Service initialized");
     }
 
     public boolean shouldUseSmr() {
@@ -115,20 +142,6 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         return this.notificationService;
     }
 
-    public void initialize() {
-        mapResolver = new MapResolver(mapService, smr, elpPolicy, this);
-        mapServer = new MapServer(mapService, smr, this, notificationService);
-        this.clusterSingletonService.registerClusterSingletonService(this);
-        mapResolver.setSmrNotificationListener((ISmrNotificationListener) mapServer);
-        LOG.info("LISP (RFC6830) Mapping Service init finished");
-    }
-
-    public void basicInit() {
-        mapResolver = new MapResolver(mapService, smr, elpPolicy, this);
-        mapServer = new MapServer(mapService, smr, this, notificationService);
-        mapResolver.setSmrNotificationListener((ISmrNotificationListener) mapServer);
-    }
-
     @Override
     public MapReply handleMapRequest(MapRequest request) {
         if (LOG.isDebugEnabled()) {
@@ -283,10 +296,14 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         mapServer = null;
     }
 
+    @Deactivate
+    @PreDestroy
     @Override
     public void close() throws Exception {
         destroy();
         clusterSingletonService.close();
+        rpcRegistration.close();
+        listenerRegistration.close();
     }
 
     @Override
@@ -307,3 +324,4 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         return SERVICE_GROUP_IDENTIFIER;
     }
 }
+