Bug 7449: Slice ReadTransactionSuccess response
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / RequestEnvelope.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.access.concepts;
9
10 import akka.actor.ActorRef;
11
12 public final class RequestEnvelope extends Envelope<Request<?, ?>> {
13     private static final long serialVersionUID = 1L;
14
15     public RequestEnvelope(final Request<?, ?> message, final long sessionId, final long txSequence) {
16         super(message, sessionId, txSequence);
17     }
18
19     @Override
20     RequestEnvelopeProxy createProxy() {
21         return new RequestEnvelopeProxy(this);
22     }
23
24     /**
25      * Respond to this envelope with a {@link RequestFailure} caused by specified {@link RequestException}.
26      *
27      * @param cause Cause of this {@link RequestFailure}
28      * @param executionTimeNanos Time to execute the request, in nanoseconds
29      * @throws NullPointerException if cause is null
30      */
31     public void sendFailure(final RequestException cause, final long executionTimeNanos) {
32         sendResponse(new FailureEnvelope(getMessage().toRequestFailure(cause), getSessionId(), getTxSequence(),
33             executionTimeNanos));
34     }
35
36     /**
37      * Respond to this envelope with a {@link RequestSuccess}.
38      *
39      * @param success Successful response
40      * @throws NullPointerException if success is null
41      */
42     public void sendSuccess(final RequestSuccess<?, ?> success, final long executionTimeNanos) {
43         sendResponse(newSuccessEnvelope(success, executionTimeNanos));
44     }
45
46     /**
47      * Creates a successful ResponseEnvelope that wraps the given successful Request response message.
48      *
49      * @param success the successful Request response message
50      * @param executionTimeNanos the execution time of the request
51      * @return a {@link ResponseEnvelope} instance
52      */
53     public ResponseEnvelope<?> newSuccessEnvelope(final RequestSuccess<?, ?> success, final long executionTimeNanos) {
54         return new SuccessEnvelope(success, getSessionId(), getTxSequence(), executionTimeNanos);
55     }
56
57     private void sendResponse(final ResponseEnvelope<?> envelope) {
58         getMessage().getReplyTo().tell(envelope, ActorRef.noSender());
59     }
60 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.