最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

obix協(xié)議在java中的配置和使用詳解

 更新時(shí)間:2017年08月29日 10:58:05   作者:失控的嬰兒車  
這篇文章主要給大家介紹了關(guān)于obix協(xié)議在java中的配置和使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。

前言

本文主要給大家介紹的是關(guān)于obix協(xié)議在java中的配置和使用,分享出來(lái)供大家參考學(xué)習(xí),下面話不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹吧。

什么是 oBIX?

簡(jiǎn)單來(lái)講,obix是一種 XML 通訊協(xié)議,使用Http Request/Post方式進(jìn)行數(shù)據(jù)通訊。所有數(shù)據(jù)通過可讀字符進(jìn)行傳送,一個(gè)oBIX對(duì)象可以有唯一的一個(gè)URL識(shí)別。

oBIX的實(shí)現(xiàn)原理

首先數(shù)據(jù)儲(chǔ)存在Niagara的服務(wù)平臺(tái)上,我們需要做的是從Niagara獲取數(shù)據(jù),并且儲(chǔ)存在InfluxDB中。下面是實(shí)現(xiàn)的流程方法。

  • 加粗 Ctrl + B
  • 斜體 Ctrl + I
  • 引用 Ctrl + Q
  • 插入鏈接 Ctrl + L
  • 插入代碼 Ctrl + K
  • 插入圖片 Ctrl + G
  • 提升標(biāo)題 Ctrl + H
  • 有序列表 Ctrl + O
  • 無(wú)序列表 Ctrl + U
  • 橫線 Ctrl + R
  • 撤銷 Ctrl + Z
  • 重做 Ctrl + Y

我們都需要定義哪些類以及變量?

類/接口 名 用途
Calculator
DiscoverEngine 搜索工具
FactorInfo 定義所采集元素的信息
FactorNameDecoderInterface 元素名稱解碼接口
FactorNameDecoderObixUrlImpl
NewValueInterface
NewValueInterfaceImpl
ObixClientMgr
ObixClient
ObixFetcher 循環(huán)抓取obix傳輸?shù)臄?shù)據(jù)

1、遍歷各個(gè)點(diǎn)

2、先遍歷各個(gè)設(shè)備,將相同的typeid的設(shè)備存入同一個(gè)hashmap中

3、開始執(zhí)行主程序,先從數(shù)據(jù)庫(kù)中查詢出項(xiàng)目名稱

4、開始搜索!

public class ObixFetcher implements JobInterface{
 
 //這個(gè)是接口的抽象方法
 public void cycleOnce() {
  //從數(shù)據(jù)庫(kù)中取出項(xiàng)目信息
  List<Project> ps = dao.selectByExample(new ProjectExample());
  //遍歷項(xiàng)目信息,如果項(xiàng)目信息的關(guān)鍵信息不為null
  for(Project p : ps){
   if(p.getObixBaseAddress() != null && p.getObixUsername() != null 
     && p.getObixPassword() != null){
    //開啟探索工具 (應(yīng)該還是一個(gè)內(nèi)部類),將關(guān)鍵項(xiàng)目信息傳入探索工具,
    DiscoverEngine de = new DiscoverEngine(p.getObixBaseAddress(),
      p.getObixUsername(), p.getObixPassword());
    //從build數(shù)據(jù)庫(kù)中將數(shù)據(jù)取出,存入bulidNameToId(同樣還是構(gòu)造方法)
    //從device數(shù)據(jù)庫(kù)中將數(shù)據(jù)取出,存入deviceNumberToId(同樣還是構(gòu)造方法)
    de.setNewValueInterface(new NewValueInterfaceImpl(p.getId(), deviceService, deviceDao, deviceTypeDao, buildDao));
    //return回來(lái)一個(gè)FactorInfo
    de.setFactorNameDecoderInterface(new FactorNameDecoderObixUrlImpl());
    de.run();
   }
  }
 }
}

以下是上文 DiscoverEngine de的構(gòu)造方法

public class DiscoverEngine {
  public DiscoverEngine(String baseUrl, String username, String password){
    this.baseUrl = baseUrl;
    obixClient = new ObixClient(baseUrl, username, password);
  }
}

