Remove use of JdkFutureAdapters 93/73893/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 10 Jul 2018 18:46:09 +0000 (20:46 +0200)
committerFaseela K <faseela.k@ericsson.com>
Wed, 11 Jul 2018 12:19:41 +0000 (12:19 +0000)
RPCs are now exposing ListenableFuture, there is no need to adapt
them.

Change-Id: Iee32036c0a2a1c044dc4c14c19f6d6eb408588af
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
alivenessmonitor/alivenessmonitor-impl-protocols/src/main/java/org/opendaylight/genius/alivenessmonitor/protocols/internal/AlivenessProtocolHandlerARP.java
alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/genius/alivenessmonitor/internal/AlivenessMonitor.java
arputil/arputil-impl/src/main/java/org/opendaylight/genius/arputil/internal/ArpUtilImpl.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/AlivenessMonitorUtils.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/pmcounters/NodeConnectorStatsImpl.java

index f15b3535a98b8fe466ed956c621f8d42498f4050..149b8f3685fbf9969c3f1160211f5a72f6e490d5 100644 (file)
@@ -14,8 +14,8 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.math.BigInteger;
 import java.util.Collection;
 import java.util.Collections;
@@ -152,22 +152,21 @@ public class AlivenessProtocolHandlerARP extends AbstractAlivenessProtocolHandle
             ListenableFuture<RpcResult<SendArpRequestOutput>> future = arpService.sendArpRequest(input);
             final String msgFormat = String.format("Send ARP Request on interface %s to destination %s",
                     sourceInterface, targetIp);
-            Futures.addCallback(JdkFutureAdapters.listenInPoolThread(future),
-                    new FutureCallback<RpcResult<SendArpRequestOutput>>() {
-                        @Override
-                        public void onFailure(Throwable error) {
-                            LOG.error("Error - {}", msgFormat, error);
-                        }
-
-                        @Override
-                        public void onSuccess(RpcResult<SendArpRequestOutput> result) {
-                            if (result != null && !result.isSuccessful()) {
-                                LOG.warn("Rpc call to {} failed {}", msgFormat, getErrorText(result.getErrors()));
-                            } else {
-                                LOG.debug("Successful RPC Result - {}", msgFormat);
-                            }
-                        }
-                    });
+            Futures.addCallback(future, new FutureCallback<RpcResult<SendArpRequestOutput>>() {
+                @Override
+                public void onFailure(Throwable error) {
+                    LOG.error("Error - {}", msgFormat, error);
+                }
+
+                @Override
+                public void onSuccess(RpcResult<SendArpRequestOutput> result) {
+                    if (result != null && !result.isSuccessful()) {
+                        LOG.warn("Rpc call to {} failed {}", msgFormat, getErrorText(result.getErrors()));
+                    } else {
+                        LOG.debug("Successful RPC Result - {}", msgFormat);
+                    }
+                }
+            }, MoreExecutors.directExecutor());
         }
     }
 
index 04f691c371cda2a8932404f0efb6024e94d381b2..8f77b959cef1b41221a4b7738f498cb0ee36090f 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
@@ -228,23 +227,21 @@ public class AlivenessMonitor extends AbstractClusteredSyncDataTreeChangeListene
                 .setPoolName(AlivenessMonitorConstants.MONITOR_IDPOOL_NAME)
                 .setLow(AlivenessMonitorConstants.MONITOR_IDPOOL_START)
                 .setHigh(AlivenessMonitorConstants.MONITOR_IDPOOL_SIZE).build();
