539f7f7b0e501591748c3de76139c0f741d0b59f
[netvirt.git] /
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.internal;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14
15 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
16 import org.opendaylight.netvirt.elan.utils.ElanUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class InterfaceRemoveWorkerOnElan implements Callable<List<ListenableFuture<Void>>> {
22
23     private static final Logger LOG = LoggerFactory.getLogger(InterfaceRemoveWorkerOnElan.class);
24
25     private final String key;
26     private final ElanInstance elanInfo;
27     private final String interfaceName;
28     private final InterfaceInfo interfaceInfo;
29     private final boolean isInterfaceStateRemoved;
30     private final ElanInterfaceManager dataChangeListener;
31
32     public InterfaceRemoveWorkerOnElan(String key, ElanInstance elanInfo, String interfaceName,
33             InterfaceInfo interfaceInfo, boolean isInterfaceStateRemoved, ElanInterfaceManager dataChangeListener) {
34         this.key = key;
35         this.elanInfo = elanInfo;
36         this.interfaceName = interfaceName;
37         this.interfaceInfo = interfaceInfo;
38         this.isInterfaceStateRemoved = isInterfaceStateRemoved;
39         this.dataChangeListener = dataChangeListener;
40     }
41
42     @Override
43     public String toString() {
44         return "InterfaceRemoveWorkerOnElan [key=" + key + ", elanInfo=" + elanInfo
45             + ", interfaceName=" + interfaceName
46             + ", interfaceInfo=" + interfaceInfo + "]";
47     }
48
49     @Override
50     @SuppressWarnings("checkstyle:IllegalCatch")
51     public List<ListenableFuture<Void>> call() throws Exception {
52         List<ListenableFuture<Void>> futures = new ArrayList<>();
53         try {
54             futures.addAll(dataChangeListener.removeElanInterface(elanInfo, interfaceName, interfaceInfo,
55                     isInterfaceStateRemoved));
56         } catch (RuntimeException e) {
57             LOG.error("Error while processing key {} for elan interface {} and elan {}",
58                     key, interfaceName, elanInfo, e);
59             ElanUtils.addToListenableFutureIfTxException(e, futures);
60         }
61         return futures;
62     }
63
64 }