mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-22 23:49:09 -04:00
Implement various fixes for sink drains
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package io.xpipe.beacon.exchange;
|
||||
|
||||
import io.xpipe.beacon.RequestMessage;
|
||||
import io.xpipe.beacon.ResponseMessage;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
/**
|
||||
* Stores a stream of data in a storage.
|
||||
*/
|
||||
public class ReadStreamExchange implements MessageExchange {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "readStream";
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Request implements RequestMessage {
|
||||
@NonNull String name;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Response implements ResponseMessage {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.xpipe.beacon.exchange;
|
||||
|
||||
import io.xpipe.beacon.RequestMessage;
|
||||
import io.xpipe.beacon.ResponseMessage;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
/**
|
||||
* Stores a stream of data in a storage.
|
||||
*/
|
||||
public class WriteStreamExchange implements MessageExchange {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "writeStream";
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Request implements RequestMessage {
|
||||
@NonNull String name;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Response implements ResponseMessage {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package io.xpipe.beacon.util;
|
||||
|
||||
import io.xpipe.beacon.BeaconConnection;
|
||||
import io.xpipe.beacon.ClientException;
|
||||
import io.xpipe.beacon.exchange.cli.DialogExchange;
|
||||
import io.xpipe.core.dialog.BaseQueryElement;
|
||||
import io.xpipe.core.dialog.ChoiceElement;
|
||||
import io.xpipe.core.dialog.DialogElement;
|
||||
import io.xpipe.core.dialog.DialogReference;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class QuietDialogHandler {
|
||||
|
||||
public static void handle(DialogReference ref, BeaconConnection connection) throws ClientException {
|
||||
new QuietDialogHandler(ref, connection, Map.of()).handle();
|
||||
}
|
||||
|
||||
private final UUID dialogKey;
|
||||
private final BeaconConnection connection;
|
||||
private final Map<String, String> overrides;
|
||||
private DialogElement element;
|
||||
|
||||
public QuietDialogHandler(DialogReference ref, BeaconConnection connection, Map<String, String> overrides) {
|
||||
this.dialogKey = ref.getDialogId();
|
||||
this.element = ref.getStart();
|
||||
this.connection = connection;
|
||||
this.overrides = overrides;
|
||||
}
|
||||
|
||||
public void handle() throws ClientException {
|
||||
String response = null;
|
||||
|
||||
if (element instanceof ChoiceElement c) {
|
||||
response = handleChoice(c);
|
||||
}
|
||||
|
||||
if (element instanceof BaseQueryElement q) {
|
||||
response = handleQuery(q);
|
||||
}
|
||||
|
||||
DialogExchange.Response res = connection.performSimpleExchange(DialogExchange.Request.builder()
|
||||
.dialogKey(dialogKey)
|
||||
.value(response)
|
||||
.build());
|
||||
if (res.getElement() != null && element.equals(res.getElement())) {
|
||||
throw new ClientException(
|
||||
"Invalid value for key " + res.getElement().toDisplayString());
|
||||
}
|
||||
|
||||
element = res.getElement();
|
||||
|
||||
if (element != null) {
|
||||
handle();
|
||||
}
|
||||
}
|
||||
|
||||
private String handleQuery(BaseQueryElement q) {
|
||||
if (q.isRequired() && !overrides.containsKey(q.getDescription())) {
|
||||
throw new IllegalStateException("Missing required config parameter: " + q.getDescription());
|
||||
}
|
||||
|
||||
return overrides.get(q.getDescription());
|
||||
}
|
||||
|
||||
private String handleChoice(ChoiceElement c) {
|
||||
if (c.isRequired() && !overrides.containsKey(c.getDescription())) {
|
||||
throw new IllegalStateException("Missing required config parameter: " + c.getDescription());
|
||||
}
|
||||
|
||||
return overrides.get(c.getDescription());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import io.xpipe.beacon.BeaconJacksonModule;
|
||||
import io.xpipe.beacon.BeaconProxyImpl;
|
||||
import io.xpipe.core.util.ProxyFunction;
|
||||
import io.xpipe.beacon.exchange.*;
|
||||
import io.xpipe.beacon.exchange.api.QueryRawDataExchange;
|
||||
import io.xpipe.beacon.exchange.api.QueryTableDataExchange;
|
||||
import io.xpipe.beacon.exchange.api.QueryTextDataExchange;
|
||||
import io.xpipe.beacon.exchange.cli.*;
|
||||
import io.xpipe.core.util.ProxyFunction;
|
||||
import io.xpipe.core.util.ProxyProvider;
|
||||
|
||||
module io.xpipe.beacon {
|
||||
@@ -21,6 +21,8 @@ module io.xpipe.beacon {
|
||||
opens io.xpipe.beacon.exchange.api;
|
||||
opens io.xpipe.beacon.exchange.data;
|
||||
opens io.xpipe.beacon.exchange.cli;
|
||||
exports io.xpipe.beacon.util;
|
||||
opens io.xpipe.beacon.util;
|
||||
|
||||
requires static com.fasterxml.jackson.core;
|
||||
requires static com.fasterxml.jackson.databind;
|
||||
@@ -37,6 +39,8 @@ module io.xpipe.beacon {
|
||||
InstanceExchange,
|
||||
EditStoreExchange,
|
||||
AddSourceExchange,
|
||||
WriteStreamExchange,
|
||||
ReadStreamExchange,
|
||||
StoreProviderListExchange,
|
||||
ListCollectionsExchange,
|
||||
ListEntriesExchange,
|
||||
|
||||
Reference in New Issue
Block a user