package org.opendaylight.controller.config.yang.config.neutron_mapper.impl;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.config.yang.config.groupbasedpolicy.GroupbasedpolicyInstance;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.groupbasedpolicy.neutron.mapper.NeutronMapper;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public class NeutronMapperInstance implements AutoCloseable{
+public class NeutronMapperInstance implements ClusterSingletonService, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(NeutronMapperInstance.class);
+
+ private static final ServiceGroupIdentifier IDENTIFIER =
+ ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
+ private final DataBroker dataBroker;
+ private final EndpointService epService;
+ private final BaseEndpointService baseEndpointService;
+ private final ClusterSingletonServiceProvider clusterSingletonService;
+ private ClusterSingletonServiceRegistration singletonServiceRegistration;
private NeutronMapper mapper;
- public NeutronMapperInstance (DataBroker dataBroker, EndpointService epService,
- BaseEndpointService baseEndpointService) {
+ public NeutronMapperInstance(final DataBroker dataBroker,
+ final EndpointService epService,
+ final BaseEndpointService baseEndpointService,
+ final ClusterSingletonServiceProvider clusterSingletonService) {
+ this.dataBroker = Preconditions.checkNotNull(dataBroker);
+ this.epService = Preconditions.checkNotNull(epService);
+ this.baseEndpointService = Preconditions.checkNotNull(baseEndpointService);
+ this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
+ }
+
+ public void instantiate() {
+ LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
+ singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ }
+
+ @Override
+ public void instantiateServiceInstance() {
+ LOG.info("Instantiating {}", this.getClass().getSimpleName());
mapper = new NeutronMapper(dataBroker, epService, baseEndpointService);
}
+
@Override
- public void close() throws Exception {
+ public ListenableFuture<Void> closeServiceInstance() {
+ LOG.info("Instance {} closed", this.getClass().getSimpleName());
mapper.close();
+ return Futures.immediateFuture(null);
}
+
+ @Override
+ public void close() throws Exception {
+ LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
+ if (singletonServiceRegistration != null) {
+ try {
+ singletonServiceRegistration.close();
+ } catch (Exception e) {
+ LOG.warn("{} closed unexpectedly", e.getMessage());
+ }
+ singletonServiceRegistration = null;
+ }
+ }
+
+ @Override
+ public ServiceGroupIdentifier getIdentifier() {
+ return IDENTIFIER;
+ }
+
}
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
<odl:rpc-service id="epService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService"/>
<odl:rpc-service id="baseEpService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService"/>
+ <reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
<bean id="neutronMapper" class="org.opendaylight.controller.config.yang.config.neutron_mapper.impl.NeutronMapperInstance"
- destroy-method="close">
+ init-method="instantiate" destroy-method="close">
<argument ref="dataBroker"/>
<argument ref="epService"/>
<argument ref="baseEpService"/>
+ <argument ref="clusterSingletonService" />
</bean>
</blueprint>
\ No newline at end of file