Search in sources :

Example 1 with VehicleMonitoringDeliveryStructure

use of uk.org.siri.siri20.VehicleMonitoringDeliveryStructure in project onebusaway-application-modules by camsys.

the class VehicleMonitoringV2Action method generateSiriResponse.

/**
 * Generate a siri response for a set of VehicleActivities
 */
private Siri generateSiriResponse(List<VehicleActivityStructure> activities, List<AgencyAndId> routeIds, Exception error, long currentTimestamp) {
    VehicleMonitoringDeliveryStructure vehicleMonitoringDelivery = new VehicleMonitoringDeliveryStructure();
    vehicleMonitoringDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(currentTimestamp));
    ServiceDelivery serviceDelivery = new ServiceDelivery();
    serviceDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(currentTimestamp));
    serviceDelivery.getVehicleMonitoringDelivery().add(vehicleMonitoringDelivery);
    if (error != null) {
        ServiceDeliveryErrorConditionStructure errorConditionStructure = new ServiceDeliveryErrorConditionStructure();
        ErrorDescriptionStructure errorDescriptionStructure = new ErrorDescriptionStructure();
        errorDescriptionStructure.setValue(error.getMessage());
        OtherErrorStructure otherErrorStructure = new OtherErrorStructure();
        otherErrorStructure.setErrorText(error.getMessage());
        errorConditionStructure.setDescription(errorDescriptionStructure);
        errorConditionStructure.setOtherError(otherErrorStructure);
        vehicleMonitoringDelivery.setErrorCondition(errorConditionStructure);
    } else {
        Calendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTimeInMillis(currentTimestamp);
        gregorianCalendar.add(Calendar.MINUTE, 1);
        vehicleMonitoringDelivery.setValidUntil(DateUtil.toXmlGregorianCalendar(gregorianCalendar.getTimeInMillis()));
        vehicleMonitoringDelivery.getVehicleActivity().addAll(activities);
        _serviceAlertsHelper.addSituationExchangeToServiceDelivery(serviceDelivery, activities, _transitDataService, routeIds);
        _serviceAlertsHelper.addGlobalServiceAlertsToServiceDelivery(serviceDelivery, _realtimeService);
    }
    Siri siri = new Siri();
    siri.setServiceDelivery(serviceDelivery);
    return siri;
}
Also used : OtherErrorStructure(uk.org.siri.siri_2.OtherErrorStructure) VehicleMonitoringDeliveryStructure(uk.org.siri.siri_2.VehicleMonitoringDeliveryStructure) ServiceDeliveryErrorConditionStructure(uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Siri(uk.org.siri.siri_2.Siri) ServiceDelivery(uk.org.siri.siri_2.ServiceDelivery) ErrorDescriptionStructure(uk.org.siri.siri_2.ErrorDescriptionStructure)

Example 2 with VehicleMonitoringDeliveryStructure

use of uk.org.siri.siri20.VehicleMonitoringDeliveryStructure 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)

Example 3 with VehicleMonitoringDeliveryStructure

use of uk.org.siri.siri20.VehicleMonitoringDeliveryStructure in project OpenTripPlanner by opentripplanner.

the class SiriVMUpdater method runPolling.

/**
 * Repeatedly makes blocking calls to an UpdateStreamer to retrieve new stop time updates, and
 * applies those updates to the graph.
 */
@Override
public void runPolling() {
    boolean moreData = false;
    do {
        // Get update lists from update source
        Siri updates = updateSource.getUpdates();
        if (updates != null) {
            boolean fullDataset = updateSource.getFullDatasetValueOfLastUpdates();
            ServiceDelivery serviceDelivery = updates.getServiceDelivery();
            // Use isTrue in case isMoreData returns null. Mark this updater as primed after last page of updates.
            // Copy moreData into a final primitive, because the object moreData persists across iterations.
            moreData = BooleanUtils.isTrue(serviceDelivery.isMoreData());
            final boolean markPrimed = !moreData;
            List<VehicleMonitoringDeliveryStructure> vmds = serviceDelivery.getVehicleMonitoringDeliveries();
            if (vmds != null) {
                updaterManager.execute(graph -> {
                    snapshotSource.applyVehicleMonitoring(graph, feedId, fullDataset, vmds);
                    if (markPrimed)
                        primed = true;
                });
            }
        }
    } while (moreData);
}
Also used : VehicleMonitoringDeliveryStructure(uk.org.siri.siri20.VehicleMonitoringDeliveryStructure) Siri(uk.org.siri.siri20.Siri) ServiceDelivery(uk.org.siri.siri20.ServiceDelivery)

Aggregations

VehicleMonitoringDeliveryStructure (uk.org.siri.siri20.VehicleMonitoringDeliveryStructure)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)1 NaturalLanguageStringStructure (uk.org.siri.siri20.NaturalLanguageStringStructure)1 ServiceDelivery (uk.org.siri.siri20.ServiceDelivery)1 Siri (uk.org.siri.siri20.Siri)1 VehicleActivityCancellationStructure (uk.org.siri.siri20.VehicleActivityCancellationStructure)1 VehicleActivityStructure (uk.org.siri.siri20.VehicleActivityStructure)1 ErrorDescriptionStructure (uk.org.siri.siri_2.ErrorDescriptionStructure)1 OtherErrorStructure (uk.org.siri.siri_2.OtherErrorStructure)1 ServiceDelivery (uk.org.siri.siri_2.ServiceDelivery)1 ServiceDeliveryErrorConditionStructure (uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure)1 Siri (uk.org.siri.siri_2.Siri)1 VehicleMonitoringDeliveryStructure (uk.org.siri.siri_2.VehicleMonitoringDeliveryStructure)1