2 * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.core.connection;
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.FutureCallback;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 final class OutboundQueueEntry {
19 private static final Logger LOG = LoggerFactory.getLogger(OutboundQueueEntry.class);
20 private FutureCallback<OfHeader> callback;
21 private OfHeader message;
22 private boolean completed;
23 private volatile boolean committed;
25 void commit(final OfHeader message, final FutureCallback<OfHeader> callback) {
26 this.message = message;
27 this.callback = callback;
29 // Volatile write, needs to be last
38 // Volatile write, needs to be last
43 return message instanceof BarrierInput;
46 boolean isCommitted() {
50 boolean isCompleted() {
54 OfHeader getMessage() {
58 boolean complete(final OfHeader response) {
59 Preconditions.checkState(!completed, "Attempted to complete a completed message %s with response %s", message, response);
61 // Multipart requests are special, we have to look at them to see
62 // if there is something outstanding and adjust ourselves accordingly
63 final boolean reallyComplete;
64 if (response instanceof MultipartReplyMessage) {
65 reallyComplete = !((MultipartReplyMessage) response).getFlags().isOFPMPFREQMORE();
66 LOG.debug("Multipart reply {}", response);
68 reallyComplete = true;
71 completed = reallyComplete;
72 if (callback != null) {
73 callback.onSuccess(response);
75 LOG.debug("Entry {} completed {} with response {}", this, completed, response);
76 return reallyComplete;
79 void fail(final Throwable cause) {
82 if (callback != null) {
83 callback.onFailure(cause);
86 LOG.warn("Ignoring failure {} for completed message {}", cause, message);