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.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
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 GbpVppProviderInstance implements ClusterSingletonService, AutoCloseable {
25 private static final Logger LOG = LoggerFactory.getLogger(GbpVppProviderInstance.class);
27 private static final ServiceGroupIdentifier IDENTIFIER =
28 ServiceGroupIdentifier.create(GbpVppProviderInstance.class.getName());
29 private final DataBroker dataBroker;
30 private final BindingAwareBroker bindingAwareBroker;
31 private final ClusterSingletonServiceProvider clusterSingletonService;
32 private ClusterSingletonServiceRegistration singletonServiceRegistration;
33 private VppRenderer renderer;
35 public GbpVppProviderInstance(final DataBroker dataBroker,
36 final BindingAwareBroker bindingAwareBroker,
37 final ClusterSingletonServiceProvider clusterSingletonService) {
38 this.dataBroker = Preconditions.checkNotNull(dataBroker);
39 this.bindingAwareBroker = Preconditions.checkNotNull(bindingAwareBroker);
40 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
43 public void initialize() {
44 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
45 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
49 public void instantiateServiceInstance() {
50 LOG.info("Instantiating {}", this.getClass().getSimpleName());
51 renderer = new VppRenderer(dataBroker, bindingAwareBroker);
55 public ListenableFuture<Void> closeServiceInstance() {
56 LOG.info("Instance {} closed", this.getClass().getSimpleName());
59 } catch (Exception e) {
60 LOG.warn("Exception while closing ... {}", e.getMessage());
62 return Futures.immediateFuture(null);
66 public void close() throws Exception {
68 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
69 if (singletonServiceRegistration != null) {
71 singletonServiceRegistration.close();
72 } catch (Exception e) {
73 LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e.getMessage());
75 singletonServiceRegistration = null;
80 public ServiceGroupIdentifier getIdentifier() {