2 * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.frm.impl;
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.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Service (per device) for registration in singleton provider.
23 public class DeviceMastership implements ClusterSingletonService {
24 private static final Logger LOG = LoggerFactory.getLogger(DeviceMastership.class);
25 private final NodeId nodeId;
26 private final ServiceGroupIdentifier identifier;
27 private ClusterSingletonServiceRegistration clusterSingletonServiceRegistration;
28 private boolean deviceMastered;
30 public DeviceMastership(final NodeId nodeId) {
32 this.identifier = ServiceGroupIdentifier.create(nodeId.getValue());
33 this.deviceMastered = false;
37 public void instantiateServiceInstance() {
38 LOG.debug("FRM started for: {}", nodeId.getValue());
39 deviceMastered = true;
43 public ListenableFuture<Void> closeServiceInstance() {
44 LOG.debug("FRM stopped for: {}", nodeId.getValue());
45 deviceMastered = false;
46 return Futures.immediateFuture(null);
50 public ServiceGroupIdentifier getIdentifier() {
54 public boolean isDeviceMastered() {
55 return deviceMastered;
58 public void setClusterSingletonServiceRegistration(final ClusterSingletonServiceRegistration registration) {
59 this.clusterSingletonServiceRegistration = registration;
62 public ClusterSingletonServiceRegistration getClusterSingletonServiceRegistration() {
63 return clusterSingletonServiceRegistration;