use of io.deephaven.web.client.api.console.JsVariableDefinition in project deephaven-core by deephaven.
the class IdeSession method getObject.
public Promise<?> getObject(JsPropertyMap<Object> definitionObject) {
if (definitionObject instanceof JsVariableDefinition) {
return connection.getObject((JsVariableDefinition) definitionObject);
}
if (!definitionObject.has("type")) {
throw new IllegalArgumentException("no type field; could not getObject");
}
String type = definitionObject.getAsAny("type").asString();
boolean hasName = definitionObject.has("name");
boolean hasId = definitionObject.has("id");
if (hasName && hasId) {
throw new IllegalArgumentException("has both name and id field; could not getObject");
} else if (hasName) {
String name = definitionObject.getAsAny("name").asString();
return getVariableDefinition(name, type).then(connection::getObject);
} else if (hasId) {
String id = definitionObject.getAsAny("id").asString();
return connection.getObject(new JsVariableDefinition(type, null, id, null));
} else {
throw new IllegalArgumentException("no name/id field; could not construct getObject");
}
}
use of io.deephaven.web.client.api.console.JsVariableDefinition in project deephaven-core by deephaven.
the class WorkerConnection method getTable.
public Promise<JsTable> getTable(JsVariableDefinition varDef, @Nullable Boolean applyPreviewColumns) {
return whenServerReady("get a table").then(serve -> {
JsLog.debug("innerGetTable", varDef.getTitle(), " started");
return newState(info, (c, cts, metadata) -> {
JsLog.debug("performing fetch for ", varDef.getTitle(), " / ", cts, " (" + LazyString.of(cts::getHandle), ")");
// TODO (deephaven-core#188): eliminate this branch by applying preview cols before subscribing
if (applyPreviewColumns == null || applyPreviewColumns) {
ApplyPreviewColumnsRequest req = new ApplyPreviewColumnsRequest();
req.setSourceId(TableTicket.createTableRef(varDef));
req.setResultId(cts.getHandle().makeTicket());
tableServiceClient.applyPreviewColumns(req, metadata, c::apply);
} else {
FetchTableRequest req = new FetchTableRequest();
req.setSourceId(TableTicket.createTableRef(varDef));
req.setResultId(cts.getHandle().makeTicket());
tableServiceClient.fetchTable(req, metadata, c::apply);
}
}, "fetch table " + varDef.getTitle()).then(cts -> {
JsLog.debug("innerGetTable", varDef.getTitle(), " succeeded ", cts);
JsTable table = new JsTable(this, cts);
return Promise.resolve(table);
});
});
}
use of io.deephaven.web.client.api.console.JsVariableDefinition in project deephaven-core by deephaven.
the class JsWidgetExportedObject method fetch.
@JsMethod
public Promise<?> fetch() {
if (getType().equals(JsVariableChanges.TABLE)) {
return Callbacks.<ExportedTableCreationResponse, Object>grpcUnaryPromise(c -> {
connection.tableServiceClient().getExportedTableCreationResponse(ticket.getTicket(), connection.metadata(), c::apply);
}).then(etcr -> {
ClientTableState cts = connection.newStateFromUnsolicitedTable(etcr, "table for widget");
JsTable table = new JsTable(connection, cts);
// never attempt a reconnect, since we might have a different widget schema entirely
table.addEventListener(JsTable.EVENT_DISCONNECT, ignore -> table.close());
return Promise.resolve(table);
});
} else {
return this.connection.getObject(new JsVariableDefinition(ticket.getType(), null, ticket.getTicket().getTicket_asB64(), null));
}
}
use of io.deephaven.web.client.api.console.JsVariableDefinition in project deephaven-core by deephaven.
the class WorkerConnection method subscribeToFieldUpdates.
@JsMethod
@SuppressWarnings("ConstantConditions")
public JsRunnable subscribeToFieldUpdates(JsConsumer<JsVariableChanges> callback) {
fieldUpdatesCallback.add(callback);
if (fieldUpdatesCallback.size == 1) {
fieldsChangeUpdateStream = ResponseStreamWrapper.of(applicationServiceClient.listFields(new ListFieldsRequest(), metadata));
fieldsChangeUpdateStream.onData(data -> {
final JsVariableDefinition[] created = new JsVariableDefinition[0];
final JsVariableDefinition[] updated = new JsVariableDefinition[0];
final JsVariableDefinition[] removed = new JsVariableDefinition[0];
JsArray<FieldInfo> removedFI = data.getRemovedList();
for (int i = 0; i < removedFI.length; ++i) {
String removedId = removedFI.getAt(i).getTypedTicket().getTicket().getTicket_asB64();
JsVariableDefinition result = knownFields.get(removedId);
removed[removed.length] = result;
knownFields.remove(removedId);
}
JsArray<FieldInfo> createdFI = data.getCreatedList();
for (int i = 0; i < createdFI.length; ++i) {
JsVariableDefinition result = new JsVariableDefinition(createdFI.getAt(i));
created[created.length] = result;
knownFields.put(result.getId(), result);
}
JsArray<FieldInfo> updatedFI = data.getUpdatedList();
for (int i = 0; i < updatedFI.length; ++i) {
JsVariableDefinition result = new JsVariableDefinition(updatedFI.getAt(i));
updated[updated.length] = result;
knownFields.put(result.getId(), result);
}
// Ensure that if a new subscription is in line to receive its initial update, we need to defer
// the updates until after it receives its initial state.
LazyPromise.runLater(() -> notifyFieldsChangeListeners(new JsVariableChanges(created, updated, removed)));
});
fieldsChangeUpdateStream.onEnd(this::checkStatus);
} else {
final JsVariableDefinition[] empty = new JsVariableDefinition[0];
final JsVariableChanges update = new JsVariableChanges(knownFields.values().toArray(empty), empty, empty);
LazyPromise.runLater(() -> {
callback.apply(update);
});
}
return () -> {
fieldUpdatesCallback.delete(callback);
if (fieldUpdatesCallback.size == 0) {
knownFields.clear();
if (fieldsChangeUpdateStream != null) {
fieldsChangeUpdateStream.cancel();
fieldsChangeUpdateStream = null;
}
}
};
}
use of io.deephaven.web.client.api.console.JsVariableDefinition in project deephaven-core by deephaven.
the class IdeSession method getVariableDefinition.
private Promise<JsVariableDefinition> getVariableDefinition(String name, String type) {
LazyPromise<JsVariableDefinition> promise = new LazyPromise<>();
final class Listener implements Consumer<JsVariableChanges> {
final JsRunnable subscription;
Listener() {
subscription = subscribeToFieldUpdates(this::accept);
}
@Override
public void accept(JsVariableChanges changes) {
JsVariableDefinition foundField = changes.getCreated().find((field, p1, p2) -> field.getTitle().equals(name) && field.getType().equals(type));
if (foundField == null) {
foundField = changes.getUpdated().find((field, p1, p2) -> field.getTitle().equals(name) && field.getType().equals(type));
}
if (foundField != null) {
subscription.run();
promise.succeed(foundField);
}
}
}
Listener listener = new Listener();
return promise.timeout(10_000).asPromise().then(Promise::resolve, fail -> {
listener.subscription.run();
// noinspection unchecked, rawtypes
return (Promise<JsVariableDefinition>) (Promise) Promise.reject(fail);
});
}
Aggregations