了解神功快照概念
问题描述:
我有查询和执行计划,我想利用该快照这样我就可以在接收端恢复并重新开始执行它。了解神功快照概念
- 什么格式应该发送到接收器?
- 如何在接收端恢复?
以下是一些代码,我从西提仓库取。
SiddhiManager siddhiManager = new SiddhiManager();
String query =
"define stream inStream(meta_roomNumber int,meta_temperature double);" +
"from inStream#window(10)[meta_temperature > 50]\n" +
"select *" +
"insert into outStream;";
ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(query);
executionPlanRuntime.start();
SiddhiContext siddhicontext = new SiddhiContext();
context.setSiddhiContext(siddhicontext);
context.setSnapshotService(new SnapshotService(context));
executionPlanRuntime.snapshot();
答
您可以使用PersistenceStore
来保存执行计划的状态(快照)并稍后恢复。请参考以下PersistenceTestCase以获取有关如何使用的。即;
// Create executionPlanRuntime
ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(executionPlan);
// Register Callbacks, InputHandlers
executionPlanRuntime.addCallback("query1", queryCallback);
stream1 = executionPlanRuntime.getInputHandler("Stream1");
// Start executionPlanRuntime
executionPlanRuntime.start();
// Send events
stream1.send(new Object[]{"WSO2", 25.6f, 100});
Thread.sleep(100);
stream1.send(new Object[]{"GOOG", 47.6f, 100});
Thread.sleep(100);
// Persist the state
executionPlanRuntime.persist();
// Shutdown the running execution plan
executionPlanRuntime.shutdown();
// Create new executionPlanRuntime
executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(executionPlan);
// Register Callbacks, InputHandlers
executionPlanRuntime.addCallback("query1", queryCallback);
stream1 = executionPlanRuntime.getInputHandler("Stream1");
// Start executionPlanRuntime
executionPlanRuntime.start();
// Restore to previously persisted state
executionPlanRuntime.restoreLastRevision();
上面提到的方式在本地机器上正常工作。我有过,我现在用的插座做网络发送快照并使其在分布式环境中工作。 –