diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java index ebac921c9..a12f8f21d 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java @@ -18,6 +18,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.InetAddress; import java.net.Socket; +import java.net.SocketException; import java.util.Arrays; import java.util.Optional; @@ -134,6 +135,8 @@ public class BeaconClient implements AutoCloseable { try { var in = socket.getInputStream(); read = JacksonHelper.newMapper().disable(JsonParser.Feature.AUTO_CLOSE_SOURCE).readTree(in); + } catch (SocketException ex) { + throw new ConnectorException("Connection to xpipe daemon closed unexpectedly"); } catch (IOException ex) { throw new ConnectorException("Couldn't read from socket", ex); } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/PreStoreExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/PreStoreExchange.java new file mode 100644 index 000000000..6a4d43716 --- /dev/null +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/PreStoreExchange.java @@ -0,0 +1,41 @@ +package io.xpipe.beacon.exchange; + +import io.xpipe.beacon.message.RequestMessage; +import io.xpipe.beacon.message.ResponseMessage; +import io.xpipe.core.store.LocalFileDataStore; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +import java.nio.file.Path; + +public class PreStoreExchange implements MessageExchange { + + @Override + public String getId() { + return "preStore"; + } + + @Override + public Class getRequestClass() { + return PreStoreExchange.Request.class; + } + + @Override + public Class getResponseClass() { + return PreStoreExchange.Response.class; + } + + @Jacksonized + @Builder + @Value + public static class Request implements RequestMessage { + } + + @Jacksonized + @Builder + @Value + public static class Response implements ResponseMessage { + LocalFileDataStore store; + } +} diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/ReadPreparationExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/ReadPreparationExchange.java index 4390125eb..52eb59e14 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/ReadPreparationExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/ReadPreparationExchange.java @@ -3,8 +3,9 @@ package io.xpipe.beacon.exchange; import io.xpipe.beacon.message.RequestMessage; import io.xpipe.beacon.message.ResponseMessage; import io.xpipe.core.source.DataSourceConfigInstance; -import io.xpipe.core.store.DataStore; +import io.xpipe.core.store.StreamDataStore; import lombok.Builder; +import lombok.NonNull; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -30,6 +31,7 @@ public class ReadPreparationExchange implements MessageExchange toConfigOptions(DataSourceDescriptor desc); Map> getConverters(); + + List getPossibleNames(); } boolean supportsStore(DataStore store); @@ -84,6 +87,8 @@ public interface DataSourceProvider { String getId(); + DataSourceDescriptor createDefaultDescriptor(); + /** * Attempt to create a useful data source descriptor from a data store. * The result does not need to be always right, it should only reflect the best effort. diff --git a/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java b/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java index 8de456c58..fbc3cd824 100644 --- a/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java +++ b/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java @@ -50,6 +50,15 @@ public class DataSourceProviders { return ALL.stream().filter(d -> d.getId().equals(name)).findAny(); } + public static Optional byName(String name) { + if (ALL == null) { + throw new IllegalStateException("Not initialized"); + } + + return ALL.stream().filter(d -> d.getCliProvider() != null && d.getCliProvider().getPossibleNames().stream() + .anyMatch(s -> s.equalsIgnoreCase(name))).findAny(); + } + public static Optional byStore(DataStore store) { if (ALL == null) { throw new IllegalStateException("Not initialized");