|
|
@ -8,6 +8,7 @@ import org.nl.modules.udw.UnifiedDataAccessor; |
|
|
|
import org.nl.modules.udw.UnifiedDataAccessorFactory; |
|
|
|
import org.nl.modules.udw.UnifiedDataAppService; |
|
|
|
import org.openscada.opc.lib.da.*; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
@ -26,6 +27,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
private int all_null; |
|
|
|
private Map<String, OpcItemDto> itemSearchCache; |
|
|
|
|
|
|
|
|
|
|
|
public DeviceOpcProtocolRunable() { |
|
|
|
this.error_num = 0; |
|
|
|
this.all_null = 0; |
|
|
@ -87,13 +89,14 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
if (this.group != null) { |
|
|
|
group.clear(); |
|
|
|
group.remove(); |
|
|
|
log.trace("{} 清理group{}"); |
|
|
|
log.trace("清理group..."); |
|
|
|
} |
|
|
|
if (this.server != null) { |
|
|
|
server.disconnect(); |
|
|
|
log.trace("{} server{}"); |
|
|
|
log.trace("清理server..."); |
|
|
|
} |
|
|
|
|
|
|
|
// group =opcServerService.getServer(this.getOpcServer().getOpc_code());
|
|
|
|
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); |
|
|
|
this.server.addStateListener(this); |
|
|
|
group = this.server.addGroup(); |
|
|
@ -186,6 +189,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
Object his = accessor_value.getValue(itemId); |
|
|
|
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { |
|
|
|
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); |
|
|
|
valueAllNotNull = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!UnifiedDataAppService.isEquals(value, his)) { |
|
|
@ -193,8 +197,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
if (true) { |
|
|
|
this.logItemChanged(itemId, accessor_value, value, itemDto); |
|
|
|
} |
|
|
|
|
|
|
|
accessor_value.setValue(itemId, value); |
|
|
|
if(!ObjectUtil.isEmpty(value)){ |
|
|
|
accessor_value.setValue(itemId, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -214,18 +219,31 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
int random = (new Random()).nextInt(10) + 1; |
|
|
|
random *= 1000; |
|
|
|
if (this.all_null < 3) { |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random); |
|
|
|
ThreadUtl.sleep((long) (5000 + random)); |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random); |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000); |
|
|
|
break start; |
|
|
|
} else if (this.all_null < 6) { |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,30000 + random); |
|
|
|
ThreadUtl.sleep((long) (1000 + random)); |
|
|
|
log.warn("重新创建server"); |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn(tag + "重新创建server"); |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,30000 + random); |
|
|
|
} |
|
|
|
// ThreadUtl.sleep((long) (30000 + random));
|
|
|
|
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000); |
|
|
|
break start; |
|
|
|
} else if (this.all_null < 12) { |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, '\uea60' + random); |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, '\uea60' + random); |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) ('\uea60' + random)); |
|
|
|
} else { |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 120000 + random); |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 120000 + random); |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) (120000 + random)); |
|
|
|
} |
|
|
|
|
|
|
@ -364,10 +382,19 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key); |
|
|
|
accessor_value.setValue(itemId, value); |
|
|
|
|
|
|
|
// if (value != null) {
|
|
|
|
// if (log.isTraceEnabled()) {
|
|
|
|
// log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()});
|
|
|
|
// }
|
|
|
|
// } else if (log.isInfoEnabled()) {
|
|
|
|
// log.info("Item {} new value: {}, Timestamp: {}, Quality: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime(), itemState.getQuality()});
|
|
|
|
// }
|
|
|
|
log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()}); |
|
|
|
|
|
|
|
OpcItemDto itemDto = this.getItem(itemId); |
|
|
|
|
|
|
|
// if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
|
|
|
|
// this.logItemChanged(itemId, accessor_value, value, itemDto);
|
|
|
|
// }
|
|
|
|
this.logItemChanged(itemId, accessor_value, value, itemDto); |
|
|
|
|
|
|
|
} catch (Exception var7) { |
|
|
@ -388,14 +415,11 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
Object obj = accessor_value.getValue(relate); |
|
|
|
sb.append("key:" + relate + "value:" + obj + ";"); |
|
|
|
} |
|
|
|
if(!itemId.endsWith("heartbeat") || !itemId.endsWith("time") ) { |
|
|
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb}); |
|
|
|
} |
|
|
|
|
|
|
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb}); |
|
|
|
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{};信号快照:{}", new Object[]{itemId, his, value, sb});
|
|
|
|
} else { |
|
|
|
if(!itemId.endsWith("heartbeat") || !itemId.endsWith("time") ) { |
|
|
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value}); |
|
|
|
} |
|
|
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value}); |
|
|
|
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{}", new Object[]{itemId, his, value});
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|