Skip to content

Commit

Permalink
Allow Vert.x to use other Context implementations than EventLoopConte…
Browse files Browse the repository at this point in the history
…xt and WorkerContext.

The Context and its related classes/intefaces have been refactored to pull up code as much as possible in Context and ContextInternal in order to ease new implementations, consequently the AbstractContext class has been removed.

The ContextImpl class has been renamed ContextBase and provides a base class for implementing context.

fixes #4425
  • Loading branch information
vietj committed Jun 30, 2022
1 parent cdeece4 commit a3e6ae5
Show file tree
Hide file tree
Showing 19 changed files with 620 additions and 443 deletions.
13 changes: 10 additions & 3 deletions src/main/java/io/vertx/core/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.vertx.codegen.annotations.Nullable;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.impl.VertxThread;
import io.vertx.core.impl.launcher.VertxCommandLauncher;
import io.vertx.core.json.JsonObject;

import java.util.List;
Expand Down Expand Up @@ -135,7 +136,9 @@ static boolean isOnVertxThread() {
* @param resultHandler handler that will be called when the blocking code is complete
* @param <T> the type of the result
*/
<T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, Handler<AsyncResult<@Nullable T>> resultHandler);
default <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, Handler<AsyncResult<@Nullable T>> resultHandler) {
executeBlocking(blockingCodeHandler, true, resultHandler);
}

/**
* Same as {@link #executeBlocking(Handler, boolean, Handler)} but with an {@code handler} called when the operation completes
Expand All @@ -145,7 +148,9 @@ static boolean isOnVertxThread() {
/**
* Same as {@link #executeBlocking(Handler, Handler)} but with an {@code handler} called when the operation completes
*/
<T> Future<T> executeBlocking(Handler<Promise<T>> blockingCodeHandler);
default <T> Future<T> executeBlocking(Handler<Promise<T>> blockingCodeHandler) {
return executeBlocking(blockingCodeHandler, true);
}

/**
* If the context is associated with a Verticle deployment, this returns the deployment ID of that deployment.
Expand All @@ -165,7 +170,9 @@ static boolean isOnVertxThread() {
/**
* The process args
*/
List<String> processArgs();
default List<String> processArgs() {
return VertxCommandLauncher.getProcessArguments();
}

/**
* Is the current context an event loop context?
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/core/file/impl/AsyncFileImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public class AsyncFileImpl implements AsyncFile {
try {
if (options.getPerms() != null) {
FileAttribute<?> attrs = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(options.getPerms()));
ch = AsynchronousFileChannel.open(file, opts, vertx.getWorkerPool(), attrs);
ch = AsynchronousFileChannel.open(file, opts, vertx.getWorkerPool().executor(), attrs);
} else {
ch = AsynchronousFileChannel.open(file, opts, vertx.getWorkerPool());
ch = AsynchronousFileChannel.open(file, opts, vertx.getWorkerPool().executor());
}
if (options.isAppend()) writePos = ch.size();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void setRequest(HttpRequest request) {

private InboundBuffer<Object> pendingQueue() {
if (pending == null) {
pending = new InboundBuffer<>(conn.getContext(), 8);
pending = new InboundBuffer<>(context, 8);
pending.drainHandler(v -> conn.doResume());
pending.handler(buffer -> {
if (buffer == InboundBuffer.END_SENTINEL) {
Expand Down
235 changes: 0 additions & 235 deletions src/main/java/io/vertx/core/impl/AbstractContext.java

This file was deleted.

Loading

0 comments on commit a3e6ae5

Please sign in to comment.