blob: 2d95385f06b261a142b5509066e7f71d88571701 [file] [log] [blame]
/**
* 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.samples.lib.math;
import java.util.Random;
import com.datatorrent.api.DefaultOutputPort;
import com.datatorrent.api.InputOperator;
import com.datatorrent.api.Context.OperatorContext;
import com.datatorrent.common.util.Pair;
/**
* Input port operator for generating random values Pair for sample application.
*
* @since 0.3.2
*/
public class RandomPairIntegers implements InputOperator
{
public final transient DefaultOutputPort<Pair<Integer, Integer>> outport = new DefaultOutputPort<Pair<Integer, Integer>>();
private Random random = new Random(11111);
private boolean equal = false;
@Override
public void beginWindow(long windowId)
{
// TODO Auto-generated method stub
}
@Override
public void endWindow()
{
// TODO Auto-generated method stub
}
@Override
public void setup(OperatorContext context)
{
// TODO Auto-generated method stub
}
@Override
public void teardown()
{
// TODO Auto-generated method stub
}
@Override
public void emitTuples()
{
if (equal)
{
int val = random.nextInt();
outport.emit(new Pair<Integer, Integer>(new Integer(val),
new Integer(val)));
} else
{
outport.emit(new Pair<Integer, Integer>(new Integer(random.nextInt()),
new Integer(random.nextInt())));
}
equal = !equal;
}
}