mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-28 11:25:37 +00:00
Rework beacon exchanges
This commit is contained in:
@@ -44,11 +44,13 @@ public class BeaconClient implements AutoCloseable {
|
||||
void accept(T var1) throws E;
|
||||
}
|
||||
|
||||
public static Optional<BeaconClient> tryConnect() {
|
||||
if (BeaconConfig.debugEnabled()) {
|
||||
System.out.println("Attempting connection to server at port " + BeaconConfig.getUsedPort());
|
||||
}
|
||||
@FunctionalInterface
|
||||
public interface FailableRunnable<E extends Throwable> {
|
||||
|
||||
void run() throws E;
|
||||
}
|
||||
|
||||
public static Optional<BeaconClient> tryConnect() {
|
||||
try {
|
||||
return Optional.of(new BeaconClient());
|
||||
} catch (IOException ex) {
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
package io.xpipe.beacon;
|
||||
|
||||
import io.xpipe.beacon.message.ResponseMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface BeaconHandler {
|
||||
|
||||
void postResponse(BeaconClient.FailableRunnable<Exception> r);
|
||||
|
||||
void prepareBody() throws IOException;
|
||||
|
||||
InputStream startBodyRead() throws IOException;
|
||||
|
||||
public <T extends ResponseMessage> void sendResponse(T obj) throws Exception;
|
||||
|
||||
public void sendClientErrorResponse(String message) throws Exception;
|
||||
|
||||
public void sendServerErrorResponse(Throwable ex) throws Exception;
|
||||
|
||||
OutputStream getOutputStream() throws Exception;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class BeaconServer {
|
||||
public static boolean tryStart() throws Exception {
|
||||
var custom = BeaconConfig.getCustomExecCommand();
|
||||
if (custom != null) {
|
||||
new ProcessBuilder("cmd", "/c", "CALL", custom).inheritIO().start();
|
||||
Runtime.getRuntime().exec(custom);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@ 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.source.DataSourceId;
|
||||
import io.xpipe.core.source.DataSourceInfo;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
import io.xpipe.core.store.DataStore;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
@@ -31,15 +32,19 @@ public class InfoExchange implements MessageExchange<InfoExchange.Request, InfoE
|
||||
@Builder
|
||||
@Value
|
||||
public static class Request implements RequestMessage {
|
||||
DataSourceId id;
|
||||
@NonNull
|
||||
DataSourceReference ref;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Response implements ResponseMessage {
|
||||
@NonNull
|
||||
DataSourceInfo info;
|
||||
@NonNull
|
||||
DataStore store;
|
||||
@NonNull
|
||||
DataSourceConfigInstance config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.source.DataSourceId;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
import io.xpipe.core.store.DataStore;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
@@ -36,7 +36,7 @@ public class ReadExecuteExchange implements MessageExchange<ReadExecuteExchange.
|
||||
@NonNull
|
||||
DataSourceConfigInstance config;
|
||||
@NonNull
|
||||
DataSourceId targetId;
|
||||
DataSourceReference target;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
|
||||
@@ -2,8 +2,9 @@ package io.xpipe.beacon.exchange;
|
||||
|
||||
import io.xpipe.beacon.message.RequestMessage;
|
||||
import io.xpipe.beacon.message.ResponseMessage;
|
||||
import io.xpipe.core.source.DataSourceId;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
@@ -28,7 +29,8 @@ public class SelectExchange implements MessageExchange<SelectExchange.Request, S
|
||||
@Builder
|
||||
@Value
|
||||
public static class Request implements RequestMessage {
|
||||
DataSourceId id;
|
||||
@NonNull
|
||||
DataSourceReference ref;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.source.DataSourceId;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
import io.xpipe.core.store.DataStore;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
@@ -32,7 +32,7 @@ public class WriteExecuteExchange implements MessageExchange<WriteExecuteExchang
|
||||
@Value
|
||||
public static class Request implements RequestMessage {
|
||||
@NonNull
|
||||
DataSourceId sourceId;
|
||||
DataSourceReference ref;
|
||||
|
||||
DataStore dataStore;
|
||||
@NonNull
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.source.DataSourceId;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
import io.xpipe.core.store.DataStore;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
@@ -34,7 +34,7 @@ public class WritePreparationExchange implements MessageExchange<WritePreparatio
|
||||
String providerType;
|
||||
String output;
|
||||
@NonNull
|
||||
DataSourceId sourceId;
|
||||
DataSourceReference ref;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package io.xpipe.beacon.message;
|
||||
|
||||
import io.xpipe.beacon.BeaconHandler;
|
||||
|
||||
public interface ResponseMessage {
|
||||
|
||||
default void postSend(BeaconHandler handler) throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user