Search in sources :

Example 1 with VehicleActivityCancellationStructure

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;
        }
    }
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri20.NaturalLanguageStringStructure) VehicleMonitoringDeliveryStructure(uk.org.siri.siri20.VehicleMonitoringDeliveryStructure) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) VehicleActivityStructure(uk.org.siri.siri20.VehicleActivityStructure) VehicleActivityCancellationStructure(uk.org.siri.siri20.VehicleActivityCancellationStructure)

Aggregations

ServiceDate (org.opentripplanner.model.calendar.ServiceDate)1 NaturalLanguageStringStructure (uk.org.siri.siri20.NaturalLanguageStringStructure)1 VehicleActivityCancellationStructure (uk.org.siri.siri20.VehicleActivityCancellationStructure)1 VehicleActivityStructure (uk.org.siri.siri20.VehicleActivityStructure)1 VehicleMonitoringDeliveryStructure (uk.org.siri.siri20.VehicleMonitoringDeliveryStructure)1