Rework various parts

This commit is contained in:
Christopher Schnick 2022-01-19 11:01:04 +01:00
parent caafb9d850
commit fd4dcc0739
9 changed files with 113 additions and 4 deletions

View file

@ -18,6 +18,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
@ -134,6 +135,8 @@ public class BeaconClient implements AutoCloseable {
try { try {
var in = socket.getInputStream(); var in = socket.getInputStream();
read = JacksonHelper.newMapper().disable(JsonParser.Feature.AUTO_CLOSE_SOURCE).readTree(in); 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) { } catch (IOException ex) {
throw new ConnectorException("Couldn't read from socket", ex); throw new ConnectorException("Couldn't read from socket", ex);
} }

View file

@ -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<PreStoreExchange.Request, PreStoreExchange.Response> {
@Override
public String getId() {
return "preStore";
}
@Override
public Class<PreStoreExchange.Request> getRequestClass() {
return PreStoreExchange.Request.class;
}
@Override
public Class<PreStoreExchange.Response> 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;
}
}

View file

@ -3,8 +3,9 @@ package io.xpipe.beacon.exchange;
import io.xpipe.beacon.message.RequestMessage; import io.xpipe.beacon.message.RequestMessage;
import io.xpipe.beacon.message.ResponseMessage; import io.xpipe.beacon.message.ResponseMessage;
import io.xpipe.core.source.DataSourceConfigInstance; import io.xpipe.core.source.DataSourceConfigInstance;
import io.xpipe.core.store.DataStore; import io.xpipe.core.store.StreamDataStore;
import lombok.Builder; import lombok.Builder;
import lombok.NonNull;
import lombok.Value; import lombok.Value;
import lombok.extern.jackson.Jacksonized; import lombok.extern.jackson.Jacksonized;
@ -30,6 +31,7 @@ public class ReadPreparationExchange implements MessageExchange<ReadPreparationE
@Value @Value
public static class Request implements RequestMessage { public static class Request implements RequestMessage {
String providerType; String providerType;
@NonNull
String dataStore; String dataStore;
} }
@ -38,6 +40,6 @@ public class ReadPreparationExchange implements MessageExchange<ReadPreparationE
@Value @Value
public static class Response implements ResponseMessage { public static class Response implements ResponseMessage {
DataSourceConfigInstance config; DataSourceConfigInstance config;
DataStore dataStore; StreamDataStore dataStore;
} }
} }

View file

@ -33,7 +33,7 @@ public class WriteExecuteExchange implements MessageExchange<WriteExecuteExchang
public static class Request implements RequestMessage { public static class Request implements RequestMessage {
@NonNull @NonNull
DataSourceId sourceId; DataSourceId sourceId;
@NonNull
DataStore dataStore; DataStore dataStore;
@NonNull @NonNull
DataSourceConfigInstance config; DataSourceConfigInstance config;

View file

@ -41,7 +41,6 @@ public class WritePreparationExchange implements MessageExchange<WritePreparatio
@Builder @Builder
@Value @Value
public static class Response implements ResponseMessage { public static class Response implements ResponseMessage {
@NonNull
DataStore dataStore; DataStore dataStore;
@NonNull @NonNull

View file

@ -32,5 +32,6 @@ module io.xpipe.beacon {
ReadExecuteExchange, ReadExecuteExchange,
DialogExchange, DialogExchange,
InfoExchange, InfoExchange,
PreStoreExchange,
VersionExchange; VersionExchange;
} }

View file

@ -0,0 +1,49 @@
package io.xpipe.core.store;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class OutputStreamStore implements StreamDataStore {
private final OutputStream out;
public OutputStreamStore(OutputStream out) {
this.out = out;
}
@Override
public InputStream openInput() throws Exception {
throw new UnsupportedOperationException("No input available");
}
@Override
public OutputStream openOutput() throws Exception {
return new OutputStream() {
@Override
public void write(int b) throws IOException {
out.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
out.write(b, off, len);
}
@Override
public void write(byte[] b) throws IOException {
out.write(b);
}
@Override
public void flush() throws IOException {
out.flush();
}
};
}
@Override
public boolean exists() {
return true;
}
}

View file

@ -9,6 +9,7 @@ import io.xpipe.core.store.StreamDataStore;
import javafx.beans.property.Property; import javafx.beans.property.Property;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -72,6 +73,8 @@ public interface DataSourceProvider {
Map<String, String> toConfigOptions(DataSourceDescriptor<?> desc); Map<String, String> toConfigOptions(DataSourceDescriptor<?> desc);
Map<DataSourceConfig.Option, Function<String, ?>> getConverters(); Map<DataSourceConfig.Option, Function<String, ?>> getConverters();
List<String> getPossibleNames();
} }
boolean supportsStore(DataStore store); boolean supportsStore(DataStore store);
@ -84,6 +87,8 @@ public interface DataSourceProvider {
String getId(); String getId();
DataSourceDescriptor<?> createDefaultDescriptor();
/** /**
* Attempt to create a useful data source descriptor from a data store. * 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. * The result does not need to be always right, it should only reflect the best effort.

View file

@ -50,6 +50,15 @@ public class DataSourceProviders {
return ALL.stream().filter(d -> d.getId().equals(name)).findAny(); return ALL.stream().filter(d -> d.getId().equals(name)).findAny();
} }
public static Optional<DataSourceProvider> 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<DataSourceProvider> byStore(DataStore store) { public static Optional<DataSourceProvider> byStore(DataStore store) {
if (ALL == null) { if (ALL == null) {
throw new IllegalStateException("Not initialized"); throw new IllegalStateException("Not initialized");