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.vpp_provider.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.controller.sal.binding.api.BindingAwareBroker;
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 GbpVppProviderInstance implements ClusterSingletonService, AutoCloseable {
26 private static final Logger LOG = LoggerFactory.getLogger(GbpVppProviderInstance.class);
28 private static final ServiceGroupIdentifier IDENTIFIER =
29 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
30 private final DataBroker dataBroker;
31 private final BindingAwareBroker bindingAwareBroker;
32 private final ClusterSingletonServiceProvider clusterSingletonService;
33 private ClusterSingletonServiceRegistration singletonServiceRegistration;
34 private VppRenderer renderer;
36 public GbpVppProviderInstance(final DataBroker dataBroker,
37 final BindingAwareBroker bindingAwareBroker,
38 final ClusterSingletonServiceProvider clusterSingletonService) {
39 this.dataBroker = Preconditions.checkNotNull(dataBroker);
40 this.bindingAwareBroker = Preconditions.checkNotNull(bindingAwareBroker);
41 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
44 public void initialize() {
45 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
46 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
50 public void instantiateServiceInstance() {
51 LOG.info("Instantiating {}", this.getClass().getSimpleName());
52 renderer = new VppRenderer(dataBroker, bindingAwareBroker);
56 public ListenableFuture<Void> closeServiceInstance() {
57 LOG.info("Instance {} closed", this.getClass().getSimpleName());
60 } catch (Exception e) {
61 LOG.warn("Exception while closing ... {}", e.getMessage());
63 return Futures.immediateFuture(null);
67 public void close() throws Exception {
69 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
70 if (singletonServiceRegistration != null) {
72 singletonServiceRegistration.close();
73 } catch (Exception e) {
74 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e.getMessage());
76 singletonServiceRegistration = null;
81 public ServiceGroupIdentifier getIdentifier() {