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.groupbasedpolicy.renderer.ios_xe_provider.impl.config;
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.groupbasedpolicy.renderer.ios_xe_provider.impl.IosXeRendererProviderImpl;
18 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.spi.SxpEpProviderProvider;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
20 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
22 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class IosXeProviderInstance implements ClusterSingletonService, AutoCloseable {
28 private static final Logger LOG = LoggerFactory.getLogger(IosXeProviderInstance.class);
30 private static final ServiceGroupIdentifier IDENTIFIER =
31 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
32 private final DataBroker dataBroker;
33 private final BindingAwareBroker bindingAwareBroker;
34 private final ClusterSingletonServiceProvider clusterSingletonService;
35 private final SxpEpProviderProvider sxpEpProvider;
36 private ClusterSingletonServiceRegistration singletonServiceRegistration;
37 private IosXeRendererProviderImpl renderer;
39 public IosXeProviderInstance(final DataBroker dataBroker,
40 final BindingAwareBroker broker,
41 final ClusterSingletonServiceProvider clusterSingletonService,
42 final SxpEpProviderProvider sxpEpProvider) {
43 this.dataBroker = Preconditions.checkNotNull(dataBroker);
44 this.bindingAwareBroker = Preconditions.checkNotNull(broker);
45 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
46 this.sxpEpProvider = Preconditions.checkNotNull(sxpEpProvider);
49 public void initialize() {
50 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
51 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
55 public void instantiateServiceInstance() {
56 LOG.info("Instantiating {}", this.getClass().getSimpleName());
57 renderer = new IosXeRendererProviderImpl(dataBroker, bindingAwareBroker, sxpEpProvider);
61 public ListenableFuture<Void> closeServiceInstance() {
62 LOG.info("Instance {} closed", this.getClass().getSimpleName());
64 return Futures.immediateFuture(null);
68 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. Cause: {}", e.getMessage());
76 singletonServiceRegistration = null;
81 public ServiceGroupIdentifier getIdentifier() {