Removed some sonar warnings.
[bgpcep.git] / pcep / topology-spi / src / main / java / org / opendaylight / bgpcep / pcep / topology / spi / AbstractInstructionExecutor.java
index a7b55bb56668cbb2c52a644bb400c0cfc7b75e63..69dcc41e13d1674fb435927a2c3b024c967cdb0c 100644 (file)
@@ -22,10 +22,41 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- *
- */
 public abstract class AbstractInstructionExecutor implements FutureCallback<Instruction> {
+
+    private static final class InstructionCallback implements FutureCallback<OperationResult> {
+
+        private final Instruction insn;
+
+        public InstructionCallback(final Instruction insn) {
+            this.insn = insn;
+        }
+
+        @Override
+        public void onSuccess(final OperationResult result) {
+            if (result.getFailure() != null) {
+                switch (result.getFailure()) {
+                case Failed:
+                case NoAck:
+                    this.insn.executionCompleted(InstructionStatus.Failed, null);
+                    break;
+                case Unsent:
+                    this.insn.executionCompleted(InstructionStatus.Cancelled, null);
+                    break;
+                default:
+                    break;
+                }
+            } else {
+                this.insn.executionCompleted(InstructionStatus.Successful, null);
+            }
+        }
+
+        @Override
+        public void onFailure(final Throwable t) {
+            this.insn.executionCompleted(InstructionStatus.Failed, null);
+        }
+    }
+
     private static final Logger LOG = LoggerFactory.getLogger(AbstractInstructionExecutor.class);
     private final SubmitInstructionInput input;
 
@@ -39,14 +70,12 @@ public abstract class AbstractInstructionExecutor implements FutureCallback<Inst
 
     public static FailureCase schedule(final InstructionScheduler scheduler, final AbstractInstructionExecutor fwd) {
         final ListenableFuture<Instruction> s;
-
         try {
             s = scheduler.scheduleInstruction(fwd.getInput());
         } catch (final SchedulerException e) {
             LOG.info("Instuction {} failed to schedule", e.getMessage(), e);
             return new FailureCaseBuilder().setFailure(e.getFailure()).build();
         }
-
         Futures.addCallback(s, fwd);
         return null;
     }
@@ -57,31 +86,7 @@ public abstract class AbstractInstructionExecutor implements FutureCallback<Inst
     public void onSuccess(final Instruction insn) {
         if (insn.checkedExecutionStart()) {
             final ListenableFuture<OperationResult> s = invokeOperation();
-            Futures.addCallback(s, new FutureCallback<OperationResult>() {
-                @Override
-                public void onSuccess(final OperationResult result) {
-                    if (result.getFailure() != null) {
-                        switch (result.getFailure()) {
-                        case Failed:
-                        case NoAck:
-                            insn.executionCompleted(InstructionStatus.Failed, null);
-                            break;
-                        case Unsent:
-                            insn.executionCompleted(InstructionStatus.Cancelled, null);
-                            break;
-                        default:
-                            break;
-                        }
-                    } else {
-                        insn.executionCompleted(InstructionStatus.Successful, null);
-                    }
-                }
-
-                @Override
-                public void onFailure(final Throwable t) {
-                    insn.executionCompleted(InstructionStatus.Failed, null);
-                }
-            });
+            Futures.addCallback(s, new InstructionCallback(insn));
         }
     }