Skip to content

Commit

Permalink
Support JPMS
Browse files Browse the repository at this point in the history
Motivation:

Support JPMS.

Changes:

- add a module info descriptor
- update to endpoint manager -> resource manager (from core)
- move test classes in a package that is not the main module package
  • Loading branch information
vietj committed Sep 9, 2024
1 parent 7e714e9 commit b45fc0b
Show file tree
Hide file tree
Showing 60 changed files with 189 additions and 140 deletions.
27 changes: 21 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-codegen</artifactId>
<artifactId>vertx-codegen-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-docgen</artifactId>
<artifactId>vertx-codegen-json</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-docgen-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
Expand Down Expand Up @@ -115,10 +120,19 @@
<id>default-compile</id>
<phase>compile</phase>
<configuration>
<annotationProcessors>
<annotationProcessor>io.vertx.codegen.CodeGenProcessor</annotationProcessor>
<annotationProcessor>io.vertx.docgen.JavaDocGenProcessor</annotationProcessor>
</annotationProcessors>
<generatedSourcesDirectory>${project.basedir}/src/main/generated</generatedSourcesDirectory>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>io.vertx</groupId>
<artifactId>vertx-codegen</artifactId>
<classifier>processor</classifier>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>io.vertx</groupId>
<artifactId>vertx-docgen-processor</artifactId>
<classifier>processor</classifier>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
Expand All @@ -141,6 +155,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useModulePath>false</useModulePath>
<systemPropertyVariables>
<java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
</systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, RedisOp
obj.setPoolName((String)member.getValue());
}
break;
case "metricsName":
if (member.getValue() instanceof String) {
obj.setMetricsName((String)member.getValue());
}
break;
case "hashSlotCacheTTL":
if (member.getValue() instanceof Number) {
obj.setHashSlotCacheTTL(((Number)member.getValue()).longValue());
Expand Down Expand Up @@ -174,6 +179,9 @@ static void toJson(RedisOptions obj, java.util.Map<String, Object> json) {
if (obj.getPoolName() != null) {
json.put("poolName", obj.getPoolName());
}
if (obj.getMetricsName() != null) {
json.put("metricsName", obj.getMetricsName());
}
json.put("hashSlotCacheTTL", obj.getHashSlotCacheTTL());
json.put("autoFailover", obj.isAutoFailover());
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/vertx/redis/client/impl/ArrayQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.Objects;

final class ArrayQueue {
public final class ArrayQueue {

private int
cur, // current number of elements
Expand All @@ -31,7 +31,7 @@ final class ArrayQueue {
/**
* Creates a new empty queue.
*/
ArrayQueue(int capacity) {
public ArrayQueue(int capacity) {
queue = new Object[capacity];
back = -1;
front = 0;
Expand All @@ -54,7 +54,7 @@ boolean isEmpty() {
* @throws IndexOutOfBoundsException if the queue is full.
* @throws NullPointerException if the value is {@code null}
*/
<T> void offer(T value) {
public <T> void offer(T value) {
Objects.requireNonNull(value, "'value' cannot be null");
if (isFull()) {
throw new IndexOutOfBoundsException();
Expand Down Expand Up @@ -87,7 +87,7 @@ <T> void offer(T value) {
*
* @return element at front of the queue or {@code null} if the queue is empty.
*/
<T> @Nullable T poll() {
public <T> @Nullable T poll() {
if (isEmpty()) {
return null;
}
Expand All @@ -102,7 +102,7 @@ <T> void offer(T value) {
return e;
}

int freeSlots() {
public int freeSlots() {
return queue.length - cur;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/vertx/redis/client/impl/BaseRedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public BaseRedisClient(Vertx vertx, NetClientOptions tcpOptions, PoolOptions poo
this.connectionManager.start();
}

public RedisConnectionManager connectionManager() {
return connectionManager;
}

@Override
public void close() {
this.connectionManager.close();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/redis/client/impl/RESPParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class RESPParser implements Handler<Buffer> {
// nesting while parsing
private final ArrayStack stack;

RESPParser(ParserHandler handler, int maxStack) {
public RESPParser(ParserHandler handler, int maxStack) {
this.handler = handler;
this.stack = new ArrayStack(maxStack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.internal.resource.ManagedResource;
import io.vertx.core.internal.resource.ResourceManager;
import io.vertx.core.net.ConnectOptions;
import io.vertx.core.net.NetClientOptions;
import io.vertx.core.net.NetSocket;
import io.vertx.core.net.impl.endpoint.EndpointManager;
import io.vertx.core.net.impl.endpoint.EndpointProvider;
import io.vertx.core.net.impl.endpoint.Endpoint;
import io.vertx.core.internal.pool.*;
import io.vertx.core.internal.net.NetClientInternal;
import io.vertx.core.internal.ContextInternal;
Expand All @@ -38,8 +37,9 @@
import io.vertx.redis.client.impl.types.ErrorType;

import java.util.Objects;
import java.util.function.Function;

class RedisConnectionManager implements EndpointProvider<RedisConnectionManager.ConnectionKey, RedisConnectionManager.RedisEndpoint> {
public class RedisConnectionManager implements Function<RedisConnectionManager.ConnectionKey, RedisConnectionManager.RedisEndpoint> {

private static final Logger LOG = LoggerFactory.getLogger(RedisConnectionManager.class);

Expand All @@ -53,7 +53,7 @@ class RedisConnectionManager implements EndpointProvider<RedisConnectionManager.
private final RedisConnectOptions connectOptions;
private final TracingPolicy tracingPolicy;

private final EndpointManager<ConnectionKey, RedisEndpoint> pooledConnectionManager;
private final ResourceManager<ConnectionKey, RedisEndpoint> pooledConnectionManager;
private long timerID;

RedisConnectionManager(VertxInternal vertx, NetClientOptions tcpOptions, PoolOptions poolOptions, RedisConnectOptions connectOptions, TracingPolicy tracingPolicy) {
Expand All @@ -65,11 +65,11 @@ class RedisConnectionManager implements EndpointProvider<RedisConnectionManager.
VertxMetrics metricsSPI = this.vertx.metricsSPI();
metrics = metricsSPI != null ? metricsSPI.createPoolMetrics("redis", poolOptions.getName(), poolOptions.getMaxSize()) : null;
this.netClient = (NetClientInternal) vertx.createNetClient(tcpOptions);
this.pooledConnectionManager = new EndpointManager<>();
this.pooledConnectionManager = new ResourceManager<>();
}

private RedisEndpoint connectionEndpointProvider(Runnable dispose, String connectionString, Request setup) {
return new RedisEndpoint(vertx, netClient, tcpOptions, poolOptions, connectOptions, tracingPolicy, dispose, connectionString, setup);
private RedisEndpoint connectionEndpointProvider(String connectionString, Request setup) {
return new RedisEndpoint(vertx, netClient, tcpOptions, poolOptions, connectOptions, tracingPolicy, connectionString, setup);
}

synchronized void start() {
Expand All @@ -93,7 +93,7 @@ private void checkExpired(long period) {
timerID = vertx.setTimer(period, id -> checkExpired(period));
}

static class ConnectionKey {
public static class ConnectionKey {
private final String string;
private final Request setup;

Expand Down Expand Up @@ -338,8 +338,8 @@ private Future<Void> setup(ContextInternal ctx, RedisConnection connection, Requ
}

@Override
public RedisEndpoint create(ConnectionKey key, Runnable dispose) {
return connectionEndpointProvider(dispose, key.string, key.setup);
public RedisEndpoint apply(ConnectionKey key) {
return connectionEndpointProvider(key.string, key.setup);
}

public Future<PooledRedisConnection> getConnection(String connectionString, Request setup) {
Expand All @@ -353,7 +353,7 @@ public Future<PooledRedisConnection> getConnection(String connectionString, Requ

final boolean metricsEnabled = metrics != null;
final Object queueMetric = metricsEnabled ? metrics.enqueue() : null;
Future<Lease<RedisConnectionInternal>> future = pooledConnectionManager.withEndpointAsync(new ConnectionKey(connectionString, setup), this, (endpoint, created) -> {
Future<Lease<RedisConnectionInternal>> future = pooledConnectionManager.withResourceAsync(new ConnectionKey(connectionString, setup), this, (endpoint, created) -> {
return endpoint.requestConnection(eventLoopContext);
});
return future
Expand All @@ -379,12 +379,15 @@ public void close() {
}
}

static class RedisEndpoint extends Endpoint {
public static class RedisEndpoint extends ManagedResource {

final ConnectionPool<RedisConnectionInternal> pool;

public RedisEndpoint(VertxInternal vertx, NetClientInternal netClient, NetClientOptions netClientOptions, PoolOptions poolOptions, RedisConnectOptions connectOptions, TracingPolicy tracingPolicy, Runnable dispose, String connectionString, Request setup) {
super(dispose);
public ConnectionPool<RedisConnectionInternal> pool() {
return pool;
}

public RedisEndpoint(VertxInternal vertx, NetClientInternal netClient, NetClientOptions netClientOptions, PoolOptions poolOptions, RedisConnectOptions connectOptions, TracingPolicy tracingPolicy, String connectionString, Request setup) {
PoolConnector<RedisConnectionInternal> connector = new RedisConnectionProvider(vertx, netClient, netClientOptions, poolOptions, connectOptions, tracingPolicy, connectionString, setup);
pool = ConnectionPool.pool(connector, new int[]{poolOptions.getMaxSize()}, poolOptions.getMaxWaiting());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/redis/client/impl/RequestImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Request arg(Buffer arg) {
return this;
}

Buffer encode() {
public Buffer encode() {
return encode(Buffer.buffer());
}

Expand Down Expand Up @@ -153,7 +153,7 @@ Buffer encode(Buffer buffer) {
return buffer;
}

List<byte[]> getArgs() {
public List<byte[]> getArgs() {
return args;
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

module io.vertx.client.redis {
requires io.vertx.core;
requires io.vertx.core.logging;
requires static io.vertx.docgen;
requires static io.vertx.codegen.api;
requires static io.vertx.codegen.json;
exports io.vertx.redis.client;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.vertx.redis.client.test;
package io.vertx.tests.redis.client;

import io.vertx.core.Future;
import io.vertx.core.Vertx;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.vertx.redis.client;
package io.vertx.tests.redis.client;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.Response;

import java.util.ArrayList;
import java.util.Comparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.vertx.redis.client.test;
package io.vertx.tests.redis.client;

import io.vertx.core.Context;
import io.vertx.core.Vertx;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.vertx.test.redis;
package io.vertx.tests.redis.client;

import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.RunTestOnContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.RedisOptions;
import io.vertx.redis.containers.RedisStandalone;
import io.vertx.tests.redis.containers.RedisStandalone;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
Expand All @@ -16,7 +16,7 @@

import static io.vertx.redis.client.Command.GET;
import static io.vertx.redis.client.Request.cmd;
import static io.vertx.redis.client.test.TestUtils.randomKey;
import static io.vertx.tests.redis.client.TestUtils.randomKey;

@RunWith(VertxUnitRunner.class)
public class RedisClient5SecureFailedTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.vertx.test.redis;
package io.vertx.tests.redis.client;

import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.RunTestOnContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.RedisOptions;
import io.vertx.redis.containers.RedisStandalone;
import io.vertx.tests.redis.containers.RedisStandalone;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
Expand All @@ -16,7 +16,7 @@

import static io.vertx.redis.client.Command.GET;
import static io.vertx.redis.client.Request.cmd;
import static io.vertx.redis.client.test.TestUtils.randomKey;
import static io.vertx.tests.redis.client.TestUtils.randomKey;

@RunWith(VertxUnitRunner.class)
public class RedisClient5SecureTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.vertx.test.redis;
package io.vertx.tests.redis.client;

import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.Async;
Expand All @@ -7,7 +7,7 @@
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.RedisOptions;
import io.vertx.redis.containers.RedisStandalone;
import io.vertx.tests.redis.containers.RedisStandalone;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
Expand All @@ -20,7 +20,7 @@
import static io.vertx.redis.client.Command.HSET;
import static io.vertx.redis.client.Command.SET;
import static io.vertx.redis.client.Request.cmd;
import static io.vertx.redis.client.test.TestUtils.randomKey;
import static io.vertx.tests.redis.client.TestUtils.randomKey;

@RunWith(VertxUnitRunner.class)
public class RedisClient5Test {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.vertx.test.redis;
package io.vertx.tests.redis.client;

import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
Expand All @@ -7,7 +7,7 @@
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.RedisOptions;
import io.vertx.redis.client.impl.types.ErrorType;
import io.vertx.redis.containers.RedisStandalone;
import io.vertx.tests.redis.containers.RedisStandalone;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
Expand All @@ -17,7 +17,7 @@

import static io.vertx.redis.client.Command.GET;
import static io.vertx.redis.client.Request.cmd;
import static io.vertx.redis.client.test.TestUtils.randomKey;
import static io.vertx.tests.redis.client.TestUtils.randomKey;

@RunWith(VertxUnitRunner.class)
public class RedisClient6SecureFailedTest {
Expand Down
Loading

0 comments on commit b45fc0b

Please sign in to comment.