Use ListenableFutures when submitting RPCs 93/3593/1
authorRobert Varga <rovarga@cisco.com>
Mon, 9 Dec 2013 19:04:03 +0000 (20:04 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 9 Dec 2013 19:04:03 +0000 (20:04 +0100)
Change-Id: Ie3f6f02b72a5520064523952aedb7cf923e1636b
Signed-off-by: Robert Varga <rovarga@cisco.com>
programming/impl-config/src/main/java/org/opendaylight/controller/config/yang/programming/impl/InstructionSchedulerImplModule.java
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java

index bcd9ab5222d496e6ed4b42b0198278fd56478f27..d47d1a840d2fac945511f17692ccea792578e4ea 100644 (file)
@@ -9,7 +9,6 @@
  */
 package org.opendaylight.controller.config.yang.programming.impl;
 
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
 import org.opendaylight.bgpcep.programming.impl.ProgrammingServiceImpl;
@@ -20,6 +19,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.failure._case.Failure;
 
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
 /**
  *
  */
@@ -45,7 +47,7 @@ org.opendaylight.controller.config.yang.programming.impl.AbstractInstructionSche
 
        @Override
        public java.lang.AutoCloseable createInstance() {
-               final ExecutorService exec = Executors.newSingleThreadExecutor();
+               final ListeningExecutorService exec = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
 
                final ProgrammingServiceImpl inst = new ProgrammingServiceImpl(getNotificationServiceDependency(), exec, getTimerDependency());
 
index 22ea11392a63251999f3a66ba528d8c4dfcd2175..951b694ddcc5694e8b820580617f1bf336c3994f 100644 (file)
@@ -62,6 +62,8 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
 
 public final class ProgrammingServiceImpl implements InstructionScheduler, ProgrammingService, AutoCloseable {
        private static final Logger LOG = LoggerFactory.getLogger(ProgrammingServiceImpl.class);
@@ -75,19 +77,19 @@ public final class ProgrammingServiceImpl implements InstructionScheduler, Progr
        private final Deque<Instruction> readyQueue = new ArrayDeque<>();
 
        private final NotificationProviderService notifs;
-       private final ExecutorService executor;
+       private final ListeningExecutorService executor;
        private final Timer timer;
        private Future<Void> thread;
        private ExecutorService exec;
 
-       public ProgrammingServiceImpl(final NotificationProviderService notifs, final ExecutorService executor, final Timer timer) {
+       public ProgrammingServiceImpl(final NotificationProviderService notifs, final ListeningExecutorService executor, final Timer timer) {
                this.notifs = Preconditions.checkNotNull(notifs);
                this.executor = Preconditions.checkNotNull(executor);
                this.timer = Preconditions.checkNotNull(timer);
        }
 
        @Override
-       public Future<RpcResult<CancelInstructionOutput>> cancelInstruction(final CancelInstructionInput input) {
+       public ListenableFuture<RpcResult<CancelInstructionOutput>> cancelInstruction(final CancelInstructionInput input) {
                return this.executor.submit(new Callable<RpcResult<CancelInstructionOutput>>() {
                        @Override
                        public RpcResult<CancelInstructionOutput> call() {
@@ -97,7 +99,7 @@ public final class ProgrammingServiceImpl implements InstructionScheduler, Progr
        }
 
        @Override
-       public Future<RpcResult<CleanInstructionsOutput>> cleanInstructions(final CleanInstructionsInput input) {
+       public ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanInstructions(final CleanInstructionsInput input) {
                return this.executor.submit(new Callable<RpcResult<CleanInstructionsOutput>>() {
                        @Override
                        public RpcResult<CleanInstructionsOutput> call() throws Exception {