-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding TransportMessage and TransportRequest classes with protobuf in…
…tegration Signed-off-by: Vacha Shah <[email protected]>
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
server/src/main/java/org/opensearch/transport/ProtobufTransportMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) {} | ||
} | ||
|
59 changes: 59 additions & 0 deletions
59
server/src/main/java/org/opensearch/transport/ProtobufTransportRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |