blob: 146df1c1a5870a0decff586378060b2eee073cd2 [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.HashMap;
import java.util.Map;
import java.util.Random;
import com.datatorrent.api.DefaultOutputPort;
import com.datatorrent.api.InputOperator;
import com.datatorrent.api.Context.OperatorContext;
/**
* Input port operator for generating random values on key, tuples are HashMap for key/values.<br>
* Key(s) : key1, key2, key3, key4, key5. <br>
*
* @since 0.3.2
*/
public class RandomKeyValMap implements InputOperator
{
public final transient DefaultOutputPort<Map<String, Integer>> outport = new DefaultOutputPort<Map<String, Integer>>();
private Random random = new Random(11111);
@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()
{
HashMap<String, Integer> map = new HashMap<String, Integer>();
Integer val = new Integer(Math.abs(random.nextInt()) % 100);
Integer val1 = new Integer(Math.abs(random.nextInt()) % 100);
map.put(val.toString(), val1);
outport.emit(map);
try
{
Thread.sleep(500);
} catch(Exception e) {
}
}
}