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() {
54 public Timer getTimer() {
58 public synchronized void done(final OperationResult result) {
59 if (state != State.DONE) {
60 LOG.debug("Request went from {} to {}", state, State.DONE);
67 public synchronized void done() {
68 OperationResult result = null;
71 result = OperationResults.UNSENT;
74 result = OperationResults.NOACK;
82 public synchronized void sent() {
83 if (state == State.UNSENT) {
84 LOG.debug("Request went from {} to {}", state, State.UNACKED);
85 state = State.UNACKED;
89 public long getElapsedMillis() {
90 return this.stopwatch.elapsed(TimeUnit.MILLISECONDS);