bck
Alejandro Acuña
2024-11-11 f1cb4443aede6d4657bdc3396c8914d3a9f4fa93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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");
    }
 
}