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.pcep.topology.provider;
10 import com.google.common.base.Stopwatch;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.SettableFuture;
13 import java.util.Timer;
14 import java.util.concurrent.TimeUnit;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.lsp.metadata.Metadata;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 final class PCEPRequest {
27 private static final Logger LOG = LoggerFactory.getLogger(PCEPRequest.class);
28 private final SettableFuture<OperationResult> future;
29 private final Metadata metadata;
30 private volatile State state;
31 private final Stopwatch stopwatch;
32 private final Timer timer;
34 PCEPRequest(final Metadata metadata) {
35 this.future = SettableFuture.create();
36 this.metadata = metadata;
37 this.state = State.UNSENT;
38 this.stopwatch = Stopwatch.createStarted();
39 this.timer = new Timer();
42 protected ListenableFuture<OperationResult> getFuture() {
46 public Metadata getMetadata() {
50 public State getState() {
58 synchronized void done(final OperationResult result) {
59 if (this.state != State.DONE) {
60 LOG.debug("Request went from {} to {}", this.state, State.DONE);
61 this.state = State.DONE;
63 this.future.set(result);
67 synchronized void done() {
68 OperationResult result;
71 result = OperationResults.UNSENT;
74 result = OperationResults.NOACK;
84 synchronized void sent() {
85 if (this.state == State.UNSENT) {
86 LOG.debug("Request went from {} to {}", this.state, State.UNACKED);
87 this.state = State.UNACKED;
91 long getElapsedMillis() {
92 return this.stopwatch.elapsed(TimeUnit.MILLISECONDS);