|
|
@ -159,37 +159,26 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
String item = protocol.getItem_code(); |
|
|
|
itemsString.add(item); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Item> itemsMap = new LinkedHashMap(); |
|
|
|
// Map<String, Item> itemsMap = new LinkedHashMap();
|
|
|
|
boolean is_error = false; |
|
|
|
StringBuilder err_message = new StringBuilder(); |
|
|
|
Iterator var6 = itemsString.iterator(); |
|
|
|
|
|
|
|
while (var6.hasNext()) { |
|
|
|
String string = (String) var6.next(); |
|
|
|
|
|
|
|
try { |
|
|
|
Item item = group.addItem(string); |
|
|
|
itemsMap.put(string, item); |
|
|
|
log.trace("添加成功 {}", string); |
|
|
|
} catch (Exception var26) { |
|
|
|
err_message.append(string + ":" + var26.getMessage()); |
|
|
|
if (!is_error) { |
|
|
|
is_error = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.info("开始添加组数据....."); |
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
Map<String, Item> itemMap = group.addItems(itemsString.toArray(new String[itemsString.size()])); |
|
|
|
Set itemSet = new HashSet(itemMap.values()); |
|
|
|
Item[] itemArr = new Item[itemSet.size()]; |
|
|
|
itemSet.toArray(itemArr); |
|
|
|
long end = System.currentTimeMillis(); |
|
|
|
log.info("组数据添加完成.....{},耗时:{}毫秒", itemSet, (end - start)); |
|
|
|
String tag; |
|
|
|
if (is_error) { |
|
|
|
tag = err_message.toString(); |
|
|
|
log.warn("{}:{}", OpcConfig.resource_code, tag); |
|
|
|
} |
|
|
|
|
|
|
|
if (!OpcStartTag.is_run) { |
|
|
|
OpcStartTag.is_run = true; |
|
|
|
} |
|
|
|
|
|
|
|
tag = ""; |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
tag = Thread.currentThread().getName(); |
|
|
@ -202,107 +191,67 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
boolean time_out = false; |
|
|
|
|
|
|
|
while (DeviceOpcSynchronizeAutoRun.isRun) { |
|
|
|
log.info("开始读取组数据....."); |
|
|
|
long begin = System.currentTimeMillis(); |
|
|
|
if (log.isTraceEnabled()) { |
|
|
|
// log.trace("{} 开始计时{}", tag, DateUtl.formatDateTime(new Date()));
|
|
|
|
} |
|
|
|
|
|
|
|
Map<Item, ItemState> itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); |
|
|
|
long end = System.currentTimeMillis(); |
|
|
|
long duration = end - begin; |
|
|
|
if (log.isTraceEnabled()) { |
|
|
|
// log.trace("{} 读取耗时:{}", tag, DateUtl.formatDuring(duration));
|
|
|
|
} |
|
|
|
|
|
|
|
Map<Item, ItemState> itemStatus = group.read(true, itemArr); |
|
|
|
long endRead = System.currentTimeMillis(); |
|
|
|
log.info("读取组数据完成.....,总共读取:{}条,耗时:{}毫秒", itemStatus.size(), (endRead - begin)); |
|
|
|
long duration = endRead - begin; |
|
|
|
if (duration > 1000L) { |
|
|
|
if (!time_out) { |
|
|
|
log.warn("{} 读取超时 : {}", tag, duration); |
|
|
|
} |
|
|
|
|
|
|
|
time_out = true; |
|
|
|
} else { |
|
|
|
time_out = false; |
|
|
|
} |
|
|
|
|
|
|
|
boolean valueAllNotNull = false; |
|
|
|
Set<Item> items = itemStatus.keySet(); |
|
|
|
|
|
|
|
Iterator var18 = items.iterator(); |
|
|
|
if (!var18.hasNext()){ |
|
|
|
log.info("查询到的为空!"); |
|
|
|
} |
|
|
|
|
|
|
|
while (var18.hasNext()) { |
|
|
|
Item item = (Item) var18.next(); |
|
|
|
ItemState itemState = (ItemState) itemStatus.get(item); |
|
|
|
for (Item item : itemStatus.keySet()) { |
|
|
|
ItemState itemState = itemStatus.get(item); |
|
|
|
Object value = OpcUtl.getValue(item, itemState); |
|
|
|
if (value != null) { |
|
|
|
if (value == null) { |
|
|
|
valueAllNotNull = true; |
|
|
|
}else { |
|
|
|
log.info("查询到的值为空"); |
|
|
|
log.info("读取到值为空,设备号:{},健康值:{}", item.getId(), itemState.getQuality()); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
String itemId = item.getId(); |
|
|
|
Object his = accessor_value.getValue(itemId); |
|
|
|
if (!ObjectUtil.equals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { |
|
|
|
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); |
|
|
|
} |
|
|
|
|
|
|
|
if (!UnifiedDataAppService.isEquals(value, his)) { |
|
|
|
OpcItemDto itemDto = this.getItem(itemId); |
|
|
|
if (Boolean.TRUE.equals(itemDto.getNeed_log())) { |
|
|
|
this.logItemChanged(itemId, accessor_value, value, itemDto); |
|
|
|
} |
|
|
|
|
|
|
|
accessor_value.setValue(itemId, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
end = System.currentTimeMillis(); |
|
|
|
if (log.isTraceEnabled()) { |
|
|
|
log.trace("{}", itemsString); |
|
|
|
// log.trace("{} 计算完成耗时{}", tag, DateUtl.formatDuring(end - begin));
|
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond); |
|
|
|
if (this.error_num != 0) { |
|
|
|
this.error_num = 0; |
|
|
|
this.message = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (!valueAllNotNull) { |
|
|
|
int random = (new Random()).nextInt(10) + 1; |
|
|
|
random *= 1000; |
|
|
|
if (this.all_null < 3) { |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn("{} 所有内容都为空,暂定{}s", tag, 5000 + random); |
|
|
|
if (valueAllNotNull) { |
|
|
|
ThreadUtl.sleep(3000L); |
|
|
|
log.info("读取组数据不健康,重新读取......"); |
|
|
|
itemStatus = group.read(true, itemArr); |
|
|
|
for (Item item : itemStatus.keySet()) { |
|
|
|
ItemState itemState = itemStatus.get(item); |
|
|
|
Object value = OpcUtl.getValue(item, itemState); |
|
|
|
if (value == null){ |
|
|
|
log.info("再次读取组数据为空,终止读取,设备号:{}",item.getId()); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) (5000 + random)); |
|
|
|
} else if (this.all_null < 6) { |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn("{} 所有内容都为空,暂定{}s", tag, 30000 + random); |
|
|
|
String itemId = item.getId(); |
|
|
|
Object his = accessor_value.getValue(itemId); |
|
|
|
if (!UnifiedDataAppService.isEquals(value, his)) { |
|
|
|
OpcItemDto itemDto = this.getItem(itemId); |
|
|
|
if (Boolean.TRUE.equals(itemDto.getNeed_log())) { |
|
|
|
this.logItemChanged(itemId, accessor_value, value, itemDto); |
|
|
|
} |
|
|
|
accessor_value.setValue(itemId, value); |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) (30000 + random)); |
|
|
|
} else if (this.all_null < 12) { |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn("{} 所有内容都为空,暂定{}ms", tag, '\uea60' + random); |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) ('\uea60' + random)); |
|
|
|
} else { |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn("{} 所有内容都为空,暂定{}ms", tag, 120000 + random); |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) (120000 + random)); |
|
|
|
} |
|
|
|
|
|
|
|
++this.all_null; |
|
|
|
} else { |
|
|
|
this.all_null = 0; |
|
|
|
} |
|
|
|
end = System.currentTimeMillis(); |
|
|
|
ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond); |
|
|
|
} |
|
|
|
|
|
|
|
log.warn("opc线程停止。。。"); |
|
|
@ -310,7 +259,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
} catch (Exception var27) { |
|
|
|
if (this.server != null) { |
|
|
|
try { |
|
|
|
this.server.disconnect(); |
|
|
|
this.server.dispose(); |
|
|
|
} catch (Exception var25) { |
|
|
|
} |
|
|
|
} |
|
|
|