1、初始化HAMR
2、实例化一个工作流
3、获取外部数据
4、处理数据
5、把处理完成的数据写到外部数据源
6、绑定
7、关闭
初始化和关闭:
try { HAMR.initialize(); // Put your jobs between initialize and shutdown... } catch(Exception e) { LOG.error("Caught Exception",e); } finally { HAMR.shutdown(); }
final Workflow workflow = new Workflow();
(1)绑定数据输入源(数据源也是一个节点)
final FileResourceReader<Long,String> reader = new FileResourceReader<>(args[0]); workflow.add(reader);(2)绑定数据输出端(输出端也是也是一个节点)
final FileResourceWriter<String,Integer> writer = new FileResourceWriter<>(args[1]); workflow.add(writer);(3)绑定处理节点(HAMR称处理节点为Flowlet)
final NumberStore<String,Integer> store = new NumberStore<>(String.class,Integer.class); final Transform<Long,String,String,Integer> transform = new Transform<Long,String,String,Integer>() { @Override protected void apply(Long key, String value, Flow flow) throws IOException { flow.push(value,Integer.valueOf(1)); } }; workflow.add(store, transform);(4)各个节点之间的绑定
reader.bindPush(transform).synchronous(); transform.bindPush(store.sum()); store.bindPush(writer);.synchronous();(5)工作流执行
workflow.execute();