forked from deephaven/deephaven-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a GrpcApiApplication That Exposes a Blink Table of Export Stat…
…e Changes
- Loading branch information
1 parent
d3b2147
commit 666f9e4
Showing
23 changed files
with
337 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
80 changes: 80 additions & 0 deletions
80
server/src/main/java/io/deephaven/server/grpc_api_app/GrpcApiApplication.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,80 @@ | ||
package io.deephaven.server.grpc_api_app; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.deephaven.appmode.ApplicationState; | ||
import io.deephaven.engine.context.ExecutionContext; | ||
import io.deephaven.engine.table.Table; | ||
import io.deephaven.engine.table.impl.sources.ring.RingTableTools; | ||
import io.deephaven.engine.util.TableTools; | ||
import io.deephaven.proto.backplane.grpc.ExportNotification; | ||
import io.deephaven.server.session.SessionState; | ||
import io.deephaven.stream.StreamToBlinkTableAdapter; | ||
import io.grpc.stub.StreamObserver; | ||
|
||
/** | ||
* The {@value APP_NAME}, application id {@value APP_ID}, produces stream {@link io.deephaven.engine.table.Table tables} | ||
* {@value NOTIFICATION_INFO}; and derived table {@value NOTIFICATION_INFO_RING}. This data is modeled after the | ||
* {@link ExportNotification} event information from {@link SessionState#addExportListener(StreamObserver)}. | ||
* | ||
* @see #ENABLED | ||
* @see #RING_SIZE | ||
*/ | ||
@AutoService(ApplicationState.Factory.class) | ||
public final class GrpcApiApplication implements ApplicationState.Factory { | ||
private static final String APP_ID = "GRPC_API_APP"; | ||
private static final String APP_NAME = "GRPC API Application"; | ||
private static final String NOTIFICATION_INFO = "session_export_notification_info"; | ||
private static final String NOTIFICATION_INFO_RING = "session_export_notification_info_ring"; | ||
|
||
private static final String ENABLED = "enabled"; | ||
private static final String RING_SIZE = "ringSize"; | ||
|
||
private static Table updateStreamTable = TableTools.emptyTable(0); | ||
|
||
public static Table getExportObjectUpdateStreamTable() { | ||
return updateStreamTable; | ||
} | ||
|
||
/** | ||
* Looks up the system property {@value ENABLED}, defaults to {@code false}. | ||
* | ||
* @return if the gRPC API application is enabled | ||
*/ | ||
private static boolean enabled() { | ||
return "true".equals(System.getProperty(GrpcApiApplication.class + "." + ENABLED, "false")); | ||
} | ||
|
||
/** | ||
* Looks up the system property {@value RING_SIZE}, defaults to {@code 1024}. The | ||
* {@value NOTIFICATION_INFO_RING} table is disabled when {@code 0} or less. | ||
* | ||
* @return the {@value NOTIFICATION_INFO_RING} table size | ||
*/ | ||
private static int ringSize() { | ||
return Integer.getInteger(GrpcApiApplication.class + "." + RING_SIZE, 1024); | ||
} | ||
|
||
@Override | ||
public ApplicationState create(ApplicationState.Listener listener) { | ||
final ApplicationState state = new ApplicationState(listener, APP_ID, APP_NAME); | ||
if (!enabled()) { | ||
return state; | ||
} | ||
|
||
final SessionStateExportObjectUpdateStream updateStream = new SessionStateExportObjectUpdateStream(); | ||
SessionState.LISTENER = updateStream::onExportObjectStateUpdate; | ||
|
||
// noinspection resource | ||
final StreamToBlinkTableAdapter adapter = new StreamToBlinkTableAdapter( | ||
SessionStateExportObjectUpdateStream.definition(), updateStream, | ||
ExecutionContext.getContext().getUpdateGraph(), NOTIFICATION_INFO); | ||
updateStreamTable = adapter.table(); | ||
state.setField(NOTIFICATION_INFO, updateStreamTable); | ||
|
||
final int ringSize = ringSize(); | ||
if (ringSize > 0) { | ||
state.setField(NOTIFICATION_INFO_RING, RingTableTools.of(updateStreamTable, ringSize)); | ||
} | ||
return state; | ||
} | ||
} |
Oops, something went wrong.