-
Notifications
You must be signed in to change notification settings - Fork 23
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 #106 from eclipse-vertx/bunch-of-improvements
Improvements
- Loading branch information
Showing
18 changed files
with
243 additions
and
171 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
43 changes: 43 additions & 0 deletions
43
vertx-grpc-common/src/main/java/io/vertx/grpc/common/GrpcErrorException.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,43 @@ | ||
/* | ||
* Copyright (c) 2011-2022 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package io.vertx.grpc.common; | ||
|
||
import io.vertx.core.VertxException; | ||
import io.vertx.core.http.StreamResetException; | ||
|
||
/** | ||
* Thrown when a failure happens before the response, and it could be interpreted to a gRPC failure, e.g. | ||
* in practice it means an HTTP/2 stream reset mapped to a gRPC code according to the | ||
* <a href="https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#http2-transport-mapping">spec</a>. | ||
*/ | ||
public class GrpcErrorException extends VertxException { | ||
|
||
public static GrpcErrorException create(StreamResetException sre) { | ||
GrpcError error = GrpcError.mapHttp2ErrorCode(sre.getCode()); | ||
GrpcStatus status = GrpcStatus.UNKNOWN; | ||
if (error != null) { | ||
status = error.status; | ||
} | ||
return new GrpcErrorException(status); | ||
} | ||
|
||
private final GrpcStatus status; | ||
|
||
public GrpcErrorException(GrpcStatus status) { | ||
super("gRPC error status: " + status.name()); | ||
|
||
this.status = status; | ||
} | ||
|
||
public GrpcStatus status() { | ||
return status; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
vertx-grpc-common/src/main/java/io/vertx/grpc/common/GrpcLocal.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,62 @@ | ||
/* | ||
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package io.vertx.grpc.common; | ||
|
||
import io.vertx.core.Context; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.internal.ContextInternal; | ||
import io.vertx.core.spi.context.storage.ContextLocal; | ||
import io.vertx.grpc.common.impl.GrpcRequestLocalRegistration; | ||
|
||
import java.time.Instant; | ||
|
||
/** | ||
* gRPC request local propagation. | ||
*/ | ||
public class GrpcLocal { | ||
|
||
/** | ||
* Context local key. | ||
*/ | ||
public static final ContextLocal<GrpcLocal> CONTEXT_LOCAL_KEY = GrpcRequestLocalRegistration.CONTEXT_LOCAL; | ||
|
||
private final long deadlineMillis; | ||
private Instant deadline; | ||
|
||
public GrpcLocal(long deadlineMillis) { | ||
this.deadlineMillis = deadlineMillis; | ||
} | ||
|
||
/** | ||
* @return the local associated with the given {@code context} | ||
*/ | ||
public static GrpcLocal of(Context context) { | ||
return ((ContextInternal)context).getLocal(CONTEXT_LOCAL_KEY); | ||
} | ||
|
||
/** | ||
* @return the current request local or {@code null} | ||
*/ | ||
public static GrpcLocal current() { | ||
Context ctx = Vertx.currentContext(); | ||
return ctx != null ? of(ctx) : null; | ||
} | ||
|
||
/** | ||
* @return the deadline | ||
*/ | ||
public Instant deadline() { | ||
if (deadline == null) { | ||
deadline = Instant.ofEpochMilli(deadlineMillis); | ||
} | ||
return deadline; | ||
} | ||
} |
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
30 changes: 0 additions & 30 deletions
30
vertx-grpc-common/src/main/java/io/vertx/grpc/common/impl/GrpcRequestLocal.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.