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.md.sal.binding.api.DataBroker;
15 import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.NeutronVppMapper;
16 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
17 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
18 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
19 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class NeutronVppMapperInstance implements ClusterSingletonService, AutoCloseable {
25 private static final Logger LOG = LoggerFactory.getLogger(NeutronVppMapperInstance.class);
27 private static final ServiceGroupIdentifier IDENTIFIER =
28 ServiceGroupIdentifier.create(NeutronVppMapperInstance.class.getName());
29 private final DataBroker dataBroker;
30 private final String socketPath;
31 private final String socketPrefix;
32 private final ClusterSingletonServiceProvider clusterSingletonService;
33 private ClusterSingletonServiceRegistration singletonServiceRegistration;
34 private NeutronVppMapper mapper;
36 public NeutronVppMapperInstance(final DataBroker dataBroker,
37 final String socketPath,
38 final String socketPrefix,
39 final ClusterSingletonServiceProvider clusterSingletonService) {
40 this.dataBroker = Preconditions.checkNotNull(dataBroker);
41 this.socketPath = Preconditions.checkNotNull(socketPath);
42 this.socketPrefix = Preconditions.checkNotNull(socketPrefix);
43 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
46 public void initialize() {
47 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
48 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
52 public void instantiateServiceInstance() {
53 LOG.info("Instantiating {}", this.getClass().getSimpleName());
54 mapper = new NeutronVppMapper(socketPath, socketPrefix, dataBroker);
58 public ListenableFuture<Void> closeServiceInstance() {
59 LOG.info("Instance {} closed", this.getClass().getSimpleName());
61 return Futures.immediateFuture(null);
65 public void close() throws Exception {
66 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
67 if (singletonServiceRegistration != null) {
69 singletonServiceRegistration.close();
70 } catch (Exception e) {
71 LOG.warn("{} closed unexpectedly.", this.getClass().getSimpleName(), e.getMessage());
73 singletonServiceRegistration = null;
78 public ServiceGroupIdentifier getIdentifier() {