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.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);
}

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.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<ReadPreparationE
@Value
public static class Request implements RequestMessage {
String providerType;
@NonNull
String dataStore;
}
@ -38,6 +40,6 @@ public class ReadPreparationExchange implements MessageExchange<ReadPreparationE
@Value
public static class Response implements ResponseMessage {
DataSourceConfigInstance config;
DataStore dataStore;
StreamDataStore dataStore;
}
}

View file

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

View file

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

View file

@ -32,5 +32,6 @@ module io.xpipe.beacon {
ReadExecuteExchange,
DialogExchange,
InfoExchange,
PreStoreExchange,
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.scene.layout.Region;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
@ -72,6 +73,8 @@ public interface DataSourceProvider {
Map<String, String> toConfigOptions(DataSourceDescriptor<?> desc);
Map<DataSourceConfig.Option, Function<String, ?>> getConverters();
List<String> 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.

View file

@ -50,6 +50,15 @@ public class DataSourceProviders {
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) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");