如何查看Hazelcast Jet Vertex的工作原理?

时间:2017-06-30 09:43:15

标签: java directed-acyclic-graphs hazelcast-jet

我尝试重新编写几周前我写入v0.4的hazelcast Jet 0.3 DAG系统作为将其从批处理更改为流程的第一步。有趣的是,突然之间,我经历了一些奇怪的行为,我无法确定顶点是否按预期工作。试图了解发生了什么,我找不到如何窥视每个顶点的内部工作的选项。有没有办法从它们中获取至少一些错误信息?

为了隔离这个问题,我试图将它简单化为一个非常简单的"从列表中读取,将其映射到地图写入地图" DAG。但是在获得任何东西方面仍然没有成功。

在我愚蠢的例子之下,也许我犯了一个非常简单的错误,一个更有知识的人会马上看到它?

出版商:

// every second via executorservice:
final IStreamMap<Long, List<byte[]>> data = jet.getMap("data");
data.set(jet.getHazelcastInstance().getAtomicLong("key").getAndIncrement(), myByteArray);

分析仪:

jet.getList(key.toString()).addAll((List<byte[]>) jet.getMap("data").get(key));
jet.getMap("data").remove(key);
logger.debug("List {} has size: {}", key, jet.getList(key.toString()).size());

final Vertex sourceDataMap = this.newVertex("sourceDataMap", readList(key.toString())).localParallelism(1);
final Vertex parseByteArrayToMap = this.newVertex("parseByteArrayToMap", map(
    (byte[] e) ->  new AbstractMap.SimpleEntry<>(jet.getHazelcastInstance().getAtomicLong("counter").getAndIncrement(), e)));
final Vertex sinkIntoResultMap = this.newVertex("sinkIntoResultMap", writeMap("result"));

this.edge(between(sourceDataMap, parseByteArrayToMap))
    .edge(between(parseByteArrayToMap,  sinkIntoResultMap));

监听器:

jet.getMap("result").addEntryListener((EntryAddedListener<Long, byte[]>)
       (EntryEvent<Long, byte[]> entryEvent)
           -> logger.debug("Got result: {} at {}",entryEvent.getValue().length, System.currentTimeMillis())
       , true);

数据生成工作正常,一切正常,直到DAG接管......但没有错误消息或来自DAG的任何内容。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

在这里,您的代码稍微清理一下,对我有效:

private boolean isActive;

public void onStart(){
    super.onStart();
    isActive = true;
    continuousCameraChange(your_camera)
}

public void onResume(){
    super.onResume();
    isActive = true;
    continuousCameraChange(your_camera)
}

public void onPause(){
    super.onPause();
    isActive = false;
}


public void onDestroy(){
    super.onDestroy();
    isActive = false;
}


public void onStop(){
    super.onStop();
    isActive = false;
}

private void continuousCameraChange(Camera camera){
    do{
        switchCamera(camera);
    }while(isActive);
}

private void switchCamera(Camera camera){
    if (Camera.CameraInfo.facing == CAMERA_FACING_BACK){
        try{
            Thread.sleep(2000);
            camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
        }catch(InterruptedException ex){
            Thread.currentThread().interrupt();
        }
        //change your camera
        Camera.CameraInfo.facing == CAMERA_FACING_FRONT;
    }else{
        try{//change 2000 to change the time for which your camera stays available
            Thread.sleep(2000);
            camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
        }catch(InterruptedException ex){
            Thread.currentThread().interrupt();
        }
        //change your camera
        Camera.CameraInfo.facing == CAMERA_FACING_BACK;
    }
}

在控制台中我看到:

public class Main {
    public static void main(String[] args) throws Exception {
        JetInstance jet = Jet.newJetInstance();
        try {
            HazelcastInstance hz = jet.getHazelcastInstance();
            ILogger logger = hz.getLoggingService().getLogger("a");

            // every second via executorservice:
            final IStreamMap<Long, List<byte[]>> data = jet.getMap("data");
            List<byte[]> myByteArray = asList(new byte[1], new byte[2]);
            IAtomicLong keyGen = hz.getAtomicLong("key");
            Long key = keyGen.getAndIncrement();
            data.set(key, myByteArray);

            String stringKey = key.toString();
            hz.getList(stringKey).addAll((List<byte[]>) jet.getMap("data").get(key));
            jet.getMap("data").remove(key);
            logger.severe(String.format("List %s has size: %d", key, jet.getList(stringKey).size()));

            hz.getMap("result").addEntryListener((EntryAddedListener<Long, byte[]>)
                    (EntryEvent<Long, byte[]> entryEvent) -> logger.severe(String.format(
                            "Got result: %d at %d", entryEvent.getValue().length, System.currentTimeMillis())),
                    true);

            DAG dag = new DAG();
            Vertex sourceDataMap = dag.newVertex("sourceDataMap", readList(stringKey)).localParallelism(1);
            Vertex parseByteArrayToMap = dag.newVertex("parseByteArrayToMap", map(
                    (byte[] e) -> entry(randomUUID(), e)));
            Vertex sinkIntoResultMap = dag.newVertex("sinkIntoResultMap", writeMap("result"));

            dag.edge(between(sourceDataMap, parseByteArrayToMap))
               .edge(between(parseByteArrayToMap, sinkIntoResultMap));

            jet.newJob(dag).execute().get();
            Thread.sleep(1000);
        } finally {
            Jet.shutdownAll();
        }
    }
}