fix:解决线程阻塞
This commit is contained in:
@@ -8,27 +8,38 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.AcsConfig;
|
||||
import org.nl.acs.common.base.CommonFinalParam;
|
||||
import org.nl.acs.device.domain.Device;
|
||||
import org.nl.acs.device_driver.conveyor.standard_conveyor_control_with_plcscanner.ItemProtocol;
|
||||
import org.nl.acs.device_driver.one_conveyor.box_subvolumes_conveyor.BoxSubvolumesConveyorDeviceDriver;
|
||||
import org.nl.acs.device_driver.two_conveyor.manipulator_agv_station.ManipulatorAgvStationDeviceDriver;
|
||||
import org.nl.acs.ext.wms.service.AcsToWmsService;
|
||||
import org.nl.acs.instruction.domain.Instruction;
|
||||
import org.nl.acs.instruction.service.InstructionService;
|
||||
import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.opc.OpcServerService;
|
||||
import org.nl.acs.task.enums.ActionTypeEnum;
|
||||
import org.nl.acs.task.enums.AgvActionTypeEnum;
|
||||
import org.nl.acs.task.enums.AgvSystemTypeEnum;
|
||||
import org.nl.acs.utils.CurrentLock;
|
||||
import org.nl.acs.utils.ReadUtil;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.config.lucene.service.LuceneExecuteLogService;
|
||||
import org.nl.config.lucene.service.dto.LuceneLogDto;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* @author zhangjiangwei
|
||||
@@ -48,6 +59,8 @@ public class AgvWaitUtil {
|
||||
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppService;
|
||||
@Autowired
|
||||
private OpcServerService opcServerService;
|
||||
|
||||
@Autowired
|
||||
private LuceneExecuteLogService luceneExecuteLogService;
|
||||
@@ -64,7 +77,27 @@ public class AgvWaitUtil {
|
||||
if (startDevice.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) {
|
||||
manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) startDevice.getDeviceDriver();
|
||||
if (manipulatorAgvStationDeviceDriver.getTo_command() != 2) {
|
||||
manipulatorAgvStationDeviceDriver.writing(2);
|
||||
if (CurrentLock.tryLock(startDeviceCode)){
|
||||
try {
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
String to_command = startDevice.getOpc_server_code() + "." + startDevice.getOpc_plc_code() + "." + startDevice.getDevice_code()
|
||||
+ "." + "to_command";
|
||||
itemMap.put(to_command, 2);
|
||||
ReadUtil.writeAndCheck(itemMap, startDevice.getOpc_server_code());
|
||||
LuceneLogDto logDto1 = LuceneLogDto.builder()
|
||||
.device_code(startDeviceCode)
|
||||
.content("诺宝agv允许取货" + "给点位" + startDeviceCode+"下发电气值2")
|
||||
.build();
|
||||
logDto1.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto1);
|
||||
}finally {
|
||||
CurrentLock.unLock(startDeviceCode);
|
||||
}
|
||||
}else {
|
||||
throw new BadRequestException(startDeviceCode+"当前点位正在执行写操作");
|
||||
}
|
||||
|
||||
// manipulatorAgvStationDeviceDriver.writing(2);
|
||||
}
|
||||
int i = 0;
|
||||
while (true){
|
||||
@@ -167,7 +200,25 @@ public class AgvWaitUtil {
|
||||
if (startDevice.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) {
|
||||
manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) startDevice.getDeviceDriver();
|
||||
if (manipulatorAgvStationDeviceDriver.getTo_command() != 3) {
|
||||
manipulatorAgvStationDeviceDriver.writing(3);
|
||||
if (CurrentLock.tryLock(startDeviceCode)){
|
||||
try {
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
String to_command = startDevice.getOpc_server_code() + "." + startDevice.getOpc_plc_code() + "." + startDevice.getDevice_code()
|
||||
+ "." + "to_command";
|
||||
itemMap.put(to_command, 3);
|
||||
ReadUtil.writeAndCheck(itemMap, startDevice.getOpc_server_code());
|
||||
LuceneLogDto logDto1 = LuceneLogDto.builder()
|
||||
.device_code(startDeviceCode)
|
||||
.content("诺宝agv允许取货" + "给点位" + startDeviceCode+"下发电气值3")
|
||||
.build();
|
||||
logDto1.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto1);
|
||||
}finally {
|
||||
CurrentLock.unLock(startDeviceCode);
|
||||
}
|
||||
}else {
|
||||
throw new BadRequestException(startDeviceCode+"当前点位正在执行写操作");
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
while (true){
|
||||
@@ -269,7 +320,26 @@ public class AgvWaitUtil {
|
||||
if (endDevice.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) {
|
||||
manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) endDevice.getDeviceDriver();
|
||||
if (manipulatorAgvStationDeviceDriver.getTo_command() != 4) {
|
||||
manipulatorAgvStationDeviceDriver.writing(4);
|
||||
if (CurrentLock.tryLock(endDeviceCode)){
|
||||
try {
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
String to_command = endDevice.getOpc_server_code() + "." + endDevice.getOpc_plc_code() + "." + endDevice.getDevice_code()
|
||||
+ "." + "to_command";
|
||||
itemMap.put(to_command, 4);
|
||||
ReadUtil.writeAndCheck(itemMap, endDevice.getOpc_server_code());
|
||||
LuceneLogDto logDto1 = LuceneLogDto.builder()
|
||||
.device_code(endDeviceCode)
|
||||
.content("诺宝agv允许取货" + "给点位" + endDeviceCode+"下发电气值4")
|
||||
.build();
|
||||
logDto1.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto1);
|
||||
}finally {
|
||||
CurrentLock.unLock(endDeviceCode);
|
||||
}
|
||||
}else {
|
||||
throw new BadRequestException(endDeviceCode+"当前点位正在执行写操作");
|
||||
}
|
||||
// manipulatorAgvStationDeviceDriver.writing(4);
|
||||
}
|
||||
int i = 0;
|
||||
while (true){
|
||||
@@ -326,7 +396,26 @@ public class AgvWaitUtil {
|
||||
if (nextDevice.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) {
|
||||
manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) nextDevice.getDeviceDriver();
|
||||
if (manipulatorAgvStationDeviceDriver.getTo_command() != 5) {
|
||||
manipulatorAgvStationDeviceDriver.writing(5);
|
||||
if (CurrentLock.tryLock(endDeviceCode)){
|
||||
try {
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
String to_command = nextDevice.getOpc_server_code() + "." + nextDevice.getOpc_plc_code() + "." + nextDevice.getDevice_code()
|
||||
+ "." + "to_command";
|
||||
itemMap.put(to_command, 5);
|
||||
ReadUtil.writeAndCheck(itemMap, nextDevice.getOpc_server_code());
|
||||
LuceneLogDto logDto1 = LuceneLogDto.builder()
|
||||
.device_code(endDeviceCode)
|
||||
.content("诺宝agv允许取货" + "给点位" + endDeviceCode+"下发电气值5")
|
||||
.build();
|
||||
logDto1.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto1);
|
||||
}finally {
|
||||
CurrentLock.unLock(endDeviceCode);
|
||||
}
|
||||
}else {
|
||||
throw new BadRequestException(endDeviceCode+"当前点位正在执行写操作");
|
||||
}
|
||||
// manipulatorAgvStationDeviceDriver.writing(5);
|
||||
}
|
||||
int i = 0;
|
||||
while (true){
|
||||
|
||||
@@ -30,4 +30,11 @@ public class XianGongAgvController {
|
||||
return new ResponseEntity<>(xianGongAgentService.xgAGVWaitPointRequest(requestParam), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/api/agv/test")
|
||||
@Log("仙工AGV请求取放货")
|
||||
@SaIgnore
|
||||
public ResponseEntity<JSONObject> test() {
|
||||
return new ResponseEntity<>(xianGongAgentService.test(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,4 +128,5 @@ public interface XianGongAgvService {
|
||||
HttpResponse sendOrderSequencesToForklift(Instruction dto, InteractionJsonDTO interactionJsonDTO);
|
||||
|
||||
|
||||
JSONObject test();
|
||||
}
|
||||
|
||||
@@ -26,16 +26,21 @@ import org.nl.acs.instruction.service.InstructionService;
|
||||
import org.nl.acs.instruction.service.dto.InteractionJsonDTO;
|
||||
import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.device.enums.DeviceType;
|
||||
import org.nl.acs.opc.OpcServerService;
|
||||
import org.nl.acs.task.enums.ActionTypeEnum;
|
||||
import org.nl.acs.task.enums.AgvActionTypeEnum;
|
||||
import org.nl.acs.task.enums.AgvSystemTypeEnum;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
import org.nl.acs.task.service.dto.TaskDto;
|
||||
import org.nl.acs.utils.CurrentLock;
|
||||
import org.nl.acs.utils.ReadUtil;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.config.lucene.service.LuceneExecuteLogService;
|
||||
import org.nl.config.lucene.service.dto.LuceneLogDto;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
@@ -69,6 +74,8 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
|
||||
private LuceneExecuteLogService luceneExecuteLogService;
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppservice;
|
||||
@Autowired
|
||||
private OpcServerService opcServerService;
|
||||
|
||||
|
||||
@Autowired
|
||||
@@ -1091,7 +1098,7 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
|
||||
}
|
||||
taskUpdate.setTask_id(instructionDto.getTask_id());
|
||||
instructionService.update(instructionDto);
|
||||
taskserver.update(taskUpdate);
|
||||
taskserver.update1(taskUpdate);
|
||||
}
|
||||
|
||||
|
||||
@@ -1143,6 +1150,26 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject test() {
|
||||
if (CurrentLock.tryLock("CK2037")){
|
||||
try {
|
||||
Device startDevice = deviceAppService.findDeviceByCode("CK2037");
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
String to_command = startDevice.getOpc_server_code() + "." + startDevice.getOpc_plc_code() + "." + startDevice.getDevice_code()
|
||||
+ "." + "to_command";
|
||||
itemMap.put(to_command, 3);
|
||||
ReadUtil.writeAndCheck(itemMap, startDevice.getOpc_server_code());
|
||||
}finally {
|
||||
CurrentLock.unLock("CK2037");
|
||||
}
|
||||
}else {
|
||||
throw new BadRequestException("当前设备正在写");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 追加动作块
|
||||
|
||||
@@ -2248,6 +2248,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
logDto.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto);
|
||||
}
|
||||
this.setPhase(phase);
|
||||
}
|
||||
//上传AGV电量
|
||||
else if (phase == 0x70) {
|
||||
|
||||
@@ -74,7 +74,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Group getServer(String code) {
|
||||
public Group getServer(String code) {
|
||||
synchronized (this.buildLock(code)) {
|
||||
Group group = null;
|
||||
group = (Group) this.groups.get(code);
|
||||
@@ -86,7 +86,6 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
if (!group.isActive()) {
|
||||
break label68;
|
||||
}
|
||||
|
||||
var10000 = group;
|
||||
} catch (JIException var14) {
|
||||
log.error(code, var14);
|
||||
@@ -132,7 +131,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
group = server.addGroup(groupName);
|
||||
} catch (Exception var12) {
|
||||
this.clearServer(code);
|
||||
ThreadUtl.sleep(5000L);
|
||||
ThreadUtl.sleep(1500L);
|
||||
log.warn("获取opc出错重新获取", code, var12);
|
||||
// server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
server = OpcUtl.getServer(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
@@ -239,7 +238,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
} catch (Exception var4) {
|
||||
this.clearServer(code);
|
||||
log.warn("写入出错opc server {} 重新加载", code, var4);
|
||||
ThreadUtl.sleep(3000L);
|
||||
ThreadUtl.sleep(1500L);
|
||||
throw var4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.concurrent.*;
|
||||
*/
|
||||
@Slf4j
|
||||
public class OpcUtl {
|
||||
private static int timeout = 1 * 60 * 1000;
|
||||
private static int timeout = 1 * 10 * 1000;
|
||||
private static String key = "rpc.socketTimeout";
|
||||
|
||||
static {
|
||||
|
||||
@@ -298,6 +298,13 @@ public interface TaskService extends CommonService<Task> {
|
||||
*/
|
||||
void update(TaskDto dto);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param dto /
|
||||
*/
|
||||
void update1(TaskDto dto);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
*
|
||||
|
||||
@@ -877,6 +877,28 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update1(TaskDto dto) {
|
||||
TaskDto entity = this.findById(dto.getTask_id());
|
||||
if (entity == null) {
|
||||
throw new BadRequestException(LangProcess.msg("error_sysAuth"));
|
||||
}
|
||||
|
||||
String currentUsername = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_by(currentUsername);
|
||||
|
||||
Task task = ConvertUtil.convert(dto, Task.class);
|
||||
taskMapper.updateById(task);
|
||||
|
||||
//从缓存中移除任务信息
|
||||
this.removeByCodeFromCache(entity.getTask_code());
|
||||
//向缓存添加任务信息
|
||||
this.addTaskToCache(dto);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(String[] ids) throws Exception {
|
||||
|
||||
@@ -10,7 +10,10 @@ import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
|
||||
import org.nl.acs.device.device_driver.standard_inspect.ItemProtocol;
|
||||
import org.nl.acs.opc.ObjectUtl;
|
||||
import org.nl.acs.opc.OpcServerService;
|
||||
import org.nl.acs.opc.OpcUtl;
|
||||
import org.nl.acs.opc.ThreadUtl;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.opc.service.mapper.OpcMapper;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
@@ -87,6 +90,35 @@ public class ReadUtil {
|
||||
}
|
||||
|
||||
}
|
||||
public static void writeAndCheck(Map<String, Object> strings, String opcServer) {
|
||||
OpcServerService server =SpringContextHolder.getBean(OpcServerService.class);
|
||||
Group group = server.getServer( opcServer);
|
||||
if (group ==null){
|
||||
throw new BadRequestException("write group not has");
|
||||
}
|
||||
System.out.println("-----server对象地址-----"+group.getServer());
|
||||
try {
|
||||
if (!group.isActive()){
|
||||
throw new BadRequestException("write group is not active");
|
||||
}
|
||||
Iterator it = strings.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
String key = (String) it.next();
|
||||
Item byteItem = group.addItem(key);
|
||||
Object o = strings.get(key);
|
||||
if (o == null || "".equals(o)) {
|
||||
break;
|
||||
}
|
||||
WriteRequest write1 = new WriteRequest(byteItem, new JIVariant(o.toString()));
|
||||
List<WriteRequest> list = new ArrayList();
|
||||
list.add(write1);
|
||||
OpcUtl.writeValue(group, (WriteRequest[]) list.toArray(new WriteRequest[0]));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
server.clearServer(opcServer);
|
||||
throw new BadRequestException("group write error:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static JSONArray getReadableItemDtos() {
|
||||
List<ItemDto> list = ItemProtocol.getReadableItemDtos();
|
||||
|
||||
Reference in New Issue
Block a user