2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.config.yang.config.neutron_vpp_mapper.impl;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.opendaylight.controller.config.yang.config.groupbasedpolicy.GroupbasedpolicyInstance;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.NeutronVppMapper;
17 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
18 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
20 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class NeutronVppMapperInstance implements ClusterSingletonService, AutoCloseable {
26 private static final Logger LOG = LoggerFactory.getLogger(NeutronVppMapperInstance.class);
28 private static final ServiceGroupIdentifier IDENTIFIER =
29 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
30 private final DataBroker dataBroker;
31 private final String socketPath;
32 private final String socketPrefix;
33 private final String routingNode;
34 private final ClusterSingletonServiceProvider clusterSingletonService;
35 private ClusterSingletonServiceRegistration singletonServiceRegistration;
36 private NeutronVppMapper mapper;
38 public NeutronVppMapperInstance(final DataBroker dataBroker,
39 final String socketPath,
40 final String socketPrefix,
41 final String routingNode,
42 final ClusterSingletonServiceProvider clusterSingletonService) {
43 this.dataBroker = Preconditions.checkNotNull(dataBroker);
44 this.socketPath = Preconditions.checkNotNull(socketPath);
45 this.socketPrefix = Preconditions.checkNotNull(socketPrefix);
46 this.routingNode = Preconditions.checkNotNull(routingNode);
47 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
50 public void initialize() {
51 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
52 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
56 public void instantiateServiceInstance() {
57 LOG.info("Instantiating {}", this.getClass().getSimpleName());
58 mapper = new NeutronVppMapper(socketPath, socketPrefix, routingNode, dataBroker);
62 public ListenableFuture<Void> closeServiceInstance() {
63 LOG.info("Instance {} closed", this.getClass().getSimpleName());
65 return Futures.immediateFuture(null);
69 public void close() throws Exception {
70 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
71 if (singletonServiceRegistration != null) {
73 singletonServiceRegistration.close();
74 } catch (Exception e) {
75 LOG.warn("{} closed unexpectedly.", this.getClass().getSimpleName(), e.getMessage());
77 singletonServiceRegistration = null;
82 public ServiceGroupIdentifier getIdentifier() {