106 lines
2.0 KiB
Java
106 lines
2.0 KiB
Java
package com.muyu.vehicle;
|
|
|
|
import com.muyu.common.ThreadPool;
|
|
import com.muyu.domain.Vehicle;
|
|
import com.muyu.vehicle.model.VehicleData;
|
|
import com.muyu.vehicle.thread.VehicleThread;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Builder;
|
|
import lombok.Data;
|
|
import lombok.NoArgsConstructor;
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
|
import static java.lang.Thread.sleep;
|
|
|
|
/**
|
|
* @author DongZeLiang
|
|
* @version 1.0
|
|
* @description 车辆实例
|
|
* @date 2023/11/16
|
|
*/
|
|
@Data
|
|
@Log4j2
|
|
@Builder
|
|
@NoArgsConstructor
|
|
@AllArgsConstructor
|
|
public class VehicleInstance {
|
|
|
|
/**
|
|
* 车辆
|
|
*/
|
|
private Vehicle vehicle;
|
|
|
|
|
|
/**
|
|
* 实例数据
|
|
*/
|
|
private VehicleData vehicleData;
|
|
|
|
|
|
/**
|
|
* 车辆工作线程
|
|
*/
|
|
private VehicleThread vehicleThread;
|
|
|
|
/**
|
|
* 线程提交回调
|
|
*/
|
|
private ScheduledFuture<?> scheduledFuture;
|
|
|
|
|
|
/***
|
|
* 获取当前车辆VIN
|
|
* @return VIN
|
|
*/
|
|
public String getVin(){
|
|
return this.vehicle.getVin();
|
|
}
|
|
|
|
|
|
/**
|
|
* 初始化线程
|
|
*/
|
|
public void initVehicleThread(){
|
|
VehicleThread vehicleThread = new VehicleThread();
|
|
vehicleThread.setVehicleInstance(this);
|
|
this.setVehicleThread(vehicleThread);
|
|
this.vehicleThread.pause();
|
|
ScheduledFuture<?> scheduledFuture = ThreadPool.submit(vehicleThread);
|
|
this.setScheduledFuture(scheduledFuture);
|
|
log.info("初始化车辆上报模拟线程开始:[{}]", this.getVin());
|
|
}
|
|
|
|
/**
|
|
* 开始上报线程
|
|
*/
|
|
public void startSend(){
|
|
this.vehicleThread.resume();
|
|
}
|
|
|
|
/**
|
|
* 暂停上报线程
|
|
*/
|
|
public void pauseSend(){
|
|
this.vehicleThread.pause();
|
|
}
|
|
|
|
/**
|
|
* 结束发送
|
|
*/
|
|
public void stopSend(){
|
|
this.vehicleThread.stop();
|
|
}
|
|
|
|
/**
|
|
* 取消执行
|
|
*/
|
|
public void cancelExecution(){
|
|
scheduledFuture.cancel(true);
|
|
this.vehicleThread = null;
|
|
this.scheduledFuture = null;
|
|
}
|
|
|
|
}
|