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.concurrent.TimeUnit;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.lsp.metadata.Metadata;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 final class PCEPRequest {
26 private static final Logger LOG = LoggerFactory.getLogger(PCEPRequest.class);
27 private final SettableFuture<OperationResult> future;
28 private final Metadata metadata;
29 private volatile State state;
30 private final Stopwatch stopwatch;
32 PCEPRequest(final Metadata metadata) {
33 this.future = SettableFuture.create();
34 this.metadata = metadata;
35 this.state = State.UNSENT;
36 this.stopwatch = new Stopwatch().start();
39 protected ListenableFuture<OperationResult> getFuture() {
43 public Metadata getMetadata() {
47 public State getState() {
51 public synchronized void done(final OperationResult result) {
52 if (state != State.DONE) {
53 LOG.debug("Request went from {} to {}", state, State.DONE);
59 public synchronized void sent() {
60 if (state == State.UNSENT) {
61 LOG.debug("Request went from {} to {}", state, State.UNACKED);
62 state = State.UNACKED;
66 public long getElapsedMillis() {
67 return this.stopwatch.elapsed(TimeUnit.MILLISECONDS);