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.openflowplugin.applications.frsync.impl.clustering;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
14 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
15 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
16 import org.opendaylight.openflowplugin.applications.frsync.util.ReconciliationRegistry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * {@link ClusterSingletonService} clusterSingletonServiceRegistration per connected device.
24 public class DeviceMastership implements ClusterSingletonService {
25 private static final Logger LOG = LoggerFactory.getLogger(DeviceMastership.class);
26 private final NodeId nodeId;
27 private final ServiceGroupIdentifier identifier;
28 private final ReconciliationRegistry reconciliationRegistry;
29 private ClusterSingletonServiceRegistration clusterSingletonServiceRegistration;
30 private boolean deviceMastered;
32 public DeviceMastership(final NodeId nodeId, final ReconciliationRegistry reconciliationRegistry) {
34 this.identifier = ServiceGroupIdentifier.create(nodeId.getValue());
35 this.reconciliationRegistry = reconciliationRegistry;
36 this.deviceMastered = false;
40 public void instantiateServiceInstance() {
41 deviceMastered = true;
42 reconciliationRegistry.register(nodeId);
43 LOG.trace("FRS started for: {}", nodeId.getValue());
47 public ListenableFuture<Void> closeServiceInstance() {
48 deviceMastered = false;
49 reconciliationRegistry.unregisterIfRegistered(nodeId);
50 LOG.debug("FRS stopped for: {}", nodeId.getValue());
51 return Futures.immediateFuture(null);
55 public ServiceGroupIdentifier getIdentifier() {
59 public boolean isDeviceMastered() {
60 return deviceMastered;
63 public void setClusterSingletonServiceRegistration(final ClusterSingletonServiceRegistration registration) {
64 this.clusterSingletonServiceRegistration = registration;
67 public ClusterSingletonServiceRegistration getClusterSingletonServiceRegistration() {
68 return clusterSingletonServiceRegistration;