package com.whyc.websocket;
|
|
import com.whyc.config.WebSocketConfig;
|
import com.whyc.dto.Response;
|
import com.whyc.pojo.db_ckpwrdev_data_rt.CKPowerDevHrTestParam;
|
import com.whyc.pojo.db_ckpwrdev_data_rt.CKPowerDevRt;
|
import com.whyc.pojo.db_ckpwrdev_data_rt.CKPowerDevSignal;
|
import com.whyc.service.CKPowerDevHrTestParamService;
|
import com.whyc.service.CKPowerDevRtService;
|
import com.whyc.service.CKPowerDevSignalService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import javax.websocket.*;
|
import javax.websocket.server.ServerEndpoint;
|
import java.io.IOException;
|
|
/**
|
* 测控台核容装置
|
*/
|
@Component
|
@ServerEndpoint(value = "/ckHrTestParam",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class)
|
public class CKHrTestParamSocket {
|
|
private Session session;
|
|
private Thread thread;
|
|
private static CKPowerDevHrTestParamService ckPowerDevHrTestParamService;
|
|
@Autowired
|
public void setCkPowerDevHrTestParamService(CKPowerDevHrTestParamService ckPowerDevHrTestParamService) {
|
CKHrTestParamSocket.ckPowerDevHrTestParamService = ckPowerDevHrTestParamService;
|
}
|
|
@OnOpen
|
public void onOpen(Session session, EndpointConfig config){
|
this.session = session;
|
|
Thread thread = new Thread() {
|
@Override
|
public void run() {
|
try{
|
while (!currentThread().isInterrupted()) {
|
CKPowerDevHrTestParam hrTestParam = ckPowerDevHrTestParamService.get();
|
session.getBasicRemote().sendObject(new Response<>().set(1,hrTestParam,"查询完成"));
|
sleep(4000);
|
}
|
} catch (Exception e) {
|
this.interrupt();
|
}
|
}
|
};
|
thread.start();
|
this.thread = thread;
|
}
|
|
@OnClose
|
public void onClose(CloseReason closeReason) throws IOException {
|
System.err.println("closeReason = " + closeReason);
|
if(session.isOpen()){
|
session.close();
|
}
|
}
|
|
@OnError
|
public void onError(Throwable error) throws IOException {
|
error.printStackTrace();
|
thread.isInterrupted();
|
if(session.isOpen()){
|
session.close();
|
}
|
}
|
}
|