He-Pin opened a new pull request, #3388:
URL: https://github.com/apache/pekko/pull/3388
### Motivation
`javadsl.SourceWithContext` delegated to `scaladsl.SourceWithContext` whose
shape is `SourceShape[(Out, Ctx)]` (Scala Tuple2). Java developers expect
`SourceShape[Pair[Out, Ctx]]` when using it in GraphDSL. This made it
impossible to use `SourceWithContext` directly in `GraphDSL.create()` without
the `.asSource()` workaround.
Fixes #2510 (refs akka/akka-core#31090)
### Modification
Changed the internal delegate of `javadsl.SourceWithContext` from
`scaladsl.SourceWithContext[Out, Ctx, Mat]` to `javadsl.Source[Pair[Out, Ctx],
Mat]`, matching the pattern already used by `javadsl.FlowWithContext` (which
does not have this bug).
Key changes:
- Constructor now takes `javadsl.Source[Pair[Out, Ctx], Mat]` instead of
`scaladsl.SourceWithContext`
- `asScala` converts Pair→Tuple2 when bridging to scaladsl
- `viaScala` uses `f(asScala).asJava` pattern (same as FlowWithContext)
- Simplified `via`, `asSource`, `to`, `toMat` methods
- Updated `scaladsl.SourceWithContext.asJava` to produce Pair-typed delegate
- Added MiMa filter for the intentional constructor signature change (2.0.0
breaking fix)
### Result
`SourceWithContext` now exposes a `Pair`-typed `SourceShape` in GraphDSL,
consistent with `FlowWithContext` and Java developer expectations. The
following code now compiles and works correctly:
```java
SourceWithContext<Element, String, NotUsed> sourceWithContext =
Source.single(new Element("key", 1)).asSourceWithContext(elem ->
elem.key);
Source<Pair<Element, String>, NotUsed> source =
Source.fromGraph(
GraphDSL.create(
sourceWithContext,
(builder, in) -> {
// in is now SourceShape<Pair<Element, String>> as expected
return SourceShape.of(in.out());
}));
```
### Tests
- `sbt "stream-tests / Test / testOnly
org.apache.pekko.stream.javadsl.SourceWithContextTest"` — 3/3 passed (includes
new GraphDSL shape test)
- `sbt "stream-tests / Test / testOnly
org.apache.pekko.stream.javadsl.FlowWithContextTest"` — 4/4 passed
- `sbt "stream-tests / Test / testOnly
org.apache.pekko.stream.scaladsl.SourceWithContextSpec
org.apache.pekko.stream.scaladsl.FlowWithContextSpec"` — 28/28 passed
- `sbt "stream-tests / Test / testOnly
org.apache.pekko.stream.javadsl.RetryFlowTest"` — 4/4 passed
- `sbt "stream-tests / Test / testOnly
org.apache.pekko.stream.scaladsl.WithContextUsageSpec"` — 5/5 passed
- `sbt "stream/mimaReportBinaryIssues"` — passed (with new filter)
- `sbt "docs/Test/compile"` — passed
### References
Fixes #2510
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]