|
32 | 32 |
|
33 | 33 | package org.opensearch.transport;
|
34 | 34 |
|
35 |
| -import org.opensearch.common.annotation.PublicApi; |
36 | 35 | import org.opensearch.common.bytes.ReleasableBytesReference;
|
37 | 36 | import org.opensearch.common.lease.Releasable;
|
38 |
| -import org.opensearch.common.lease.Releasables; |
39 |
| -import org.opensearch.common.util.io.IOUtils; |
40 | 37 | import org.opensearch.core.common.io.stream.StreamInput;
|
| 38 | +import org.opensearch.transport.nativeprotocol.NativeInboundMessage; |
41 | 39 |
|
42 | 40 | import java.io.IOException;
|
43 | 41 |
|
44 | 42 | /**
|
45 | 43 | * Inbound data as a message
|
46 |
| - * |
| 44 | + * This api is deprecated, please use {@link org.opensearch.transport.nativeprotocol.NativeInboundMessage} instead. |
47 | 45 | * @opensearch.api
|
48 | 46 | */
|
49 |
| -@PublicApi(since = "1.0.0") |
50 |
| -public class InboundMessage implements Releasable, BaseInboundMessage { |
| 47 | +@Deprecated |
| 48 | +public class InboundMessage implements Releasable, ProtocolInboundMessage { |
51 | 49 |
|
52 |
| - private final Header header; |
53 |
| - private final ReleasableBytesReference content; |
54 |
| - private final Exception exception; |
55 |
| - private final boolean isPing; |
56 |
| - private Releasable breakerRelease; |
57 |
| - private StreamInput streamInput; |
58 |
| - private String protocol; |
| 50 | + private NativeInboundMessage nativeInboundMessage; |
59 | 51 |
|
60 | 52 | public InboundMessage(Header header, ReleasableBytesReference content, Releasable breakerRelease) {
|
61 |
| - this.header = header; |
62 |
| - this.content = content; |
63 |
| - this.breakerRelease = breakerRelease; |
64 |
| - this.exception = null; |
65 |
| - this.isPing = false; |
| 53 | + this.nativeInboundMessage = new NativeInboundMessage(header, content, breakerRelease); |
66 | 54 | }
|
67 | 55 |
|
68 | 56 | public InboundMessage(Header header, Exception exception) {
|
69 |
| - this.header = header; |
70 |
| - this.content = null; |
71 |
| - this.breakerRelease = null; |
72 |
| - this.exception = exception; |
73 |
| - this.isPing = false; |
| 57 | + this.nativeInboundMessage = new NativeInboundMessage(header, exception); |
74 | 58 | }
|
75 | 59 |
|
76 | 60 | public InboundMessage(Header header, boolean isPing) {
|
77 |
| - this.header = header; |
78 |
| - this.content = null; |
79 |
| - this.breakerRelease = null; |
80 |
| - this.exception = null; |
81 |
| - this.isPing = isPing; |
| 61 | + this.nativeInboundMessage = new NativeInboundMessage(header, isPing); |
82 | 62 | }
|
83 | 63 |
|
84 | 64 | public Header getHeader() {
|
85 |
| - return header; |
| 65 | + return this.nativeInboundMessage.getHeader(); |
86 | 66 | }
|
87 | 67 |
|
88 | 68 | public int getContentLength() {
|
89 |
| - if (content == null) { |
90 |
| - return 0; |
91 |
| - } else { |
92 |
| - return content.length(); |
93 |
| - } |
| 69 | + return this.nativeInboundMessage.getContentLength(); |
94 | 70 | }
|
95 | 71 |
|
96 | 72 | public Exception getException() {
|
97 |
| - return exception; |
| 73 | + return this.nativeInboundMessage.getException(); |
98 | 74 | }
|
99 | 75 |
|
100 | 76 | public boolean isPing() {
|
101 |
| - return isPing; |
| 77 | + return this.nativeInboundMessage.isPing(); |
102 | 78 | }
|
103 | 79 |
|
104 | 80 | public boolean isShortCircuit() {
|
105 |
| - return exception != null; |
| 81 | + return this.nativeInboundMessage.getException() != null; |
106 | 82 | }
|
107 | 83 |
|
108 | 84 | public Releasable takeBreakerReleaseControl() {
|
109 |
| - final Releasable toReturn = breakerRelease; |
110 |
| - breakerRelease = null; |
111 |
| - if (toReturn != null) { |
112 |
| - return toReturn; |
113 |
| - } else { |
114 |
| - return () -> {}; |
115 |
| - } |
| 85 | + return this.nativeInboundMessage.takeBreakerReleaseControl(); |
116 | 86 | }
|
117 | 87 |
|
118 | 88 | public StreamInput openOrGetStreamInput() throws IOException {
|
119 |
| - assert isPing == false && content != null; |
120 |
| - if (streamInput == null) { |
121 |
| - streamInput = content.streamInput(); |
122 |
| - streamInput.setVersion(header.getVersion()); |
123 |
| - } |
124 |
| - return streamInput; |
| 89 | + return this.nativeInboundMessage.openOrGetStreamInput(); |
125 | 90 | }
|
126 | 91 |
|
127 | 92 | @Override
|
128 | 93 | public void close() {
|
129 |
| - IOUtils.closeWhileHandlingException(streamInput); |
130 |
| - Releasables.closeWhileHandlingException(content, breakerRelease); |
| 94 | + this.nativeInboundMessage.close(); |
131 | 95 | }
|
132 | 96 |
|
133 | 97 | @Override
|
134 | 98 | public String toString() {
|
135 |
| - return "InboundMessage{" + header + "}"; |
136 |
| - } |
137 |
| - |
138 |
| - @Override |
139 |
| - public String getProtocol() { |
140 |
| - return NATIVE_PROTOCOL; |
| 99 | + return this.nativeInboundMessage.toString(); |
141 | 100 | }
|
142 | 101 |
|
143 |
| - @Override |
144 |
| - public void setProtocol() { |
145 |
| - this.protocol = NATIVE_PROTOCOL; |
146 |
| - } |
147 | 102 | }
|
0 commit comments