use of uk.org.siri.siri20.VehicleActivityCancellationStructure in project OpenTripPlanner by opentripplanner.
the class SiriTimetableSnapshotSource method applyVehicleMonitoring.
/**
* Method to apply a trip update list to the most recent version of the timetable snapshot.
*
* @param graph graph to update (needed for adding/changing stop patterns)
* @param fullDataset true iff the list with updates represent all updates that are active right
* now, i.e. all previous updates should be disregarded
* @param updates SIRI VehicleMonitoringDeliveries that should be applied atomically
*/
public void applyVehicleMonitoring(final Graph graph, final String feedId, final boolean fullDataset, final List<VehicleMonitoringDeliveryStructure> updates) {
if (updates == null) {
LOG.warn("updates is null");
return;
}
// Acquire lock on buffer
bufferLock.lock();
try {
if (fullDataset) {
// Remove all updates from the buffer
buffer.clear(feedId);
}
for (VehicleMonitoringDeliveryStructure vmDelivery : updates) {
ServiceDate serviceDate = new ServiceDate();
List<VehicleActivityStructure> activities = vmDelivery.getVehicleActivities();
if (activities != null) {
// Handle activities
LOG.info("Handling {} VM-activities.", activities.size());
int handledCounter = 0;
int skippedCounter = 0;
for (VehicleActivityStructure activity : activities) {
boolean handled = handleModifiedTrip(graph, feedId, activity, serviceDate);
if (handled) {
handledCounter++;
} else {
skippedCounter++;
}
}
LOG.info("Applied {} VM-activities, skipped {}.", handledCounter, skippedCounter);
}
List<VehicleActivityCancellationStructure> cancellations = vmDelivery.getVehicleActivityCancellations();
if (cancellations != null && !cancellations.isEmpty()) {
// Handle cancellations
LOG.info("TODO: Handle {} cancellations.", cancellations.size());
}
List<NaturalLanguageStringStructure> notes = vmDelivery.getVehicleActivityNotes();
if (notes != null && !notes.isEmpty()) {
// Handle notes
LOG.info("TODO: Handle {} notes.", notes.size());
}
}
// Make sure that the public (locking) getTimetableSnapshot function is not called.
if (purgeExpiredData) {
final boolean modified = purgeExpiredData();
getTimetableSnapshot(modified);
} else {
getTimetableSnapshot(false);
}
} finally {
// Always release lock
bufferLock.unlock();
if (keepLogging) {
LOG.info("Reducing SIRI-VM logging until restart");
keepLogging = false;
}
}
}
Aggregations