Skip to content

Commit

Permalink
Adding TransportMessage and TransportRequest classes with protobuf in…
Browse files Browse the repository at this point in the history
…tegration

Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah committed Apr 22, 2023
1 parent 46821ee commit f60609c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
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) {}
}

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);
}
}

0 comments on commit f60609c

Please sign in to comment.