-        ListenableFuture<RpcResult<CreateIdPoolOutput>> resultFuture = idManager.createIdPool(createPool);
-        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(resultFuture),
-                new FutureCallback<RpcResult<CreateIdPoolOutput>>() {
-                    @Override
-                    public void onFailure(Throwable error) {
-                        LOG.error("Failed to create idPool for Aliveness Monitor Service", error);
-                    }
+        Futures.addCallback(idManager.createIdPool(createPool), new FutureCallback<RpcResult<CreateIdPoolOutput>>() {
+            @Override
+            public void onFailure(Throwable error) {
+                LOG.error("Failed to create idPool for Aliveness Monitor Service", error);
+            }
 
-                    @Override
-                    public void onSuccess(@Nonnull RpcResult<CreateIdPoolOutput> result) {
-                        if (result.isSuccessful()) {
-                            LOG.debug("Created IdPool for Aliveness Monitor Service");
-                        } else {
-                            LOG.error("RPC to create Idpool failed {}", result.getErrors());
-                        }
-                    }
-                }, callbackExecutorService);
+            @Override
+            public void onSuccess(@Nonnull RpcResult<CreateIdPoolOutput> result) {
+                if (result.isSuccessful()) {
+                    LOG.debug("Created IdPool for Aliveness Monitor Service");
+                } else {
+                    LOG.error("RPC to create Idpool failed {}", result.getErrors());
+                }
+            }
+        }, callbackExecutorService);
     }
 
     private int getUniqueId(final String idKey) {
index f8251043a32aafef8e26b76ca305a58655bcbbcd..2dfcea572efb561b6935ce183d3ac143373761fd 100644 (file)
@@ -13,7 +13,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
 
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
@@ -177,20 +176,19 @@ public class ArpUtilImpl extends AbstractLifecycle implements OdlArputilService,
             ListenableFuture<RpcResult<SendArpRequestOutput>> arpReqFt = sendArpRequest(builder.build());
             final SettableFuture<RpcResult<GetMacOutput>> ft = SettableFuture.create();
 
-            Futures.addCallback(JdkFutureAdapters.listenInPoolThread(arpReqFt, threadPool),
-                    new FutureCallback<RpcResult<SendArpRequestOutput>>() {
-                        @Override
-                        public void onFailure(Throwable ex) {
-                            RpcResultBuilder<GetMacOutput> resultBuilder = RpcResultBuilder.<GetMacOutput>failed()
-                                    .withError(ErrorType.APPLICATION, ex.getMessage(), ex);
-                            ft.set(resultBuilder.build());
-                        }
-
-                        @Override
-                        public void onSuccess(RpcResult<SendArpRequestOutput> result) {
-                            LOG.trace("Successfully sent the arp pkt out for ip {}", dstIpAddress);
-                        }
-                    }, MoreExecutors.directExecutor());
+            Futures.addCallback(arpReqFt, new FutureCallback<RpcResult<SendArpRequestOutput>>() {
+                @Override
+                public void onFailure(Throwable ex) {
+                    RpcResultBuilder<GetMacOutput> resultBuilder = RpcResultBuilder.<GetMacOutput>failed()
+                            .withError(ErrorType.APPLICATION, ex.getMessage(), ex);
+                    ft.set(resultBuilder.build());
+                }
+
+                @Override
+                public void onSuccess(RpcResult<SendArpRequestOutput> result) {
+                    LOG.trace("Successfully sent the arp pkt out for ip {}", dstIpAddress);
+                }
+            }, MoreExecutors.directExecutor());
 
             macAddrs.put(dstIpAddress, ft);
             return ft;
index daec8fe358f89dca9a2beb77d612e4c254168c82..c360afec4b8af092c77f6a5e39b0eededb7ae3bb 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.genius.interfacemanager.commons;
 
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.List;
@@ -16,7 +15,6 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
@@ -130,8 +128,7 @@ public final class AlivenessMonitorUtils {
                     MonitorStopInput input = new MonitorStopInputBuilder().setMonitorId(monitorId).build();
 
                     ListenableFuture<RpcResult<MonitorStopOutput>> future = alivenessMonitorService.monitorStop(input);
-                    ListenableFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(future),
-                            LOG, "Stop LLDP monitoring for {}", trunkInterface);
+                    ListenableFutures.addErrorLogging(future, LOG, "Stop LLDP monitoring for {}", trunkInterface);
 
                     removeMonitorIdInterfaceMap(tx, monitorId);
                     removeMonitorIdFromInterfaceMonitorIdMap(tx, interfaceName, monitorId);
@@ -208,8 +205,7 @@ public final class AlivenessMonitorUtils {
 
                 ListenableFuture<RpcResult<MonitorProfileDeleteOutput>> future =
                         alivenessMonitorService.monitorProfileDelete(profileDeleteInput);
-                ListenableFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(future),
-                        LOG, "Delete monitor profile {}", interfaceName);
+                ListenableFutures.addErrorLogging(future, LOG, "Delete monitor profile {}", interfaceName);
             }
         }
     }
index 44b915d164818f7f503db97ee1aef9b3248517c7..a794a85659109a9f193b15c51fcc12e7b7fb2065 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.genius.interfacemanager.pmcounters;
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -21,7 +20,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ThreadFactory;
@@ -31,7 +29,6 @@ import javax.annotation.Nonnull;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
@@ -161,14 +158,11 @@ public class NodeConnectorStatsImpl extends AsyncClusteredDataTreeChangeListener
             for (BigInteger node : nodes) {
                 LOG.trace("Requesting AllNodeConnectorStatistics and flow table statistics for node - {}", node);
                 // Call RPC to Get NodeConnector Stats for node
-                Future<RpcResult<GetNodeConnectorStatisticsOutput>> ncStatsFuture = opendaylightDirectStatisticsService
-                        .getNodeConnectorStatistics(buildGetNodeConnectorStatisticsInput(node));
-                //Create ListenableFuture to get RPC result asynchronously
-                ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> ncStatsListenableFuture =
-                        JdkFutureAdapters.listenInPoolThread(ncStatsFuture);
+                ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> ncStatsFuture =
+                        opendaylightDirectStatisticsService.getNodeConnectorStatistics(
+                            buildGetNodeConnectorStatisticsInput(node));
 
-                Futures.addCallback(ncStatsListenableFuture, new
-                        FutureCallback<RpcResult<GetNodeConnectorStatisticsOutput>>() {
+                Futures.addCallback(ncStatsFuture, new FutureCallback<RpcResult<GetNodeConnectorStatisticsOutput>>() {
 
                     @Override
                     public void onFailure(@Nonnull Throwable error) {
@@ -191,14 +185,10 @@ public class NodeConnectorStatsImpl extends AsyncClusteredDataTreeChangeListener
                 }, MoreExecutors.directExecutor());
 
                 // Call RPC to Get flow stats for node
-                Future<RpcResult<GetFlowStatisticsOutput>>  flowStatsFuture = opendaylightDirectStatisticsService
-                        .getFlowStatistics(buildGetFlowStatisticsInput(node));
-                //Create ListenableFuture to get RPC result asynchronously
-                ListenableFuture<RpcResult<GetFlowStatisticsOutput>> flowStatsListenableFuture =
-                        JdkFutureAdapters.listenInPoolThread(flowStatsFuture);
-
-                Futures.addCallback(flowStatsListenableFuture, new
-                        FutureCallback<RpcResult<GetFlowStatisticsOutput>>() {
+                ListenableFuture<RpcResult<GetFlowStatisticsOutput>> flowStatsFuture =
+                        opendaylightDirectStatisticsService.getFlowStatistics(buildGetFlowStatisticsInput(node));
+
+                Futures.addCallback(flowStatsFuture, new FutureCallback<RpcResult<GetFlowStatisticsOutput>>() {
 
                     @Override
                     public void onFailure(@Nonnull Throwable error) {