以下是上文obixClient = new ObixClient(baseUrl, username, password)的構(gòu)造方法

public class ObixClient {
  public ObixClient(String baseUrl, String userName, String password){
    
    this.baseUrl = baseUrl;
    this.userName = userName;
    this.password = password;
    
    init();
  }
  //uri中存放著路由地址,然后傳給session,session會(huì)在后面用到
  private void init() {
    Uri uri = new Uri(baseUrl); 
    session = new ObixSession (uri, userName, password);
  }
}

this就是說(shuō)這個(gè)類的當(dāng)前這個(gè)對(duì)象,也就是構(gòu)造方法產(chǎn)生的對(duì)象。

以下信息好像并沒有用到

public class NewValueInterfaceImpl implements NewValueInterface{
  HashMap<String, Integer> buildNameToId = new HashMap<String, Integer>();
  HashMap<String, Integer> deviceNumberToId = new HashMap<String, Integer>();

  public NewValueInterfaceImpl(Integer projectId, IDeviceManagementService deviceService, DeviceMapper deviceDao, DeviceTypeMapper deviceTypeDao,BuildMapper buildDao) {
    this.deviceDao = deviceDao;
    this.deviceTypeDao = deviceTypeDao;
    this.buildDao = buildDao;
    this.projectId = projectId;
    this.deviceService = deviceService;
    //遍歷數(shù)據(jù)庫(kù)中的建筑,存入map
    List<Build> bs = buildDao.selectByExample(new BuildExample());
    for(Build b : bs){
      buildNameToId.put(b.getName(), b.getId());
    }
    //遍歷數(shù)據(jù)庫(kù)中的設(shè)備,存入map
    List<Device> ds = deviceDao.selectByExample(new DeviceExample());
    for(Device d : ds){
      deviceNumberToId.put(d.getNumber(), d.getId());
    }
  }
}

以上信息好像并沒有用到

接著跑了下面兩個(gè)接口

還沒搞懂什么意思以下

public class DiscoverEngine {
  //此處一直用內(nèi)部類來(lái)實(shí)現(xiàn),上面定義了一個(gè)匿名內(nèi)部類,此處給匿名內(nèi)部類賦值
  public void setNewValueInterface(NewValueInterface inft){
    newValueInterface = inft;
  }
  //同上
  public void setFactorNameDecoderInterface(FactorNameDecoderInterface inft){
    factorNameDecoderInterface = inft;
  }
}

以上

然后開始無(wú)情的 run 起來(lái)這個(gè)搜索工具

public class DiscoverEngine {
  //首先傳進(jìn)來(lái)url地址
  public void run(){
    readUrl(baseUrl);
  }
  
  public void readUrl(String url){
//    System.out.println("processing url " + url);
    //此處用到session方法
    Obj obj = obixClient.read(url);
    if(obj == null){
      return;
    }
    //新建一個(gè)Obj,用于儲(chǔ)存 out 所對(duì)應(yīng)的 value
    Obj outObj = obj.get("out");//此處的out是儲(chǔ)存的值(理解成標(biāo)簽的ID)
    if(outObj != null){
      //如果****那么就新建一個(gè)fi 將項(xiàng)目信息分項(xiàng)保存
      if(this.factorNameDecoderInterface != null){
        FactorInfo fi = factorNameDecoderInterface.decode(obj.getHref().get());
        if(newValueInterface != null && fi != null){
          //如果信息不為空,我們就要準(zhǔn)備存讀出來(lái)的數(shù)了
          newValueInterface.onNewValue(fi, outObj.toString());
        }
      }
    }
    else{
      for(Obj o : obj.list()){
        readUrl(url + o.getHref()); 
      }
    }
  }
}

下面用到了session

public class ObixClient {
    public Obj read(String url){
    try {
      //根據(jù)我們傳進(jìn)去的url中讀出一個(gè)obj,這個(gè)obj如果有value,就返回一個(gè)數(shù),否則就返回地址 />
      Obj obj = session.read(new Uri(url));
      return obj;
    } catch (Exception e) {
      e.printStackTrace();
      
      return null;
    }
  }
}

