GpsOfflineMonitorThread.java 967 Bytes
package com.bsth.vehicle.gpsdata;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer;
import com.bsth.vehicle.gpsdata.entity.GpsRealData;

/**
 * 
 * @ClassName: GpsOfflineMonitorThread 
 * @Description: TODO(GPS 掉线监控) 
 * @author PanZhao
 * @date 2016年7月29日 上午1:03:29 
 *
 */
@Component
public class GpsOfflineMonitorThread extends Thread{

	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Override
	public void run() {
		
		long t = System.currentTimeMillis();
		Collection<GpsRealData> allGps = GpsRealDataBuffer.allGps();
		
		for(GpsRealData gps : allGps){
			if(t - gps.getTimestamp() 
					> GpsRealDataBuffer.OFFLINE_TIME && gps.isOnline()){
				gps.setOnline(false);
				logger.info("设备:" + gps.getDeviceId() + " 掉线");
			}
		}
	}
}