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.concepts;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.concepts.WritableObjects;
18 public abstract class ResponseEnvelope<T extends Response<?, ?>> extends Envelope<T> {
19 interface SerialForm<T extends Response<?, ?>, E extends ResponseEnvelope<T>> extends Envelope.SerialForm<T, E> {
21 default void writeExternal(final ObjectOutput out, final @NonNull E envelope) throws IOException {
22 Envelope.SerialForm.super.writeExternal(out, envelope);
23 WritableObjects.writeLong(out, envelope.getExecutionTimeNanos());
27 default E readExternal(final ObjectInput in, final long sessionId, final long txSequence, final T message)
29 return readExternal(in, sessionId, txSequence, message, WritableObjects.readLong(in));
32 E readExternal(ObjectInput in, long sessionId, long txSequence, T message, long executionTimeNanos);
36 private static final long serialVersionUID = 1L;
38 private final long executionTimeNanos;
40 ResponseEnvelope(final T message, final long sessionId, final long txSequence, final long executionTimeNanos) {
41 super(message, sessionId, txSequence);
42 checkArgument(executionTimeNanos >= 0, "Negative executionTime");
43 this.executionTimeNanos = executionTimeNanos;
47 * Return the time the request took to execute in nanoseconds. This may not reflect the actual CPU time, but rather
48 * a measure of the complexity involved in servicing the original request.
50 * @return Time the request took to execute in nanoseconds
52 public final long getExecutionTimeNanos() {
53 return executionTimeNanos;