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

feat: Exposes GraphInterpreter when initing the stages. #919

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.apache.pekko.stream.scaladsl

import org.apache.pekko
import org.apache.pekko.stream.impl.fusing.GraphInterpreter
import pekko.NotUsed
import pekko.stream.Attributes
import pekko.stream.Attributes.Attribute
Expand Down Expand Up @@ -143,6 +144,14 @@ class FromMaterializerSpec extends StreamSpec {
Source.empty.via(flow).runWith(Sink.head).futureValue should not be empty
}

"expose interpreter" in {
val flow = Flow.fromMaterializer { (_, _) =>
Flow.fromSinkAndSource(Sink.ignore, Source.single(GraphInterpreter.currentInterpreter))
}

Source.empty.via(flow).runWith(Sink.head).futureValue should not be null
}

"propagate materialized value" in {
val flow = Flow.fromMaterializer { (_, _) =>
Flow.fromSinkAndSourceMat(Sink.ignore, Source.maybe[NotUsed])(Keep.right)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,27 @@ import pekko.stream.stage._
*/
def init(subMat: Materializer): Unit = {
_subFusingMaterializer = if (subMat == null) materializer else subMat
var i = 0
while (i < logics.length) {
val logic = logics(i)
logic.interpreter = this
try {
logic.beforePreStart()
logic.preStart()
} catch {
case NonFatal(e) =>
log.error(e, "Error during preStart in [{}]: {}", logic.toString, e.getMessage)
logic.failStage(e)
val currentInterpreterHolder = _currentInterpreter.get()
val previousInterpreter = currentInterpreterHolder(0)
currentInterpreterHolder(0) = this
try {
var i = 0
while (i < logics.length) {
val logic = logics(i)
logic.interpreter = this
try {
logic.beforePreStart()
logic.preStart()
} catch {
case NonFatal(e) =>
log.error(e, "Error during preStart in [{}]: {}", logic.toString, e.getMessage)
logic.failStage(e)
}
afterStageHasRun(logic)
i += 1
}
afterStageHasRun(logic)
i += 1
} finally {
currentInterpreterHolder(0) = previousInterpreter
}
}

Expand Down
Loading