2014-10-02 116 views
0

我必須在ESPER中定義下面的類,以便能夠引用子類型和內部數組。我必須務實地做到這一點。我並不怎麼在意:Esper:在語法上定義一個子類型的類型?

UPDATE完整的類

public class IoTEntityEvent implements java.io.Serializable { 

    private IoTProperty[] Properties; 
    private String About; 

    IoTEntityEvent(){ 
     this.About = null; 
     this.Properties = null; 
    } 
    public String getAbout() { 
     return About; 
    } 

    public void setAbout(String value){ 
     this.About = value; 
    } 
    public void setProperties(int index, IoTProperty value) { 
     Properties[index] = value; 
    } 


    public IoTProperty getProperties(int index) { 
     return Properties[index]; 
    } 

    public void setProperties(IoTProperty[] value) { 
     Properties = value; 
    } 


    public IoTProperty[] getProperties() { 
     return Properties; 
    } 
} 

這是子類:

public class IoTProperty implements java.io.Serializable { 
     private Map<String,String>[] IoTStateObservation =null; 
     private String About = null; 

     IoTProperty(){ 
      this.About = null; 
      this.IoTStateObservation = null; 
     } 

     public String getAbout() { 
       return About; 
      } 

     public void setAbout(String value) { 
      About = value; 
     } 


     public Map<String,String>[] getIoTStateObservation() { 
       return IoTStateObservation; 
      } 
     public void setIoTStateObservation(Map<String,String>[] value) { 
      IoTStateObservation = value; 
     } 

     public Map<String,String> getIoTStateObservation(int index) { 
      return IoTStateObservation[index]; 
     } 
     public void setIoTStateObservation(int index, Map<String,String> value) { 
      IoTStateObservation[0] = value; 
     } 
     } 

我想是這樣的:

eventNames[0] = "About"; 
eventType[0] = String.class; 

eventNames[1] = "Properties"; 
eventType[1] = IoTProperty[].class; 

epService.getEPAdministrator().getConfiguration().addEventType("type", eventNames, eventType); 

This works but I ca不能訪問子類型。我也嘗試以類似的方式定義子類型。有人可以解釋我想怎麼做嗎?

回答

0

謝謝你的幫助。我發現瞭如何和是如下:

epService.getEPAdministrator().getConfiguration().addEventType("type",IoTEntityEvent.class); 

那麼事件應發這樣沒有任何鑄造:

IoTValue[] va= {new IoTValue("0.62","2014-06-09T18:08:40.968Z","2014-06-09T18:08:40.968Z")}; 
IoTProperty[] pr = {new IoTProperty(va,"property")}; 
IoTEntityEvent event = new IoTEntityEvent(pr,"Entity"); 
epService.getEPRuntime().sendEvent(event); 
0

你是什麼意思,「這個工程,但我不能訪問子類型。」 嘗試像「選擇屬性[0] .whatever」類型?

+0

這應該是一個評論 – Marco13 2014-10-02 18:53:18

+0

通過它的工作原理就意味着我能夠來查詢它,甚至做屬性[0]。但是當我嘗試做屬性[0]。關於不行。另外,它的工作原理我的意思是在底層對象的返回值包含Properties [0] .About的值,我只是無法在esper中查詢它。 – 2014-10-03 10:55:56

+0

確保您具有小寫屬性。根據JavaBean「getAbout()」是「關於」而不是「關於」。你也可以做一個「admin.getConfiguration()。getEventType(」type「),它返回一個EventType對象,告訴你存在哪些屬性,例如getPropertyNames() – user650839 2014-10-03 14:33:36

0

按照艾斯波文檔:

普通老式Java對象事件對象實例是通過暴露JavaBean風格的getter方法事件屬性。事件類或接口不必完全符合JavaBean規範;但是,對於Esper引擎來獲取事件屬性,必須存在必需的JavaBean getter方法,或者可以通過配置來定義訪問器樣式和訪問器方法。

總之,您需要創建JavaBean獲取器和設置器才能訪問您的私有成員。

+0

謝謝你的迴應,我做到了!你可以看到getter和setters – 2014-10-03 10:49:03

+0

你需要有一個方法「public Property [] getProperties(){return properties; }「,以符合JavaBean。你應該能夠像esper中的」event.properties [x]「一樣訪問它們。 – xpa1492 2014-10-03 13:04:05

相關問題