kafka To 源码

  • 2022-10-20
  • 浏览 (226)

kafka To 代码

文件路径:/streams/src/main/java/org/apache/kafka/streams/processor/To.java

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.kafka.streams.processor;

import java.util.Objects;

/**
 * This class is used to provide the optional parameters when sending output records to downstream processor
 * using {@link ProcessorContext#forward(Object, Object, To)}.
 */
public class To {
    protected String childName;
    protected long timestamp;

    private To(final String childName,
               final long timestamp) {
        this.childName = childName;
        this.timestamp = timestamp;
    }

    protected To(final To to) {
        this(to.childName, to.timestamp);
    }

    protected void update(final To to) {
        childName = to.childName;
        timestamp = to.timestamp;
    }

    /**
     * Forward the key/value pair to one of the downstream processors designated by the downstream processor name.
     * @param childName name of downstream processor
     * @return a new {@link To} instance configured with {@code childName}
     */
    public static To child(final String childName) {
        return new To(childName, -1);
    }

    /**
     * Forward the key/value pair to all downstream processors
     * @return a new {@link To} instance configured for all downstream processor
     */
    public static To all() {
        return new To(null, -1);
    }

    /**
     * Set the timestamp of the output record.
     * @param timestamp the output record timestamp
     * @return itself (i.e., {@code this})
     */
    public To withTimestamp(final long timestamp) {
        this.timestamp = timestamp;
        return this;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final To to = (To) o;
        return timestamp == to.timestamp &&
            Objects.equals(childName, to.childName);
    }

    /**
     * Equality is implemented in support of tests, *not* for use in Hash collections, since this class is mutable.
     */
    @Override
    public int hashCode() {
        throw new UnsupportedOperationException("To is unsafe for use in Hash collections");
    }

    @Override
    public String toString() {
        return "To{" +
               "childName='" + childName + '\'' +
               ", timestamp=" + timestamp +
               '}';
    }
}

相关信息

kafka 源码目录

相关文章

kafka AbstractProcessor 源码

kafka BatchingStateRestoreCallback 源码

kafka Cancellable 源码

kafka CommitCallback 源码

kafka ConnectedStoreProvider 源码

kafka ExtractRecordMetadataTimestamp 源码

kafka FailOnInvalidTimestamp 源码

kafka LogAndSkipOnInvalidTimestamp 源码

kafka Processor 源码

kafka ProcessorContext 源码

0  赞