2 * Copyright (c) 2016 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.controller.cluster.access.client;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import java.util.function.Consumer;
15 import org.opendaylight.controller.cluster.access.concepts.Request;
16 import org.opendaylight.controller.cluster.access.concepts.Response;
17 import org.opendaylight.yangtools.concepts.Immutable;
20 * Single entry in a {@link AbstractClientConnection}. Tracks the request, the associated callback and time when
21 * the request was first enqueued.
23 public class ConnectionEntry implements Immutable {
24 private final Consumer<Response<?, ?>> callback;
25 private final Request<?, ?> request;
26 private final long enqueuedTicks;
28 ConnectionEntry(final Request<?, ?> request, final Consumer<Response<?, ?>> callback, final long now) {
29 this.request = requireNonNull(request);
30 this.callback = requireNonNull(callback);
34 ConnectionEntry(final ConnectionEntry entry) {
35 this(entry.request, entry.callback, entry.enqueuedTicks);
38 public final Consumer<Response<?, ?>> getCallback() {
42 public final Request<?, ?> getRequest() {
46 public void complete(final Response<?, ?> response) {
47 callback.accept(response);
50 public final long getEnqueuedTicks() {
55 public final String toString() {
56 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
59 ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
60 return toStringHelper.add("request", request).add("enqueuedTicks", enqueuedTicks);