diff --git a/server/src/main/java/org/opensearch/transport/ProtobufTransportMessage.java b/server/src/main/java/org/opensearch/transport/ProtobufTransportMessage.java new file mode 100644 index 0000000000000..0bca490774ec4 --- /dev/null +++ b/server/src/main/java/org/opensearch/transport/ProtobufTransportMessage.java @@ -0,0 +1,43 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.transport; + +import com.google.protobuf.CodedInputStream; +import org.opensearch.common.io.stream.ProtobufWriteable; +import org.opensearch.common.transport.TransportAddress; + +/** + * Message over the transport interface with Protobuf serialization. +* +* @opensearch.internal +*/ +public abstract class ProtobufTransportMessage implements ProtobufWriteable { + + private TransportAddress remoteAddress; + + public void remoteAddress(TransportAddress remoteAddress) { + this.remoteAddress = remoteAddress; + } + + public TransportAddress remoteAddress() { + return remoteAddress; + } + + /** + * Constructs a new empty transport message + */ + public ProtobufTransportMessage() {} + + /** + * Constructs a new transport message with the data from the {@link CodedInputStream}. This is + * currently a no-op + */ + public ProtobufTransportMessage(com.google.protobuf.CodedInputStream in) {} +} + \ No newline at end of file diff --git a/server/src/main/java/org/opensearch/transport/ProtobufTransportRequest.java b/server/src/main/java/org/opensearch/transport/ProtobufTransportRequest.java new file mode 100644 index 0000000000000..ec78e3cdb2bf1 --- /dev/null +++ b/server/src/main/java/org/opensearch/transport/ProtobufTransportRequest.java @@ -0,0 +1,59 @@ +/* +* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +package org.opensearch.transport; + +import com.google.protobuf.CodedInputStream; +import com.google.protobuf.CodedOutputStream; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.tasks.ProtobufTaskId; +import org.opensearch.tasks.ProtobufTaskAwareRequest; +import org.opensearch.tasks.TaskId; + +import java.io.IOException; + +/** + * A transport request with Protobuf serialization. +* +* @opensearch.internal +*/ +public abstract class ProtobufTransportRequest extends ProtobufTransportMessage implements ProtobufTaskAwareRequest { + + /** + * Parent of this request. Defaults to {@link TaskId#EMPTY_TASK_ID}, meaning "no parent". + */ + private ProtobufTaskId parentTaskId = ProtobufTaskId.EMPTY_TASK_ID; + + public ProtobufTransportRequest() {} + + public ProtobufTransportRequest(com.google.protobuf.CodedInputStream in) throws IOException { + parentTaskId = ProtobufTaskId.readFromStream(in); + } + + /** + * Set a reference to task that created this request. + */ + @Override + public void setParentTask(ProtobufTaskId taskId) { + this.parentTaskId = taskId; + } + + /** + * Get a reference to the task that created this request. Defaults to {@link TaskId#EMPTY_TASK_ID}, meaning "there is no parent". + */ + @Override + public ProtobufTaskId getParentTask() { + return parentTaskId; + } + + @Override + public void writeTo(com.google.protobuf.CodedOutputStream out) throws IOException { + parentTaskId.writeTo(out); + } +}