forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#17946 from michalszynkiewicz/fix-grpc-re…
…quest-scope gRPC: fix request context propagation
- Loading branch information
Showing
34 changed files
with
1,185 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ime/src/main/java/io/quarkus/grpc/runtime/supports/blocking/BlockingExecutionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkus.grpc.runtime.supports.blocking; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import io.grpc.Context; | ||
import io.grpc.ServerCall; | ||
import io.quarkus.arc.InjectableContext; | ||
import io.quarkus.arc.ManagedContext; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Promise; | ||
|
||
class BlockingExecutionHandler<ReqT> implements Handler<Promise<Object>> { | ||
private final ServerCall.Listener<ReqT> delegate; | ||
private final Context grpcContext; | ||
private final Consumer<ServerCall.Listener<ReqT>> consumer; | ||
private final InjectableContext.ContextState state; | ||
private final ManagedContext requestContext; | ||
|
||
public BlockingExecutionHandler(Consumer<ServerCall.Listener<ReqT>> consumer, Context grpcContext, | ||
ServerCall.Listener<ReqT> delegate, InjectableContext.ContextState state, | ||
ManagedContext requestContext) { | ||
this.consumer = consumer; | ||
this.grpcContext = grpcContext; | ||
this.delegate = delegate; | ||
this.state = state; | ||
this.requestContext = requestContext; | ||
} | ||
|
||
@Override | ||
public void handle(Promise<Object> event) { | ||
final Context previous = Context.current(); | ||
grpcContext.attach(); | ||
try { | ||
requestContext.activate(state); | ||
try { | ||
consumer.accept(delegate); | ||
} catch (Throwable any) { | ||
event.fail(any); | ||
return; | ||
} finally { | ||
requestContext.deactivate(); | ||
} | ||
event.complete(); | ||
} finally { | ||
grpcContext.detach(previous); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../main/java/io/quarkus/grpc/runtime/supports/blocking/DevModeBlockingExecutionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.grpc.runtime.supports.blocking; | ||
|
||
import io.vertx.core.Handler; | ||
import io.vertx.core.Promise; | ||
|
||
class DevModeBlockingExecutionHandler implements Handler<Promise<Object>> { | ||
|
||
final ClassLoader tccl; | ||
final Handler<Promise<Object>> delegate; | ||
|
||
public DevModeBlockingExecutionHandler(ClassLoader tccl, Handler<Promise<Object>> delegate) { | ||
this.tccl = tccl; | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void handle(Promise<Object> event) { | ||
ClassLoader originalTccl = Thread.currentThread().getContextClassLoader(); | ||
Thread.currentThread().setContextClassLoader(tccl); | ||
try { | ||
delegate.handle(event); | ||
} finally { | ||
Thread.currentThread().setContextClassLoader(originalTccl); | ||
} | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
...time/src/main/java/io/quarkus/grpc/runtime/supports/context/GrpcEnableRequestContext.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.