From fd4dcc0739f5f7c0ec93aba6349716c9b7adcc11 Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Wed, 19 Jan 2022 11:01:04 +0100 Subject: [PATCH] Rework various parts --- .../java/io/xpipe/beacon/BeaconClient.java | 3 ++ .../beacon/exchange/PreStoreExchange.java | 41 ++++++++++++++++ .../exchange/ReadPreparationExchange.java | 6 ++- .../beacon/exchange/WriteExecuteExchange.java | 2 +- .../exchange/WritePreparationExchange.java | 1 - beacon/src/main/java/module-info.java | 1 + .../xpipe/core/store/OutputStreamStore.java | 49 +++++++++++++++++++ .../xpipe/extension/DataSourceProvider.java | 5 ++ .../xpipe/extension/DataSourceProviders.java | 9 ++++ 9 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 beacon/src/main/java/io/xpipe/beacon/exchange/PreStoreExchange.java create mode 100644 core/src/main/java/io/xpipe/core/store/OutputStreamStore.java diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java index ebac921c..a12f8f21 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 00000000..6a4d4371 --- /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 4390125e..52eb59e1 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 8de456c5..fbc3cd82 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");