2017-05-24 72 views
0

我有查詢和執行計劃,我想利用該快照這樣我就可以在接收端恢復並重新開始執行它。瞭解神功快照概念

  1. 什麼格式應該發送到接收器?
  2. 如何在接收端恢復?

以下是一些代碼,我從西提倉庫取。

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(); 

回答

1

您可以使用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(); 
+0

上面提到的方式在本地機器上正常工作。我有過,我現在用的插座做網絡發送快照並使其在分佈式環境中工作。 –