將URL地址中的信息分項(xiàng)保存

public class FactorNameDecoderObixUrlImpl implements FactorNameDecoderInterface{

  @Override
  public FactorInfo decode(String url) {

    
    String[] tokens = url.split(":")[2].split("\\/");
    //新建一個(gè) 對(duì)象 將url中解析出的信息分享保存到這個(gè)對(duì)象中
    FactorInfo fi = new FactorInfo();
    fi.setDeviceName(tokens[tokens.length - 2]);
    fi.setDeviceTypeName(tokens[tokens.length - 3]);
    fi.setFactorName(tokens[tokens.length - 1]);
    
    
    fi.setBuildName("");
    fi.setFloorName("");
    fi.setProjectName("");
    
    return fi;
  }

}
public class NewValueInterfaceImpl implements NewValueInterface{
  static ConcurrentHashMap<String, Long> dataInfluxTime = new ConcurrentHashMap<String, Long>();
  DeviceMapper deviceDao; 
  IDeviceManagementService deviceService;
  DeviceTypeMapper deviceTypeDao;
  BuildMapper buildDao;
  Integer projectId;
  
  HashMap<String, Integer> buildNameToId = new HashMap<String, Integer>();
  HashMap<String, Integer> deviceNumberToId = new HashMap<String, Integer>();
  
  public NewValueInterfaceImpl(Integer projectId, IDeviceManagementService deviceService, DeviceMapper deviceDao, DeviceTypeMapper deviceTypeDao,BuildMapper buildDao) {
    this.deviceDao = deviceDao;
    this.deviceTypeDao = deviceTypeDao;
    this.buildDao = buildDao;
    this.projectId = projectId;
    this.deviceService = deviceService;
    
    List<Build> bs = buildDao.selectByExample(new BuildExample());
    for(Build b : bs){
      buildNameToId.put(b.getName(), b.getId());
    }
    
    List<Device> ds = deviceDao.selectByExample(new DeviceExample());
    for(Device d : ds){
      deviceNumberToId.put(d.getNumber(), d.getId());
    }
  }

