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.openflowjava.protocol.api.connection.OutboundQueueException;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 final class OutboundQueueEntry {
20 private static final Logger LOG = LoggerFactory.getLogger(OutboundQueueEntry.class);
21 private FutureCallback<OfHeader> callback;
22 private OfHeader message;
23 private boolean completed;
24 private boolean barrier;
25 private volatile boolean committed;
27 void commit(final OfHeader message, final FutureCallback<OfHeader> callback) {
28 this.message = message;
29 this.callback = callback;
30 this.barrier = message instanceof BarrierInput;
32 // Volatile write, needs to be last
42 // Volatile write, needs to be last
50 boolean isCommitted() {
54 boolean isCompleted() {
58 OfHeader takeMessage() {
59 final OfHeader ret = message;
64 boolean complete(final OfHeader response) {
65 Preconditions.checkState(!completed, "Attempted to complete a completed message with response %s", response);
67 // Multipart requests are special, we have to look at them to see
68 // if there is something outstanding and adjust ourselves accordingly
69 final boolean reallyComplete;
70 if (response instanceof MultipartReplyMessage) {
71 reallyComplete = !((MultipartReplyMessage) response).getFlags().isOFPMPFREQMORE();
72 LOG.debug("Multipart reply {}", response);
74 reallyComplete = true;
77 completed = reallyComplete;
78 if (callback != null) {
79 callback.onSuccess(response);
81 // We will not need the callback anymore, make sure it can be GC'd
85 LOG.debug("Entry {} completed {} with response {}", this, completed, response);
86 return reallyComplete;
89 void fail(final OutboundQueueException cause) {
92 if (callback != null) {
93 callback.onFailure(cause);
97 LOG.warn("Ignoring failure {} for completed message", cause);