Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to resolve FIXME share trailers through matval #302

Open
laglangyue opened this issue Apr 17, 2024 · 2 comments
Open

try to resolve FIXME share trailers through matval #302

laglangyue opened this issue Apr 17, 2024 · 2 comments

Comments

@laglangyue
Copy link
Contributor

laglangyue commented Apr 17, 2024

source code

def onCallClosed(status: Status, trailers: Metadata): Unit = {
if (status.isOk()) {
// FIXME share trailers through matval
completeStage()
} else {
failStage(status.asRuntimeException(trailers))
}
call = null

I've submit a pr

@laglangyue
Copy link
Contributor Author

I went to learn about GRPC, header=>message=>trailers
We stored the header and future [trailers] through GrpcResponseMetadata
We have completed the promise [GrpcResponseMetada] in onHeader, so we are unable to assign a value to the trainers,
So the original author defined another Promise [trailers]
When on Hedaer, GrpcResponseMetadata is in a semi completed state
OnClose is the final state

@laglangyue
Copy link
Contributor Author

I think this FIXME may not be necessary, but there is a lot of repetitive code about GrpcResponseMetada, which can be constructed using a builder pattern to create GrpcResponseMetada, with Header, with Message, with Close (with Trailers)

I have tried writing some code locally, but I still need some deeper exploration

class GrpcResponseMetadataImpl(
    grpcHeaders: io.grpc.Metadata, trailersPromise: Promise[io.grpc.Metadata]) extends GrpcResponseMetadata {

  override def headers: pekko.grpc.scaladsl.Metadata =
    MetadataImpl.scalaMetadataFromGoogleGrpcMetadata(grpcHeaders)
  override def getHeaders(): pekko.grpc.javadsl.Metadata =
    MetadataImpl.javaMetadataFromGoogleGrpcMetadata(grpcHeaders)
  override def trailers: Future[pekko.grpc.scaladsl.Metadata] =
    trailersPromise.future.map(MetadataImpl.scalaMetadataFromGoogleGrpcMetadata)(ExecutionContexts.parasitic)
  override def getTrailers(): CompletionStage[pekko.grpc.javadsl.Metadata] =
    trailersPromise.future.map(MetadataImpl.javaMetadataFromGoogleGrpcMetadata)(ExecutionContexts.parasitic)
      .asJava
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant