Skip to content

Commit c49ae89

Browse files
committed
Revert "Replacing InboundMessage with NativeInboundMessage for deprecation (opensearch-project#13126)"
This reverts commit f5c3ef9.
1 parent 20ebe6e commit c49ae89

File tree

9 files changed

+157
-78
lines changed

9 files changed

+157
-78
lines changed

server/src/main/java/org/opensearch/transport/InboundAggregator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.opensearch.core.common.bytes.BytesArray;
4141
import org.opensearch.core.common.bytes.BytesReference;
4242
import org.opensearch.core.common.bytes.CompositeBytesReference;
43-
import org.opensearch.transport.nativeprotocol.NativeInboundMessage;
4443

4544
import java.io.IOException;
4645
import java.util.ArrayList;
@@ -114,7 +113,7 @@ public void aggregate(ReleasableBytesReference content) {
114113
}
115114
}
116115

117-
public NativeInboundMessage finishAggregation() throws IOException {
116+
public InboundMessage finishAggregation() throws IOException {
118117
ensureOpen();
119118
final ReleasableBytesReference releasableContent;
120119
if (isFirstContent()) {
@@ -128,7 +127,7 @@ public NativeInboundMessage finishAggregation() throws IOException {
128127
}
129128

130129
final BreakerControl breakerControl = new BreakerControl(circuitBreaker);
131-
final NativeInboundMessage aggregated = new NativeInboundMessage(currentHeader, releasableContent, breakerControl);
130+
final InboundMessage aggregated = new InboundMessage(currentHeader, releasableContent, breakerControl);
132131
boolean success = false;
133132
try {
134133
if (aggregated.getHeader().needsToReadVariableHeader()) {
@@ -143,7 +142,7 @@ public NativeInboundMessage finishAggregation() throws IOException {
143142
if (isShortCircuited()) {
144143
aggregated.close();
145144
success = true;
146-
return new NativeInboundMessage(aggregated.getHeader(), aggregationException);
145+
return new InboundMessage(aggregated.getHeader(), aggregationException);
147146
} else {
148147
success = true;
149148
return aggregated;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/*
10+
* Licensed to Elasticsearch under one or more contributor
11+
* license agreements. See the NOTICE file distributed with
12+
* this work for additional information regarding copyright
13+
* ownership. Elasticsearch licenses this file to you under
14+
* the Apache License, Version 2.0 (the "License"); you may
15+
* not use this file except in compliance with the License.
16+
* You may obtain a copy of the License at
17+
*
18+
* http://www.apache.org/licenses/LICENSE-2.0
19+
*
20+
* Unless required by applicable law or agreed to in writing,
21+
* software distributed under the License is distributed on an
22+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23+
* KIND, either express or implied. See the License for the
24+
* specific language governing permissions and limitations
25+
* under the License.
26+
*/
27+
28+
/*
29+
* Modifications Copyright OpenSearch Contributors. See
30+
* GitHub history for details.
31+
*/
32+
33+
package org.opensearch.transport;
34+
35+
import org.opensearch.common.annotation.DeprecatedApi;
36+
import org.opensearch.common.bytes.ReleasableBytesReference;
37+
import org.opensearch.common.lease.Releasable;
38+
import org.opensearch.core.common.io.stream.StreamInput;
39+
import org.opensearch.transport.nativeprotocol.NativeInboundMessage;
40+
41+
import java.io.IOException;
42+
43+
/**
44+
* Inbound data as a message
45+
* This api is deprecated, please use {@link org.opensearch.transport.nativeprotocol.NativeInboundMessage} instead.
46+
* @opensearch.api
47+
*/
48+
@DeprecatedApi(since = "2.14.0")
49+
public class InboundMessage implements Releasable, ProtocolInboundMessage {
50+
51+
private final NativeInboundMessage nativeInboundMessage;
52+
53+
public InboundMessage(Header header, ReleasableBytesReference content, Releasable breakerRelease) {
54+
this.nativeInboundMessage = new NativeInboundMessage(header, content, breakerRelease);
55+
}
56+
57+
public InboundMessage(Header header, Exception exception) {
58+
this.nativeInboundMessage = new NativeInboundMessage(header, exception);
59+
}
60+
61+
public InboundMessage(Header header, boolean isPing) {
62+
this.nativeInboundMessage = new NativeInboundMessage(header, isPing);
63+
}
64+
65+
public Header getHeader() {
66+
return this.nativeInboundMessage.getHeader();
67+
}
68+
69+
public int getContentLength() {
70+
return this.nativeInboundMessage.getContentLength();
71+
}
72+
73+
public Exception getException() {
74+
return this.nativeInboundMessage.getException();
75+
}
76+
77+
public boolean isPing() {
78+
return this.nativeInboundMessage.isPing();
79+
}
80+
81+
public boolean isShortCircuit() {
82+
return this.nativeInboundMessage.getException() != null;
83+
}
84+
85+
public Releasable takeBreakerReleaseControl() {
86+
return this.nativeInboundMessage.takeBreakerReleaseControl();
87+
}
88+
89+
public StreamInput openOrGetStreamInput() throws IOException {
90+
return this.nativeInboundMessage.openOrGetStreamInput();
91+
}
92+
93+
@Override
94+
public void close() {
95+
this.nativeInboundMessage.close();
96+
}
97+
98+
@Override
99+
public String toString() {
100+
return this.nativeInboundMessage.toString();
101+
}
102+
103+
@Override
104+
public String getProtocol() {
105+
return this.nativeInboundMessage.getProtocol();
106+
}
107+
108+
}

server/src/main/java/org/opensearch/transport/NativeMessageHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.opensearch.telemetry.tracing.Tracer;
5353
import org.opensearch.telemetry.tracing.channels.TraceableTcpTransportChannel;
5454
import org.opensearch.threadpool.ThreadPool;
55-
import org.opensearch.transport.nativeprotocol.NativeInboundMessage;
5655
import org.opensearch.transport.nativeprotocol.NativeOutboundHandler;
5756

5857
import java.io.EOFException;
@@ -119,7 +118,7 @@ public void messageReceived(
119118
long slowLogThresholdMs,
120119
TransportMessageListener messageListener
121120
) throws IOException {
122-
NativeInboundMessage inboundMessage = (NativeInboundMessage) message;
121+
InboundMessage inboundMessage = (InboundMessage) message;
123122
TransportLogger.logInboundMessage(channel, inboundMessage);
124123
if (inboundMessage.isPing()) {
125124
keepAlive.receiveKeepAlive(channel);
@@ -130,7 +129,7 @@ public void messageReceived(
130129

131130
private void handleMessage(
132131
TcpChannel channel,
133-
NativeInboundMessage message,
132+
InboundMessage message,
134133
long startTime,
135134
long slowLogThresholdMs,
136135
TransportMessageListener messageListener
@@ -202,7 +201,7 @@ private Map<String, Collection<String>> extractHeaders(Map<String, String> heade
202201
private <T extends TransportRequest> void handleRequest(
203202
TcpChannel channel,
204203
Header header,
205-
NativeInboundMessage message,
204+
InboundMessage message,
206205
TransportMessageListener messageListener
207206
) throws IOException {
208207
final String action = header.getActionName();

server/src/main/java/org/opensearch/transport/TcpTransport.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,18 @@ protected void serverAcceptedChannel(TcpChannel channel) {
777777
*/
778778
protected abstract void stopInternal();
779779

780+
/**
781+
* @deprecated use {@link #inboundMessage(TcpChannel, ProtocolInboundMessage)}
782+
* Handles inbound message that has been decoded.
783+
*
784+
* @param channel the channel the message is from
785+
* @param message the message
786+
*/
787+
@Deprecated(since = "2.14.0", forRemoval = true)
788+
public void inboundMessage(TcpChannel channel, InboundMessage message) {
789+
inboundMessage(channel, (ProtocolInboundMessage) message);
790+
}
791+
780792
/**
781793
* Handles inbound message that has been decoded.
782794
*

server/src/main/java/org/opensearch/transport/TransportLogger.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.opensearch.core.common.io.stream.InputStreamStreamInput;
4141
import org.opensearch.core.common.io.stream.StreamInput;
4242
import org.opensearch.core.compress.CompressorRegistry;
43-
import org.opensearch.transport.nativeprotocol.NativeInboundMessage;
4443

4544
import java.io.IOException;
4645

@@ -65,7 +64,7 @@ static void logInboundMessage(TcpChannel channel, BytesReference message) {
6564
}
6665
}
6766

68-
static void logInboundMessage(TcpChannel channel, NativeInboundMessage message) {
67+
static void logInboundMessage(TcpChannel channel, InboundMessage message) {
6968
if (logger.isTraceEnabled()) {
7069
try {
7170
String logMessage = format(channel, message, "READ");
@@ -137,7 +136,7 @@ private static String format(TcpChannel channel, BytesReference message, String
137136
return sb.toString();
138137
}
139138

140-
private static String format(TcpChannel channel, NativeInboundMessage message, String event) throws IOException {
139+
private static String format(TcpChannel channel, InboundMessage message, String event) throws IOException {
141140
final StringBuilder sb = new StringBuilder();
142141
sb.append(channel);
143142

server/src/main/java/org/opensearch/transport/nativeprotocol/NativeInboundBytesHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.opensearch.transport.InboundAggregator;
1717
import org.opensearch.transport.InboundBytesHandler;
1818
import org.opensearch.transport.InboundDecoder;
19+
import org.opensearch.transport.InboundMessage;
1920
import org.opensearch.transport.ProtocolInboundMessage;
2021
import org.opensearch.transport.StatsTracker;
2122
import org.opensearch.transport.TcpChannel;
@@ -31,7 +32,7 @@
3132
public class NativeInboundBytesHandler implements InboundBytesHandler {
3233

3334
private static final ThreadLocal<ArrayList<Object>> fragmentList = ThreadLocal.withInitial(ArrayList::new);
34-
private static final NativeInboundMessage PING_MESSAGE = new NativeInboundMessage(null, true);
35+
private static final InboundMessage PING_MESSAGE = new InboundMessage(null, true);
3536

3637
private final ArrayDeque<ReleasableBytesReference> pending;
3738
private final InboundDecoder decoder;
@@ -151,7 +152,7 @@ private void forwardFragments(
151152
messageHandler.accept(channel, PING_MESSAGE);
152153
} else if (fragment == InboundDecoder.END_CONTENT) {
153154
assert aggregator.isAggregating();
154-
try (NativeInboundMessage aggregated = aggregator.finishAggregation()) {
155+
try (InboundMessage aggregated = aggregator.finishAggregation()) {
155156
statsTracker.markMessageReceived();
156157
messageHandler.accept(channel, aggregated);
157158
}

server/src/test/java/org/opensearch/transport/InboundAggregatorTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.opensearch.core.common.breaker.CircuitBreakingException;
4343
import org.opensearch.core.common.bytes.BytesArray;
4444
import org.opensearch.test.OpenSearchTestCase;
45-
import org.opensearch.transport.nativeprotocol.NativeInboundMessage;
4645
import org.junit.Before;
4746

4847
import java.io.IOException;
@@ -108,7 +107,7 @@ public void testInboundAggregation() throws IOException {
108107
}
109108

110109
// Signal EOS
111-
NativeInboundMessage aggregated = aggregator.finishAggregation();
110+
InboundMessage aggregated = aggregator.finishAggregation();
112111

113112
assertThat(aggregated, notNullValue());
114113
assertFalse(aggregated.isPing());
@@ -139,7 +138,7 @@ public void testInboundUnknownAction() throws IOException {
139138
assertEquals(0, content.refCount());
140139

141140
// Signal EOS
142-
NativeInboundMessage aggregated = aggregator.finishAggregation();
141+
InboundMessage aggregated = aggregator.finishAggregation();
143142

144143
assertThat(aggregated, notNullValue());
145144
assertTrue(aggregated.isShortCircuit());
@@ -162,7 +161,7 @@ public void testCircuitBreak() throws IOException {
162161
content1.close();
163162

164163
// Signal EOS
165-
NativeInboundMessage aggregated1 = aggregator.finishAggregation();
164+
InboundMessage aggregated1 = aggregator.finishAggregation();
166165

167166
assertEquals(0, content1.refCount());
168167
assertThat(aggregated1, notNullValue());
@@ -181,7 +180,7 @@ public void testCircuitBreak() throws IOException {
181180
content2.close();
182181

183182
// Signal EOS
184-
NativeInboundMessage aggregated2 = aggregator.finishAggregation();
183+
InboundMessage aggregated2 = aggregator.finishAggregation();
185184

186185
assertEquals(1, content2.refCount());
187186
assertThat(aggregated2, notNullValue());
@@ -200,7 +199,7 @@ public void testCircuitBreak() throws IOException {
200199
content3.close();
201200

202201
// Signal EOS
203-
NativeInboundMessage aggregated3 = aggregator.finishAggregation();
202+
InboundMessage aggregated3 = aggregator.finishAggregation();
204203

205204
assertEquals(1, content3.refCount());
206205
assertThat(aggregated3, notNullValue());
@@ -264,7 +263,7 @@ public void testFinishAggregationWillFinishHeader() throws IOException {
264263
content.close();
265264

266265
// Signal EOS
267-
NativeInboundMessage aggregated = aggregator.finishAggregation();
266+
InboundMessage aggregated = aggregator.finishAggregation();
268267

269268
assertThat(aggregated, notNullValue());
270269
assertFalse(header.needsToReadVariableHeader());

0 commit comments

Comments
 (0)