diff --git a/java/build.gradle b/java/build.gradle index 696943d18e..37e04defaa 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -31,6 +31,12 @@ subprojects { } } +tasks.named('jar') { + manifest { + attributes('Automatic-Module-Name': 'glide') + } +} + dependencies { testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.9.2' } diff --git a/java/client/build.gradle b/java/client/build.gradle index 07962a8b02..04bbd62f5b 100644 --- a/java/client/build.gradle +++ b/java/client/build.gradle @@ -2,6 +2,7 @@ import java.nio.file.Paths plugins { id 'java-library' + //id 'org.gradlex.extra-java-module-info' } repositories { @@ -9,7 +10,7 @@ repositories { } dependencies { - implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.24.3' + implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.21.12' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' implementation group: 'io.netty', name: 'netty-handler', version: '4.1.100.Final' diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 2493fcc951..386ca2e047 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -1,12 +1,16 @@ /** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api; -import glide.api.models.exceptions.RedisException; +import static glide.ffi.resolvers.SocketListenerResolver.getSocket; + +import glide.api.models.configuration.BaseClientConfiguration; +import glide.connectors.handlers.CallbackDispatcher; +import glide.connectors.handlers.ChannelHandler; import glide.ffi.resolvers.RedisValueResolver; import glide.managers.BaseCommandResponseResolver; import glide.managers.CommandManager; import glide.managers.ConnectionManager; -import java.util.HashMap; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.BiFunction; import lombok.AllArgsConstructor; @@ -58,59 +62,6 @@ protected static CompletableFuture CreateClient( } } - /** - * Check for errors in the Response and return null Throws an error if an unexpected value is - * returned - * - * @return null if the response is empty - */ - protected static Void handleVoidResponse(Response response) { - Object value = handleObjectResponse(response); - if (value == null) { - return null; - } - throw new RedisException( - "Unexpected return type from Redis: got " - + value.getClass().getSimpleName() - + " expected null"); - } - - /** - * Extracts the response value from the Redis response and either throws an exception or returns - * the value as a String. - * - * @param response Redis protobuf message - * @return Response as a String - */ - protected static String handleStringResponse(Response response) { - Object value = handleObjectResponse(response); - if (value instanceof String) { - return (String) value; - } - throw new RedisException( - "Unexpected return type from Redis: got " - + value.getClass().getSimpleName() - + " expected String"); - } - - /** - * Extracts the response value from the Redis response and either throws an exception or returns - * the * value as a HashMap - * - * @param response Redis protobuf message - * @return Response as a String - */ - protected static HashMap handleMapResponse(Response response) { - Object value = handleObjectResponse(response); - if (value instanceof HashMap) { - return (HashMap) value; - } - throw new RedisException( - "Unexpected return type from Redis: got " - + value.getClass().getSimpleName() - + " expected HashMap"); - } - /** * Closes this resource, relinquishing any underlying resources. This method is invoked * automatically on objects managed by the try-with-resources statement. diff --git a/java/client/src/main/java/glide/api/RedisClient.java b/java/client/src/main/java/glide/api/RedisClient.java index a16da091c5..c39ebfb753 100644 --- a/java/client/src/main/java/glide/api/RedisClient.java +++ b/java/client/src/main/java/glide/api/RedisClient.java @@ -2,26 +2,17 @@ package glide.api; import glide.api.commands.BaseCommands; -import glide.api.commands.ConnectionCommands; -import glide.api.commands.GenericCommands; -import glide.api.commands.ServerCommands; -import glide.api.commands.StringCommands; -import glide.api.models.commands.InfoOptions; -import glide.api.models.commands.SetOptions; import glide.api.models.configuration.RedisClientConfiguration; import glide.managers.CommandManager; import glide.managers.ConnectionManager; import glide.managers.models.Command; -import java.util.List; -import java.util.Map; import java.util.concurrent.CompletableFuture; /** * Async (non-blocking) client for Redis in Standalone mode. Use {@link #CreateClient} to request a * client to Redis. */ -public class RedisClient extends BaseClient - implements BaseCommands, GenericCommands, ConnectionCommands, ServerCommands, StringCommands { +public class RedisClient extends BaseClient implements BaseCommands { protected RedisClient(ConnectionManager connectionManager, CommandManager commandManager) { super(connectionManager, commandManager); @@ -43,118 +34,4 @@ public CompletableFuture customCommand(String[] args) { Command.builder().requestType(Command.RequestType.CUSTOM_COMMAND).arguments(args).build(); return commandManager.submitNewCommand(command, this::handleObjectResponse); } - - /** - * Ping the Redis server. - * - * @see redis.io for details. - * @returns the String "PONG" - */ - @Override - public CompletableFuture ping() { - Command command = Command.builder().requestType(Command.RequestType.PING).build(); - return commandManager.submitNewCommand(command, BaseClient::handleStringResponse); - } - - /** - * Ping the Redis server. - * - * @see redis.io for details. - * @param msg - the ping argument that will be returned. - * @returns return a copy of the argument. - */ - @Override - public CompletableFuture ping(String msg) { - Command command = - Command.builder() - .requestType(Command.RequestType.PING) - .arguments(new String[] {msg}) - .build(); - return commandManager.submitNewCommand(command, BaseClient::handleStringResponse); - } - - /** - * Get information and statistics about the Redis server. DEFAULT option is assumed - * - * @see redis.io for details. - * @return CompletableFuture with the response - */ - @Override - public CompletableFuture info() { - Command command = Command.builder().requestType(Command.RequestType.INFO).build(); - return commandManager.submitNewCommand(command, BaseClient::handleMapResponse); - } - - /** - * Get information and statistics about the Redis server. - * - * @see redis.io for details. - * @param options - A list of InfoSection values specifying which sections of information to - * retrieve. When no parameter is provided, the default option is assumed. - * @return CompletableFuture with the response - */ - @Override - public CompletableFuture info(InfoOptions options) { - Command command = - Command.builder() - .requestType(Command.RequestType.INFO) - .arguments(options.toInfoOptions()) - .build(); - return commandManager.submitNewCommand(command, BaseClient::handleMapResponse); - } - - /** - * Get the value associated with the given key, or null if no such value exists. - * - * @see redis.io for details. - * @param key - The key to retrieve from the database. - * @return If `key` exists, returns the value of `key` as a string. Otherwise, return null - */ - @Override - public CompletableFuture get(String key) { - Command command = - Command.builder() - .requestType(Command.RequestType.GET_STRING) - .arguments(new String[] {key}) - .build(); - return commandManager.submitNewCommand(command, BaseClient::handleStringResponse); - } - - /** - * Set the given key with the given value. - * - * @see redis.io for details. - * @param key - The key to store. - * @param value - The value to store with the given key. - * @return null - */ - @Override - public CompletableFuture set(String key, String value) { - Command command = - Command.builder() - .requestType(Command.RequestType.SET_STRING) - .arguments(new String[] {key, value}) - .build(); - return commandManager.submitNewCommand(command, BaseClient::handleVoidResponse); - } - - /** - * Set the given key with the given value. Return value is dependent on the passed options. - * - * @see redis.io for details. - * @param key - The key to store. - * @param value - The value to store with the given key. - * @param options - The Set options - * @return string or null If value isn't set because of `onlyIfExists` or `onlyIfDoesNotExist` - * conditions, return null. If `returnOldValue` is set, return the old value as a string. - */ - @Override - public CompletableFuture set(String key, String value, SetOptions options) { - Command command = - Command.builder() - .requestType(Command.RequestType.SET_STRING) - .arguments(options.toSetOptions(List.of(key, value))) - .build(); - return commandManager.submitNewCommand(command, BaseClient::handleStringResponse); - } } diff --git a/java/examples/src/main/java/glide/examples/ExamplesApp.java b/java/examples/src/main/java/glide/examples/ExamplesApp.java index 687414384a..3ad2e1bdf9 100644 --- a/java/examples/src/main/java/glide/examples/ExamplesApp.java +++ b/java/examples/src/main/java/glide/examples/ExamplesApp.java @@ -55,18 +55,6 @@ private static void runGlideExamples() { try { RedisClient client = GlideClient.connectToGlide(settings); - System.out.println("Glide PING: " + client.ping().get()); - System.out.println("Glide PING(custom): " + client.ping("found you!").get()); - - // panic - // System.out.println("Glide INFO(): " + client.info().get()); - - System.out.println("Glide SET(myKey, myValue): " + client.set("myKey", "myValue").get()); - System.out.println("Glide GET(myKey): " + client.get("myKey").get()); - System.out.println("Glide SET(myKey, yourValue): " + client.set("myKey", "yourValue").get()); - System.out.println("Glide GET(myKey): " + client.get("myKey").get()); - System.out.println("Glide GET(invalid): " + client.get("invalid").get()); - Object customGetMyKey = client.customCommand(new String[] {"get", "myKey"}).get(); System.out.println("Glide CUSTOM_COMMAND(get, myKey): " + customGetMyKey);