Skip to content

Commit

Permalink
introduce factory for stream ticket
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Maurya <[email protected]>
  • Loading branch information
rishabhmaurya committed Nov 26, 2024
1 parent e472e7e commit 49b701e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ public interface StreamManager extends AutoCloseable {
* @throws IllegalStateException if the stream has been cancelled or closed
*/
StreamReader getStreamReader(StreamTicket ticket);

/**
* Gets the StreamTicketFactory instance associated with this StreamManager.
*
* @return the StreamTicketFactory instance
*/
StreamTicketFactory getStreamTicketFactory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,13 @@ public interface StreamProducer extends Closeable {
*
* @return Estimated number of rows, or -1 if unknown
*/
default int estimatedRowCount() {
return -1;
}
int estimatedRowCount();

/**
* Task action name
* @return action name
*/
default String getAction() {
return "";
}
String getAction();

/**
* BatchedJob interface for producing stream data in batches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,4 @@ public interface StreamTicket {
* @return Base64 encoded byte array containing the ticket information
*/
byte[] toBytes();

/**
* Creates a StreamTicket from its serialized byte representation.
*
* @param bytes Base64 encoded byte array containing ticket information
* @return a new StreamTicket instance
* @throws IllegalArgumentException if the input is invalid
*/
static StreamTicket fromBytes(byte[] bytes) {
throw new UnsupportedOperationException("Implementation must be provided by concrete class");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.arrow.spi;

import org.opensearch.common.annotation.ExperimentalApi;

/**
* Factory interface for creating and managing StreamTicket instances.
* This factory provides methods to create and deserialize StreamTickets,
* ensuring consistent ticket creation.
*/
@ExperimentalApi
public interface StreamTicketFactory {
/**
* Generates a new StreamTicket
*
* @return A new StreamTicket instance
*/
StreamTicket generateTicket();

/**
* Deserializes a StreamTicket from its byte representation.
*
* @param bytes The byte array containing the serialized ticket data
* @return A StreamTicket instance reconstructed from the byte array
* @throws IllegalArgumentException if bytes is null or invalid
*/
StreamTicket fromBytes(byte[] bytes);
}

0 comments on commit 49b701e

Please sign in to comment.