Skip to content

Commit

Permalink
Revert "Managers"
Browse files Browse the repository at this point in the history
This reverts commit 337bcd7.
  • Loading branch information
acarbonetto committed Dec 22, 2023
1 parent 3c3c244 commit fcfa263
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 276 deletions.
3 changes: 0 additions & 3 deletions java/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,16 @@ tasks.register('cleanProtobuf') {
tasks.register('buildRustRelease', Exec) {
commandLine 'cargo', 'build', '--release'
workingDir project.rootDir
environment 'CARGO_TERM_COLOR', 'always'
}

tasks.register('buildRustReleaseStrip', Exec) {
commandLine 'cargo', 'build', '--release', '--strip'
workingDir project.rootDir
environment 'CARGO_TERM_COLOR', 'always'
}

tasks.register('buildRust', Exec) {
commandLine 'cargo', 'build'
workingDir project.rootDir
environment 'CARGO_TERM_COLOR', 'always'
}

tasks.register('buildWithRust') {
Expand Down
62 changes: 0 additions & 62 deletions java/client/src/main/java/babushka/managers/ClientState.java

This file was deleted.

89 changes: 12 additions & 77 deletions java/client/src/main/java/babushka/managers/CommandManager.java
Original file line number Diff line number Diff line change
@@ -1,88 +1,23 @@
package babushka.managers;

import babushka.connectors.handlers.ChannelHandler;
import babushka.ffi.resolvers.RedisValueResolver;
import babushka.models.RequestBuilder;
import java.util.List;
import babushka.api.commands.Command;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import redis_request.RedisRequestOuterClass.RequestType;
import java.util.function.Function;
import response.ResponseOuterClass.Response;

@RequiredArgsConstructor
public class CommandManager {

/** UDS connection representation. */
private final ChannelHandler channel;

/**
* Client state, which {@link CommandManager} can flick to closed if corresponding error received.
*/
private final ClientState.ClosableClientState clientState;

/**
* Async (non-blocking) get.<br>
* See <a href="https://redis.io/commands/get/">REDIS docs for GET</a>.
*
* @param key The key name
*/
public CompletableFuture<String> get(String key) {
return submitNewCommand(RequestType.GetString, List.of(key));
}

/**
* Async (non-blocking) set.<br>
* See <a href="https://redis.io/commands/set/">REDIS docs for SET</a>.
*
* @param key The key name
* @param value The value to set
*/
public CompletableFuture<String> set(String key, String value) {
return submitNewCommand(RequestType.SetString, List.of(key, value));
}

/**
* Build a command and submit it Netty to send.
*
* @param command Command type
* @param args Command arguments
* @return A result promise
*/
private CompletableFuture<String> submitNewCommand(RequestType command, List<String> args) {
if (!clientState.isConnected()) {
throw new IllegalStateException("Connection is not open");
}

// TODO this explicitly uses ForkJoin thread pool. May be we should use another one.
return CompletableFuture.supplyAsync(
() -> channel.write(RequestBuilder.prepareRedisRequest(command, args), true))
// TODO: is there a better way to execute this?
.thenComposeAsync(f -> f)
.thenApplyAsync(this::extractValueFromResponse);
}

/**
* Check response and extract data from it.
*
* @param response A response received from Babushka
* @return A String from the Redis RESP2 response, or Ok. Otherwise, returns null
* @param command
* @param responseHandler
* @return
*/
private String extractValueFromResponse(Response response) {
if (response.hasRequestError()) {
// TODO do we need to support different types of exceptions and distinguish them by type?
throw new RuntimeException(
String.format(
"%s: %s",
response.getRequestError().getType(), response.getRequestError().getMessage()));
} else if (response.hasClosingError()) {
CompletableFuture.runAsync(channel::close);
clientState.disconnect();
throw new RuntimeException("Connection closed: " + response.getClosingError());
} else if (response.hasConstantResponse()) {
return response.getConstantResponse().toString();
} else if (response.hasRespPointer()) {
return RedisValueResolver.valueFromPointer(response.getRespPointer()).toString();
}
return null;
public <T> CompletableFuture<T> submitNewCommand(
Command command, Function<Response, T> responseHandler) {
// register callback
// create protobuf message from command
// submit async call
// handle return type in the thenApplyAsync
return new CompletableFuture<>();
}
}
71 changes: 0 additions & 71 deletions java/client/src/main/java/babushka/managers/ConnectionManager.java

This file was deleted.

60 changes: 0 additions & 60 deletions java/client/src/main/java/babushka/models/RequestBuilder.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package glide.ffi.resolvers;

<<<<<<<< HEAD:java/client/src/main/java/glide/ffi/resolvers/GlideCoreNativeDefinitions.java
<<<<<<<< HEAD:java/client/src/main/java/glide/ffi/resolvers/GlideCoreNativeDefinitions.java
public class GlideCoreNativeDefinitions {
public static native String startSocketListenerExternal() throws Exception;
========
public class SocketListenerResolver {
>>>>>>>> 337bcd7 (Managers):java/client/src/main/java/glide/ffi/resolvers/SocketListenerResolver.java
========
public class BabushkaCoreNativeDefinitions {
public static native String startSocketListenerExternal() throws Exception;
>>>>>>>> 5d172a4 (Revert "Managers"):java/client/src/main/java/glide/ffi/resolvers/BabushkaCoreNativeDefinitions.java

/** Make an FFI call to Babushka to open a UDS socket to connect to. */
private static native String startSocketListener() throws Exception;
public static native Object valueFromPointer(long pointer);

static {
System.loadLibrary("glide-rs");
Expand All @@ -21,7 +25,7 @@ public class SocketListenerResolver {
*/
public static String getSocket() {
try {
return startSocketListener();
return startSocketListenerExternal();
} catch (Exception | UnsatisfiedLinkError e) {
System.err.printf("Failed to create a UDS connection: %s%n%n", e);
throw new RuntimeException(e);
Expand Down

0 comments on commit fcfa263

Please sign in to comment.