Class JsWidget
- All Implemented Interfaces:
ServerObject
,WidgetMessageDetails
Most custom object types result in a single response being sent to the client, often with other exported objects, but
some will have streamed responses, and allow the client to send follow-up requests of its own. This class's API is
backwards compatible, but as such does not offer a way to tell the difference between a streaming or non-streaming
object type, the client code that handles the payloads is expected to know what to expect. See
WidgetMessageDetails
for more information.
When the promise that returns this object resolves, it will have the first response assigned to its fields. Later responses from the server will be emitted as "message" events. When the connection with the server ends, the "close" event will be emitted. In this way, the connection will behave roughly in the same way as a WebSocket - either side can close, and after close no more messages will be processed. There can be some latency in closing locally while remote messages are still pending - it is up to implementations of plugins to handle this case.
Also like WebSockets, the plugin API doesn't define how to serialize messages, and just handles any binary payloads.
What it does handle however, is allowing those messages to include references to server-side objects with those
payloads. Those server side objects might be tables or other built-in types in the Deephaven JS API, or could be
objects usable through their own plugins. They also might have no plugin at all, allowing the client to hold a
reference to them and pass them back to the server, either to the current plugin instance, or through another API.
The Widget
type does not specify how those objects should be used or their lifecycle, but leaves that
entirely to the plugin. Messages will arrive in the order they were sent.
This can suggest several patterns for how plugins operate:
- The plugin merely exists to transport some other object to the client. This can be useful for objects which can
easily be translated to some other type (like a Table) when the user clicks on it. An example of this is
pandas.DataFrame
will result in a widget that only contains a staticJsTable
. Presently, the widget is immediately closed, and only the Table is provided to the JS API consumer. - The plugin provides references to Tables and other objects, and those objects can live longer than the object
which provided them. One concrete example of this could have been
JsPartitionedTable
when fetching constituent tables, but it was implemented before bidirectional plugins were implemented. Another example of this is plugins that serve as a "factory", giving the user access to table manipulation/creation methods not supported by gRPC or the JS API. - The plugin provides reference to Tables and other objects that only make sense within the context of the widget
instance, so when the widget goes away, those objects should be released as well. This is also an example of
JsPartitionedTable
, as the partitioned table tracks creation of new keys through an internal table instance.
- One object per message - the message clearly is about that object, no other details required.
- Objects indexed within their message - as each message comes with a list of objects, those objects can be
referenced within the payload by index. This is roughly how
JsFigure
behaves, where the figure descriptor schema includes an index for each created series, describing which table should be used, which columns should be mapped to each axis. - Objects indexed since widget creation - each message would append its objects to a list created when the widget was first made, and any new exports that arrive in a new message would be appended to that list. Then, subsequent messages can reference objects already sent. This imposes a limitation where the client cannot release any exports without the server somehow signaling that it will never reference that export again.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class io.deephaven.web.client.api.event.HasEventHandling
HasEventHandling.EventPair<T>
Nested classes/interfaces inherited from interface io.deephaven.web.client.api.ServerObject
ServerObject.Union
-
Field Summary
FieldsFields inherited from class io.deephaven.web.client.api.event.HasEventHandling
INTERNAL_EVENT_RELEASED
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Ends the client connection to the server.Returns the data from this message as a base64-encoded string.Returns the data from this message as a utf-8 string.elemental2.core.Uint8Array
Returns the data from this message as a Uint8Array.Returns an array of exported objects sent from the server.getType()
elemental2.promise.Promise<JsWidget>
refetch()
void
sendMessage
(JsWidget.MessageUnion msg, elemental2.core.JsArray<ServerObject.Union> references) Sends a string/bytes payload to the server, along with references to objects that exist on the server.Methods inherited from class io.deephaven.web.client.api.event.HasEventHandling
addEventListener, addEventListenerOneShot, addEventListenerOneShot, failureHandled, fireCriticalEvent, fireCriticalEvent, fireEvent, fireEvent, fireEvent, hasListener, hasListeners, isSuppress, logPrefix, nextEvent, removeEventListener, suppressEvents, unsuppressEvents
-
Field Details
-
EVENT_MESSAGE
- See Also:
-
EVENT_CLOSE
- See Also:
-
-
Constructor Details
-
JsWidget
-
-
Method Details
-
getConnection
- Specified by:
getConnection
in interfaceServerObject
-
close
@JsMethod public void close()Ends the client connection to the server. -
refetch
-
getTicket
-
getType
- Returns:
- the type of this widget
-
typedTicket
- Specified by:
typedTicket
in interfaceServerObject
-
getDataAsBase64
Description copied from interface:WidgetMessageDetails
Returns the data from this message as a base64-encoded string.- Specified by:
getDataAsBase64
in interfaceWidgetMessageDetails
-
getDataAsU8
@JsMethod public elemental2.core.Uint8Array getDataAsU8()Description copied from interface:WidgetMessageDetails
Returns the data from this message as a Uint8Array.- Specified by:
getDataAsU8
in interfaceWidgetMessageDetails
-
getDataAsString
Description copied from interface:WidgetMessageDetails
Returns the data from this message as a utf-8 string.- Specified by:
getDataAsString
in interfaceWidgetMessageDetails
-
getExportedObjects
Description copied from interface:WidgetMessageDetails
Returns an array of exported objects sent from the server. The plugin implementation is now responsible for these objects, and should close them when no longer needed.- Specified by:
getExportedObjects
in interfaceWidgetMessageDetails
- Returns:
- the exported objects sent in the initial message from the server. The client is responsible for closing them when finished using them.
-
sendMessage
@JsMethod public void sendMessage(JsWidget.MessageUnion msg, @JsOptional elemental2.core.JsArray<ServerObject.Union> references) Sends a string/bytes payload to the server, along with references to objects that exist on the server.- Parameters:
msg
- string/buffer/view instance that represents data to sendreferences
- an array of objects that can be safely sent to the server
-