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 ClusterSingletonServiceProvider clusterSingletonService;
34 private ClusterSingletonServiceRegistration singletonServiceRegistration;
35 private NeutronVppMapper mapper;
37 public NeutronVppMapperInstance(final DataBroker dataBroker,
38 final String socketPath,
39 final String socketPrefix,
40 final ClusterSingletonServiceProvider clusterSingletonService) {
41 this.dataBroker = Preconditions.checkNotNull(dataBroker);
42 this.socketPath = Preconditions.checkNotNull(socketPath);
43 this.socketPrefix = Preconditions.checkNotNull(socketPrefix);
44 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
47 public void initialize() {
48 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
49 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
53 public void instantiateServiceInstance() {
54 LOG.info("Instantiating {}", this.getClass().getSimpleName());
55 mapper = new NeutronVppMapper(socketPath, socketPrefix, dataBroker);
59 public ListenableFuture<Void> closeServiceInstance() {
60 LOG.info("Instance {} closed", this.getClass().getSimpleName());
62 return Futures.immediateFuture(null);
66 public void close() throws Exception {
67 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
68 if (singletonServiceRegistration != null) {
70 singletonServiceRegistration.close();
71 } catch (Exception e) {
72 LOG.warn("{} closed unexpectedly.", this.getClass().getSimpleName(), e.getMessage());
74 singletonServiceRegistration = null;
79 public ServiceGroupIdentifier getIdentifier() {