| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.websocket.EncodeException; |
| | | import javax.websocket.OnOpen; |
| | | import javax.websocket.Session; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.PathParam; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.io.IOException; |
| | | import java.security.Principal; |
| | | |
| | | @ServerEndpoint(value = "/deviceWorkState/{deviceId}/{workState}/{uId}",encoders = WebSocketEncoder.class) |
| | | @Component |
| | |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session, @PathParam("deviceId") Integer deviceId, @PathParam("workState") Integer workState, @PathParam("uId") Long uId){ |
| | | thread = new Thread("Thread_batteryData") { |
| | | thread = new Thread("Thread_DeviceWorkState") { |
| | | public void run() { |
| | | while (!thread.isInterrupted()) { |
| | | try { |
| | |
| | | thread.start(); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable error) { |
| | | error.printStackTrace(); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | } |
| | | } |