package art.servers.fleetserver.controller;
|
|
import art.library.interop.serialization.Serialization;
|
import art.library.model.devices.Device;
|
import art.library.model.devices.DeviceStatus;
|
import art.library.model.devices.vehicle.Vehicle;
|
import art.library.utils.synchro.Mutex;
|
import art.servers.fleetserver.Shared;
|
import java.util.Arrays;
|
|
|
|
public class ControllerVehicles extends art.servers.controller.Controller
|
{
|
private Mutex mutex = new Mutex();
|
private String name = null;
|
|
public ControllerVehicles()
|
{
|
this.name = "Controller vehicles";
|
this.setName(name);
|
start();
|
}
|
|
|
|
public void run()
|
{
|
Shared.traceInformation(name, "Starting");
|
|
while ((isInterrupted() == false) && (exit == false))
|
{
|
|
// Check timeout vehicles
|
|
try
|
{
|
long timestamp = System.currentTimeMillis();
|
|
Device[] ldevice = Shared.model.getDevices();
|
Vehicle[] lvehicle = Arrays.copyOf(ldevice, ldevice.length, Vehicle[].class);
|
|
for (Vehicle vehicle : lvehicle)
|
{
|
try
|
{
|
Vehicle vehicleclone = Serialization.clone(vehicle);
|
|
if ((timestamp - vehicleclone.getLastTimestampStatusUpdate()) > (vehicleclone.getDeviceInformation().polling * 2 * 1000))
|
{
|
if (vehicleclone.getStatus() != DeviceStatus.STATUS_OFFLINE)
|
{
|
// Vehicle offline
|
|
vehicleclone.setAlarm("alarm_offline", true, timestamp);
|
vehicleclone.getDeviceStatus().status = DeviceStatus.STATUS_OFFLINE;
|
Shared.model.updateDevice(vehicle, vehicleclone);
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
|
|
try
|
{
|
sleep(1000);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
Shared.traceInformation(name, "Finishing");
|
}
|
|
}
|