14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
-
18
17
package org .apache .kafka .streams .kstream .internals .foreignkeyjoin ;
19
18
20
19
import org .apache .kafka .common .errors .UnsupportedVersionException ;
43
42
* of the primary key. This eliminates race-condition results for rapidly-changing foreign-keys for a given primary key.
44
43
* Applies the join and emits nulls according to LEFT/INNER rules.
45
44
*
46
- * @param <K > Type of primary keys
47
- * @param <V > Type of primary values
48
- * @param <VO > Type of foreign values
49
- * @param <VR > Type of joined result of primary and foreign values
45
+ * @param <KLeft > Type of primary keys
46
+ * @param <VLeft > Type of primary values
47
+ * @param <VRight > Type of foreign values
48
+ * @param <VOut > Type of joined result of primary and foreign values
50
49
*/
51
- public class ResponseJoinProcessorSupplier <K , V , VO , VR > implements ProcessorSupplier <K , SubscriptionResponseWrapper <VO >, K , VR > {
50
+ public class ResponseJoinProcessorSupplier <KLeft , VLeft , VRight , VOut >
51
+ implements ProcessorSupplier <KLeft , SubscriptionResponseWrapper <VRight >, KLeft , VOut > {
52
+
52
53
private static final Logger LOG = LoggerFactory .getLogger (ResponseJoinProcessorSupplier .class );
53
- private final KTableValueGetterSupplier <K , V > valueGetterSupplier ;
54
- private final Serializer <V > constructionTimeValueSerializer ;
54
+ private final KTableValueGetterSupplier <KLeft , VLeft > valueGetterSupplier ;
55
+ private final Serializer <VLeft > constructionTimeValueSerializer ;
55
56
private final Supplier <String > valueHashSerdePseudoTopicSupplier ;
56
- private final ValueJoiner <? super V , ? super VO , ? extends VR > joiner ;
57
+ private final ValueJoiner <? super VLeft , ? super VRight , ? extends VOut > joiner ;
57
58
private final boolean leftJoin ;
58
59
59
- public ResponseJoinProcessorSupplier (final KTableValueGetterSupplier <K , V > valueGetterSupplier ,
60
- final Serializer <V > valueSerializer ,
60
+ public ResponseJoinProcessorSupplier (final KTableValueGetterSupplier <KLeft , VLeft > valueGetterSupplier ,
61
+ final Serializer <VLeft > valueSerializer ,
61
62
final Supplier <String > valueHashSerdePseudoTopicSupplier ,
62
- final ValueJoiner <? super V , ? super VO , ? extends VR > joiner ,
63
+ final ValueJoiner <? super VLeft , ? super VRight , ? extends VOut > joiner ,
63
64
final boolean leftJoin ) {
64
65
this .valueGetterSupplier = valueGetterSupplier ;
65
66
constructionTimeValueSerializer = valueSerializer ;
@@ -69,24 +70,24 @@ public ResponseJoinProcessorSupplier(final KTableValueGetterSupplier<K, V> value
69
70
}
70
71
71
72
@ Override
72
- public Processor <K , SubscriptionResponseWrapper <VO >, K , VR > get () {
73
+ public Processor <KLeft , SubscriptionResponseWrapper <VRight >, KLeft , VOut > get () {
73
74
return new ContextualProcessor <>() {
74
75
private String valueHashSerdePseudoTopic ;
75
- private Serializer <V > runtimeValueSerializer = constructionTimeValueSerializer ;
76
+ private Serializer <VLeft > runtimeValueSerializer = constructionTimeValueSerializer ;
76
77
77
- private KTableValueGetter <K , V > valueGetter ;
78
+ private KTableValueGetter <KLeft , VLeft > valueGetter ;
78
79
private Sensor droppedRecordsSensor ;
79
80
80
81
81
82
@ SuppressWarnings ({"unchecked" , "resource" })
82
83
@ Override
83
- public void init (final ProcessorContext <K , VR > context ) {
84
+ public void init (final ProcessorContext <KLeft , VOut > context ) {
84
85
super .init (context );
85
86
valueHashSerdePseudoTopic = valueHashSerdePseudoTopicSupplier .get ();
86
87
valueGetter = valueGetterSupplier .get ();
87
88
valueGetter .init (context );
88
89
if (runtimeValueSerializer == null ) {
89
- runtimeValueSerializer = (Serializer <V >) context .valueSerde ().serializer ();
90
+ runtimeValueSerializer = (Serializer <VLeft >) context .valueSerde ().serializer ();
90
91
}
91
92
92
93
final InternalProcessorContext <?, ?> internalProcessorContext = (InternalProcessorContext <?, ?>) context ;
@@ -98,14 +99,14 @@ public void init(final ProcessorContext<K, VR> context) {
98
99
}
99
100
100
101
@ Override
101
- public void process (final Record <K , SubscriptionResponseWrapper <VO >> record ) {
102
+ public void process (final Record <KLeft , SubscriptionResponseWrapper <VRight >> record ) {
102
103
if (record .value ().version () != SubscriptionResponseWrapper .CURRENT_VERSION ) {
103
104
//Guard against modifications to SubscriptionResponseWrapper. Need to ensure that there is
104
105
//compatibility with previous versions to enable rolling upgrades. Must develop a strategy for
105
106
//upgrading from older SubscriptionWrapper versions to newer versions.
106
107
throw new UnsupportedVersionException ("SubscriptionResponseWrapper is of an incompatible version." );
107
108
}
108
- final ValueAndTimestamp <V > currentValueWithTimestamp = valueGetter .get (record .key ());
109
+ final ValueAndTimestamp <VLeft > currentValueWithTimestamp = valueGetter .get (record .key ());
109
110
110
111
final long [] currentHash = currentValueWithTimestamp == null ?
111
112
null :
@@ -115,7 +116,7 @@ public void process(final Record<K, SubscriptionResponseWrapper<VO>> record) {
115
116
116
117
//If this value doesn't match the current value from the original table, it is stale and should be discarded.
117
118
if (java .util .Arrays .equals (messageHash , currentHash )) {
118
- final VR result ;
119
+ final VOut result ;
119
120
120
121
if (record .value ().foreignValue () == null && (!leftJoin || currentValueWithTimestamp == null )) {
121
122
result = null ; //Emit tombstone
0 commit comments