Skip to content

Commit 50c3ff2

Browse files
author
Pawel Czajka
committed
used holder
1 parent 7832399 commit 50c3ff2

File tree

1 file changed

+7
-6
lines changed
  • engine/flink/components/base-unbounded/src/main/scala/pl/touk/nussknacker/engine/flink/util/transformer/aggregate

1 file changed

+7
-6
lines changed

engine/flink/components/base-unbounded/src/main/scala/pl/touk/nussknacker/engine/flink/util/transformer/aggregate/ExtendedWindowOperator.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ object ExtendedWindowOperator {
6464

6565
}
6666

67+
private[aggregate] case class NuWindowContextHolder(var nuWindowContext: NuWindowContext)
68+
6769
private[aggregate] sealed trait NuWindowContext
6870

6971
private[aggregate] final case class OnElementWindowContext(
@@ -82,7 +84,7 @@ private[aggregate] class ExtendedWindowOperator[A](
8284
aggregateFunction: AggregateFunction[Input[A], AnyRef, AnyRef],
8385
trigger: Trigger[_ >: Input[A], TimeWindow],
8486
preserveContext: Boolean,
85-
private val contextHolderRef: AtomicReference[NuWindowContext] = new AtomicReference(OnTimerWindowContext)
87+
private val contextHolderRef: NuWindowContextHolder = NuWindowContextHolder(OnTimerWindowContext)
8688
) extends WindowOperator[String, Input[A], AnyRef, ValueWithContext[AnyRef], TimeWindow](
8789
assigner,
8890
assigner.getWindowSerializer(stream.getExecutionConfig),
@@ -102,13 +104,12 @@ private[aggregate] class ExtendedWindowOperator[A](
102104
) {
103105

104106
override def processElement(element: StreamRecord[ValueWithContext[StringKeyedValue[A]]]): Unit = {
105-
contextHolderRef.set(
107+
contextHolderRef.nuWindowContext =
106108
OnElementWindowContext(if (preserveContext) Some(element.getValue.context) else None, element.getTimestamp)
107-
)
108109
try {
109110
super.processElement(element)
110111
} finally {
111-
contextHolderRef.set(OnTimerWindowContext)
112+
contextHolderRef.nuWindowContext = OnTimerWindowContext
112113
}
113114
}
114115

@@ -117,7 +118,7 @@ private[aggregate] class ExtendedWindowOperator[A](
117118
private class ValueEmittingWindowFunction(
118119
convertToEngineRuntimeContext: RuntimeContext => EngineRuntimeContext,
119120
nodeId: String,
120-
private val contextHolderRef: AtomicReference[NuWindowContext]
121+
private val contextHolderRef: NuWindowContextHolder
121122
) extends ProcessWindowFunction[AnyRef, ValueWithContext[AnyRef], String, TimeWindow] {
122123

123124
@transient
@@ -134,7 +135,7 @@ private class ValueEmittingWindowFunction(
134135
out: Collector[ValueWithContext[AnyRef]]
135136
): Unit = {
136137
elements.forEach { element =>
137-
val contextOpt = contextHolderRef.get match {
138+
val contextOpt = contextHolderRef.nuWindowContext match {
138139
case OnElementWindowContext(contextToPreserve, timestampToOverride) =>
139140
// in current flink implementation out is always of type TimestampedCollector
140141
out.asInstanceOf[TimestampedCollector[_]].setAbsoluteTimestamp(timestampToOverride)

0 commit comments

Comments
 (0)