forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
174 additions
and
40 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
16 changes: 16 additions & 0 deletions
16
...runtime/src/main/java/io/quarkus/grpc/runtime/supports/context/CleanUpRequestContext.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,16 @@ | ||
package io.quarkus.grpc.runtime.supports.context; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.interceptor.InterceptorBinding; | ||
|
||
@Inherited | ||
@InterceptorBinding | ||
@Target({ ElementType.TYPE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CleanUpRequestContext { | ||
} |
37 changes: 37 additions & 0 deletions
37
.../main/java/io/quarkus/grpc/runtime/supports/context/GrpcRequestContextCdiInterceptor.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,37 @@ | ||
package io.quarkus.grpc.runtime.supports.context; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ManagedContext; | ||
import io.vertx.core.Context; | ||
import io.vertx.core.Vertx; | ||
|
||
@Interceptor | ||
@CleanUpRequestContext | ||
public class GrpcRequestContextCdiInterceptor { | ||
public static final String GRPC_REQUEST_CONTEXT_STATE = "GRPC_REQUEST_CONTEXT_STATE"; | ||
|
||
@AroundInvoke | ||
public Object cleanUpContext(InvocationContext invocationContext) throws Exception { | ||
boolean cleanUp = false; | ||
ManagedContext requestContext = Arc.container().requestContext(); | ||
if (!requestContext.isActive()) { | ||
cleanUp = true; | ||
requestContext.activate(); | ||
Context context = Vertx.currentContext(); | ||
if (context != null) { | ||
context.put(GRPC_REQUEST_CONTEXT_STATE, requestContext.getState()); | ||
} | ||
} | ||
try { | ||
return invocationContext.proceed(); | ||
} finally { | ||
if (cleanUp) { | ||
requestContext.deactivate(); | ||
} | ||
} | ||
} | ||
} |
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