2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.bgpcep.programming.impl;
10 import io.netty.util.Timeout;
11 import io.netty.util.concurrent.Future;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.opendaylight.bgpcep.programming.spi.ExecutionResult;
17 import org.opendaylight.bgpcep.programming.spi.InstructionExecutor;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.status.changed.Details;
22 import com.google.common.base.Preconditions;
24 final class Instruction {
25 private final List<Instruction> dependants = new ArrayList<>();
26 private final InstructionExecutor executor;
27 private final List<Instruction> dependencies;
28 private final InstructionId id;
29 private volatile InstructionStatus status = InstructionStatus.Queued;
30 private Timeout timeout;
32 Instruction(final InstructionId id, final InstructionExecutor executor, final List<Instruction> dependencies, final Timeout timeout) {
33 this.id = Preconditions.checkNotNull(id);
34 this.executor = Preconditions.checkNotNull(executor);
35 this.dependencies = Preconditions.checkNotNull(dependencies);
36 this.timeout = Preconditions.checkNotNull(timeout);
39 InstructionId getId() {
43 InstructionStatus getStatus() {
47 Future<ExecutionResult<Details>> execute() {
48 return executor.execute();
51 void setStatus(final InstructionStatus status) {
55 synchronized void cancel() {
56 if (timeout != null) {
62 synchronized void completed() {
66 synchronized void addDependant(final Instruction d) {
70 List<Instruction> getDependencies() {
74 List<Instruction> getDependants() {