!str #15236 Replace Transformer with Stage

* replace all existing Transformer with Stage (PushPullStage)
* use Flow[ByteString, ByteString] as encoder/decoder transformer in http
* use the IteratorInterpreter for strict if possible
* emit then become
* emit then finish
* termination emits
* FlowTransformerSpec
* rework types to work with Java API
* rename and move things
* add scaladoc
This commit is contained in:
Patrik Nordwall 2014-11-12 10:43:39 +01:00
parent 299854905b
commit a82f266367
61 changed files with 1478 additions and 1518 deletions

View file

@ -4,7 +4,6 @@
package akka.stream.javadsl
import java.util.concurrent.Callable
import akka.actor.ActorRef
import akka.actor.Props
import akka.japi.Util
@ -12,13 +11,13 @@ import akka.stream._
import akka.stream.scaladsl.PropsSource
import org.reactivestreams.Publisher
import org.reactivestreams.Subscriber
import scala.annotation.unchecked.uncheckedVariance
import scala.collection.JavaConverters._
import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration
import scala.language.higherKinds
import scala.language.implicitConversions
import akka.stream.stage.Stage
/** Java API */
object Source {
@ -387,56 +386,41 @@ class Source[+Out](delegate: scaladsl.Source[Out]) {
new Source(delegate.buffer(size, overflowStrategy))
/**
* Generic transformation of a stream: for each element the [[akka.stream.Transformer#onNext]]
* function is invoked, expecting a (possibly empty) sequence of output elements
* to be produced.
* After handing off the elements produced from one input element to the downstream
* subscribers, the [[akka.stream.Transformer#isComplete]] predicate determines whether to end
* stream processing at this point; in that case the upstream subscription is
* canceled. Before signaling normal completion to the downstream subscribers,
* the [[akka.stream.Transformer#onTermination]] function is invoked to produce a (possibly empty)
* sequence of elements in response to the end-of-stream event.
*
* [[akka.stream.Transformer#onError]] is called when failure is signaled from upstream.
*
* After normal completion or error the [[akka.stream.Transformer#cleanup]] function is called.
*
* It is possible to keep state in the concrete [[akka.stream.Transformer]] instance with
* ordinary instance variables. The [[akka.stream.Transformer]] is executed by an actor and
* therefore you do not have to add any additional thread safety or memory
* visibility constructs to access the state from the callback methods.
* Generic transformation of a stream with a custom processing [[akka.stream.stage.Stage]].
* This operator makes it possible to extend the `Flow` API when there is no specialized
* operator that performs the transformation.
*
* Note that you can use [[#timerTransform]] if you need support for scheduled events in the transformer.
*/
def transform[U](name: String, mkTransformer: japi.Creator[Transformer[Out, U]]): javadsl.Source[U] =
new Source(delegate.transform(name, () mkTransformer.create()))
def transform[U](name: String, mkStage: japi.Creator[Stage[Out, U]]): javadsl.Source[U] =
new Source(delegate.transform(name, () mkStage.create()))
/**
* Transformation of a stream, with additional support for scheduled events.
*
* For each element the [[akka.stream.Transformer#onNext]]
* For each element the [[akka.stream.TransformerLike#onNext]]
* function is invoked, expecting a (possibly empty) sequence of output elements
* to be produced.
* After handing off the elements produced from one input element to the downstream
* subscribers, the [[akka.stream.Transformer#isComplete]] predicate determines whether to end
* subscribers, the [[akka.stream.TransformerLike#isComplete]] predicate determines whether to end
* stream processing at this point; in that case the upstream subscription is
* canceled. Before signaling normal completion to the downstream subscribers,
* the [[akka.stream.Transformer#onTermination]] function is invoked to produce a (possibly empty)
* the [[akka.stream.TransformerLike#onTermination]] function is invoked to produce a (possibly empty)
* sequence of elements in response to the end-of-stream event.
*
* [[akka.stream.Transformer#onError]] is called when failure is signaled from upstream.
* [[akka.stream.TransformerLike#onError]] is called when failure is signaled from upstream.
*
* After normal completion or error the [[akka.stream.Transformer#cleanup]] function is called.
* After normal completion or error the [[akka.stream.TransformerLike#cleanup]] function is called.
*
* It is possible to keep state in the concrete [[akka.stream.Transformer]] instance with
* ordinary instance variables. The [[akka.stream.Transformer]] is executed by an actor and
* It is possible to keep state in the concrete [[akka.stream.TimerTransformer]] instance with
* ordinary instance variables. The [[akka.stream.TimerTransformer]] is executed by an actor and
* therefore you do not have to add any additional thread safety or memory
* visibility constructs to access the state from the callback methods.
*
* Note that you can use [[#transform]] if you just need to transform elements time plays no role in the transformation.
*/
def timerTransform[U](name: String, mkTransformer: japi.Creator[TimerTransformer[Out, U]]): javadsl.Source[U] =
new Source(delegate.timerTransform(name, () mkTransformer.create()))
def timerTransform[U](name: String, mkStage: japi.Creator[TimerTransformer[Out, U]]): javadsl.Source[U] =
new Source(delegate.timerTransform(name, () mkStage.create()))
/**
* Takes up to `n` elements from the stream and returns a pair containing a strict sequence of the taken element