public class Composition extends Object
GraphComputation
s.
The first computation is expected to be a composed computation.
The composition of two computations C1 that transforms ComposedKey(K1, R1) to
ComposedResult(R1) with C2 that transforms K2 to R2 results in a computation C' that transforms
ComposedKey(K1, R2) to ComposedResult(R2). This is under a Composer
that takes K1 and R1
and returns a set of K2's to be computed.
TODO(bobyf): currently composition only builds properly left to right.
Constructor and Description |
---|
Composition() |
Modifier and Type | Method and Description |
---|---|
static <Key1 extends ComputeKey<Result1>,Result1 extends ComputeResult> |
asComposition(Class<Result1> resultClass,
GraphComputation<Key1,Result1> baseComputation)
Creates a
ComposedComputation from a normal GraphComputation for performing
compositions. |
static <KeyBase extends ComputeKey<?>,Key1 extends ComputeKey<Result1>,Result1 extends ComputeResult,Key2 extends ComputeKey<Result2>,Result2 extends ComputeResult> |
composeLeft(Class<Result2> resultClass,
ComposedComputation<KeyBase,Result1> baseComputation,
KeyComposer<Key1,Result1,Key2> composer)
Creates a
ComposedComputation from a base ComposedComputation used for chaining
multiple GraphComputation together. |
static <KeyIntermediate extends ComputeKey<?>,Key1 extends ComputeKey<Result1>,Result1 extends ComputeResult,Key2 extends ComputeKey<Result2>,Result2 extends ComputeResult> |
composeRight(Class<Result2> resultClass,
GraphComputation<Key1,Result1> baseComputation,
KeyComposer<Key1,Result1,KeyIntermediate> composer)
Creates a
ComposedComputation from a base ComposedComputation used for chaining
multiple GraphComputation together. |
public static <KeyBase extends ComputeKey<?>,Key1 extends ComputeKey<Result1>,Result1 extends ComputeResult,Key2 extends ComputeKey<Result2>,Result2 extends ComputeResult> ComposedComputation<KeyBase,Result2> composeLeft(Class<Result2> resultClass, ComposedComputation<KeyBase,Result1> baseComputation, KeyComposer<Key1,Result1,Key2> composer)
ComposedComputation
from a base ComposedComputation
used for chaining
multiple GraphComputation
together.
Chaining computations means to begin at a base computation that transforms K1 to R1, and then using the this method chain a second computation K2 to R2 to create one composed computation of K1 to Composed[R2]. The resulting composed computation can be then used to chain more computations Kn to Rn, until we have computations K1 to Rn. Note that since we create a Composed[Rn], all subsequent compositions are required to wait for the completion of all Rn's. This is a reduce and not ideal for creating computations that resembles trees in its fan out.
Key1
- the type of base computation keyResult1
- the type of base computation resultKey2
- the type of the second composing computationResult2
- the result type of the second composing computationresultClass
- the result class of this compositionbaseComputation
- the base computationcomposer
- a KeyComposer
that takes results of the base computation and determines
how to trigger the computation for the result class desired.ComposedComputation
that takes in a composed key from Key1
to ComposedResult
of Result2
public static <KeyIntermediate extends ComputeKey<?>,Key1 extends ComputeKey<Result1>,Result1 extends ComputeResult,Key2 extends ComputeKey<Result2>,Result2 extends ComputeResult> ComposedComputation<Key1,Result2> composeRight(Class<Result2> resultClass, GraphComputation<Key1,Result1> baseComputation, KeyComposer<Key1,Result1,KeyIntermediate> composer)
ComposedComputation
from a base ComposedComputation
used for chaining
multiple GraphComputation
together.
Chaining computations means to begin at a base computation that transforms K1 to R1, and then using this method chain a second composed computation composed(K2) to composed(R2) to create one composed computation of K1 to Composed[R2]. The resulting composed computation can be then used to chain more computations Kn to Rn, until we have computations K1 to Rn. Note that for this, we start at the right, which helps create fan-out tree structured graph computation.
KeyIntermediate
- the type of the key of the right ComposedComputation
Key1
- the type of base computation keyResult1
- the type of base computation resultKey2
- the type of the key corresponding to the final result typeResult2
- the result type of the right ComposedComputation
resultClass
- the result class of this compositionbaseComputation
- the base computationcomposer
- a KeyComposer
that takes results of the base computation and determines
how to trigger the computation for the result class desired.ComposedComputation
that takes in a composed key from Key1
to ComposedResult
of Result2
public static <Key1 extends ComputeKey<Result1>,Result1 extends ComputeResult> ComposedComputation<Key1,Result1> asComposition(Class<Result1> resultClass, GraphComputation<Key1,Result1> baseComputation)
ComposedComputation
from a normal GraphComputation
for performing
compositions. The composition created is just a wrapper around the existing GraphComputation
and doesn't do anything.Key1
- the key type of the computationResult1
- the result type of the computationresultClass
- the class of the result of the wrapped computationbaseComputation
- the computation to wrap as ComposedComputation
ComposedComputation
wrapping the given GraphComputation