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