Revert "Use managed transactions in elanmanager-impl"
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / utils / ElanClusterUtils.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.elan.utils;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.List;
12 import java.util.concurrent.Callable;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
16 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
17 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
18
19 @Singleton
20 public final class ElanClusterUtils {
21     private final EntityOwnershipUtils entityOwnershipUtils;
22     private final JobCoordinator jobCoordinator;
23
24     @Inject
25     public ElanClusterUtils(EntityOwnershipUtils entityOwnershipUtils, JobCoordinator jobCoordinator) {
26         this.entityOwnershipUtils = entityOwnershipUtils;
27         this.jobCoordinator = jobCoordinator;
28     }
29
30     public void runOnlyInOwnerNode(String jobDesc, Runnable job) {
31         entityOwnershipUtils.runOnlyInOwnerNode(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
32             HwvtepSouthboundConstants.ELAN_ENTITY_NAME, jobCoordinator, jobDesc, job);
33     }
34
35     public void runOnlyInOwnerNode(String jobKey, String jobDesc, Callable<List<ListenableFuture<Void>>> job) {
36         entityOwnershipUtils.runOnlyInOwnerNode(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
37             HwvtepSouthboundConstants.ELAN_ENTITY_NAME, jobCoordinator, jobKey, jobDesc, job);
38     }
39 }