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.groupbasedpolicy.gbp_ise_adapter;
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.gbp_ise_adapter.impl.GbpIseAdapterProvider;
18 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
20 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
21 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class GbpIseAdapterProviderInstance implements ClusterSingletonService, AutoCloseable {
27 private static final Logger LOG = LoggerFactory.getLogger(GbpIseAdapterProviderInstance.class);
29 private static final ServiceGroupIdentifier IDENTIFIER =
30 ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
31 private final DataBroker dataBroker;
32 private final BindingAwareBroker bindingAwareBroker;
33 private final ClusterSingletonServiceProvider clusterSingletonService;
34 private ClusterSingletonServiceRegistration singletonServiceRegistration;
35 private GbpIseAdapterProvider iseAdapterProvider;
37 public GbpIseAdapterProviderInstance(final DataBroker dataBroker,
38 final BindingAwareBroker bindingAwareBroker,
39 final ClusterSingletonServiceProvider clusterSingletonService) {
40 this.dataBroker = Preconditions.checkNotNull(dataBroker);
41 this.bindingAwareBroker = Preconditions.checkNotNull(bindingAwareBroker);
42 this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
45 public void initialize() {
46 LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
47 singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
51 public void instantiateServiceInstance() {
52 LOG.info("Instantiating {}", this.getClass().getSimpleName());
53 iseAdapterProvider = new GbpIseAdapterProvider(dataBroker, bindingAwareBroker);
57 public ListenableFuture<Void> closeServiceInstance() {
58 LOG.info("Instance {} closed", this.getClass().getSimpleName());
59 iseAdapterProvider.close();
60 return Futures.immediateFuture(null);
64 public void close() throws Exception {
65 LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
66 if (singletonServiceRegistration != null) {
68 singletonServiceRegistration.close();
69 } catch (Exception e) {
70 LOG.warn("{} closed unexpectedly. Cause: {}", e.getMessage());
72 singletonServiceRegistration = null;
77 public ServiceGroupIdentifier getIdentifier() {