File was renamed from src/main/java/com/whyc/webSocket/DevInfSocket.java |
| | |
| | | import com.whyc.dto.DevInfDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.db_user.UserInf; |
| | | import com.whyc.service.DevInfService; |
| | | import com.whyc.service.DevLithiumInfService; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | |
| | | |
| | | /** |
| | | * 设备实时连接信息 |
| | | * 锂电设备实时连接信息 |
| | | */ |
| | | @Component |
| | | @ServerEndpoint(value = "/dinfSocket",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) |
| | | public class DevInfSocket { |
| | | @ServerEndpoint(value = "/devLithiumInf",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) |
| | | public class DevLithiumInfSocket { |
| | | private Session session; |
| | | |
| | | private Thread thread; |
| | | |
| | | private static DevInfService dinfService; |
| | | private static DevLithiumInfService service; |
| | | |
| | | private HttpSession httpSession; |
| | | |
| | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | @Autowired |
| | | public void setDevInfService(DevInfService dinfService) { |
| | | DevInfSocket.dinfService = dinfService; |
| | | public void setService(DevLithiumInfService service) { |
| | | DevLithiumInfSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | |
| | | UserInf user = (UserInf) this.httpSession.getAttribute("user"); |
| | | final int userId = user.getUid(); |
| | | //final int userId = 101; |
| | | thread = new Thread("Thread_DinfSocket") { |
| | | thread = new Thread("Thread_DevLithiumInfSocket") { |
| | | @Override |
| | | public void run() { |
| | | while (runFlag && !isInterrupted()) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | Response res=dinfService.getAllInf(userId, devInfDto); |
| | | Response res=service.getAllInf(userId, devInfDto); |
| | | if (session.isOpen()) { |
| | | //推送信息 |
| | | synchronized (session) { |