X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Ftopology-spi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fbgpcep%2Fpcep%2Ftopology%2Fspi%2FAbstractInstructionExecutor.java;h=69dcc41e13d1674fb435927a2c3b024c967cdb0c;hb=150ed34044d43e7e8e2af102e763cd944501c609;hp=a7b55bb56668cbb2c52a644bb400c0cfc7b75e63;hpb=30db7b55e989bcc68bf7535f2b308758b11a6d91;p=bgpcep.git diff --git a/pcep/topology-spi/src/main/java/org/opendaylight/bgpcep/pcep/topology/spi/AbstractInstructionExecutor.java b/pcep/topology-spi/src/main/java/org/opendaylight/bgpcep/pcep/topology/spi/AbstractInstructionExecutor.java index a7b55bb566..69dcc41e13 100644 --- a/pcep/topology-spi/src/main/java/org/opendaylight/bgpcep/pcep/topology/spi/AbstractInstructionExecutor.java +++ b/pcep/topology-spi/src/main/java/org/opendaylight/bgpcep/pcep/topology/spi/AbstractInstructionExecutor.java @@ -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 { + + private static final class InstructionCallback implements FutureCallback { + + 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 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 s = invokeOperation(); - Futures.addCallback(s, new FutureCallback() { - @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)); } }