  @Override
  public void onNewValue(FactorInfo fi, String value) {
    
    //先將URL中的設(shè)備名稱信息取出來(lái),然后再取出對(duì)應(yīng)的ID
    String number = fi.getDeviceName();
    Integer deviceId = deviceNumberToId.get(number);
    if(deviceId == null){
      number = fi.getDeviceName();
      Device record = new Device();
      record.setName(number);
      record.setNumber(number);
      record.setProjectId(projectId);
      record.setTypeId(fi.getDeviceTypeId());
      deviceService.insert(record );

      deviceId = record.getId();
      System.out.println("found new device id=" + deviceId + ", name=" + number);
      deviceNumberToId.put(number, deviceId);
    }
    Double val = null;
    //然后將ID存入device中
    Device updateRecord = new Device();
    updateRecord.setId(deviceId);
    //將取出的值也存入device
    try{
      Double d = Double.parseDouble(value);
      updateRecord.setCurrentValue(d.intValue());
      val = d;
    }
    catch(Exception e){
      if(value.equalsIgnoreCase("true")){
        updateRecord.setCurrentValue(1);
        val = 1.0;
      }
      else if(value.equalsIgnoreCase("false")){
        updateRecord.setCurrentValue(0);
        val = 0.0;
      }
    }
    
    if(updateRecord.getCurrentValue() != null){
      deviceDao.updateByPrimaryKeySelective(updateRecord );
    }
    
    //將所得所得數(shù)據(jù)存入influxDB
    try{
      String timeKey = projectId+"_"+deviceId+"_"+fi.getFactorName();
      Long t = dataInfluxTime.get(timeKey);
      if(t == null) t = new Long(0);
      Long now = System.currentTimeMillis();
      if(now - t > 10 * 60 * 1000){
        InfluxDBUtil.insert(projectId, deviceId, convert10Minutes(now), fi.getFactorName(), val);
        dataInfluxTime.put(timeKey, now);
      }
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • SpringBoot?模板模式實(shí)現(xiàn)優(yōu)惠券邏輯的示例代碼

    SpringBoot?模板模式實(shí)現(xiàn)優(yōu)惠券邏輯的示例代碼

    這篇文章主要介紹了SpringBoot?模板模式實(shí)現(xiàn)優(yōu)惠券邏輯,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-08-08
  • Springmvc實(shí)現(xiàn)文件上傳

    Springmvc實(shí)現(xiàn)文件上傳

    這篇文章主要為大家詳細(xì)介紹了Springmvc實(shí)現(xiàn)文件上傳功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • 使用@value注解取不到application.xml配置文件中的值問題

    使用@value注解取不到application.xml配置文件中的值問題

    這篇文章主要介紹了使用@value注解取不到application.xml配置文件中的值問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 解決bufferedReader.readLine()讀到最后發(fā)生阻塞的問題

    解決bufferedReader.readLine()讀到最后發(fā)生阻塞的問題

    這篇文章主要介紹了解決bufferedReader.readLine()讀到最后發(fā)生阻塞的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • jdk中keytool的使用以及如何提取jks文件中的公鑰和私鑰

    jdk中keytool的使用以及如何提取jks文件中的公鑰和私鑰

    JKS文件由公鑰和密鑰構(gòu)成利用Java?Keytool工具生成的文件,它是由公鑰和密鑰構(gòu)成的,下面這篇文章主要給大家介紹了關(guān)于jdk中keytool的使用以及如何提取jks文件中公鑰和私鑰的相關(guān)資料,需要的朋友可以參考下
    2024-03-03
  • 基于java servlet過濾器和監(jiān)聽器(詳解)

    基于java servlet過濾器和監(jiān)聽器(詳解)

    下面小編就為大家?guī)?lái)一篇基于java servlet過濾器和監(jiān)聽器(詳解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2017-10-10
  • 一文教你如何使用AES對(duì)接口參數(shù)進(jìn)行加密

    一文教你如何使用AES對(duì)接口參數(shù)進(jìn)行加密

    這篇文章主要是想為大家介紹一下如何使用AES實(shí)現(xiàn)對(duì)接口參數(shù)進(jìn)行加密,文中的示例代碼簡(jiǎn)潔易懂,具有一定的借鑒價(jià)值,需要的小伙伴可以了解一下
    2023-08-08
  • SpringBoot統(tǒng)一返回格式的方法詳解

    SpringBoot統(tǒng)一返回格式的方法詳解

    今天小編主要是和大家分享一個(gè)讓代碼變得更簡(jiǎn)潔的小技巧:統(tǒng)一返回格式,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2022-08-08
  • IDEA2020 Plugins不能用的解決辦法及Plugins 搜索不了插件的問題

    IDEA2020 Plugins不能用的解決辦法及Plugins 搜索不了插件的問題

    這篇文章主要介紹了IDEA2020 Plugins不能用的解決辦法,文中給大家介紹了Intellij IDEA 2020.1 的Plugins 搜索不了插件,連接超時(shí)的問題,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2020-06-06
  • 利用Spring Data MongoDB持久化文檔數(shù)據(jù)的方法教程

    利用Spring Data MongoDB持久化文檔數(shù)據(jù)的方法教程

    這篇文章主要給大家介紹了關(guān)于利用Spring Data MongoDB持久化文檔數(shù)據(jù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-08-08

最新評(píng)論

浦东新区| 无锡市| 江源县| 龙里县| 怀化市| 霍林郭勒市| 马龙县| 易门县| 伽师县| 阿拉善左旗| 山阳县| 万盛区| 乌恰县| 怀化市| 沈阳市| 泽普县| 纳雍县| 新余市| 沙洋县| 来宾市| 石林| 沭阳县| 呼图壁县| 兴城市| 同德县| 溧水县| 射洪县| 灌云县| 五家渠市| 攀枝花市| 通州市| 屯昌县| 镶黄旗| 秭归县| 大连市| 长泰县| 大邑县| 富平县| 阳春市| 太原市| 广饶县|