com.datatorrent.lib.stream.StreamDuplicater Maven / Gradle / Ivy
/**
* 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 com.datatorrent.lib.stream;
import com.datatorrent.api.DefaultInputPort;
import com.datatorrent.api.DefaultOutputPort;
import com.datatorrent.api.annotation.Stateless;
import com.datatorrent.lib.util.BaseKeyOperator;
/**
* An implementation of BaseKeyValueOperator that duplicates an input stream as is into two output streams.
*
* Duplication is needed to allow separation of listeners into two streams with different properties (for example
* inline vs in-rack)
* This is a pass through operator
*
* Port Interface
* data: expects <K>
* out1: emits <K>
* out2: emits <K>
*
* @displayName Stream duplicator
* @category Stream Manipulators
* @tags duplicate
* @since 0.3.2
*/
@Stateless
public class StreamDuplicater extends BaseKeyOperator
{
/**
* Input data port.
*/
public final transient DefaultInputPort data = new DefaultInputPort()
{
/**
* Emits tuple on both streams
*/
@Override
public void process(K tuple)
{
out1.emit(cloneKey(tuple));
out2.emit(cloneKey(tuple));
}
};
/**
* Output port 1 that emits duplicate of input stream.
*/
public final transient DefaultOutputPort out1 = new DefaultOutputPort();
/**
* Output port 2 that emits duplicate of input stream.
*/
public final transient DefaultOutputPort out2 = new DefaultOutputPort();
}