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;
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;
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();
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() {
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()) {
mapServer = null;
}
+ @Deactivate
+ @PreDestroy
@Override
public void close() throws Exception {
destroy();
clusterSingletonService.close();
+ rpcRegistration.close();
+ listenerRegistration.close();
}
@Override
return SERVICE_GROUP_IDENTIFIER;
}
}
+