Search in sources :

Example 1 with ServiceDelivery

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

the class SiriSXUpdater method getUpdates.

private Siri getUpdates() {
    long t1 = System.currentTimeMillis();
    long creating = 0;
    long fetching = 0;
    long unmarshalling = 0;
    try {
        String sxServiceRequest = SiriHelper.createSXServiceRequestAsXml(requestorRef);
        creating = System.currentTimeMillis() - t1;
        t1 = System.currentTimeMillis();
        InputStream is = SiriHttpUtils.postData(url, sxServiceRequest, timeout, requestHeaders);
        fetching = System.currentTimeMillis() - t1;
        t1 = System.currentTimeMillis();
        Siri siri = SiriHelper.unmarshal(is);
        unmarshalling = System.currentTimeMillis() - t1;
        if (siri == null) {
            throw new RuntimeException("Failed to get data from url " + url);
        }
        ServiceDelivery serviceDelivery = siri.getServiceDelivery();
        if (serviceDelivery == null) {
            throw new RuntimeException("Failed to get serviceDelivery " + url);
        }
        ZonedDateTime responseTimestamp = serviceDelivery.getResponseTimestamp();
        if (responseTimestamp.isBefore(lastTimestamp)) {
            LOG.info("Ignoring feed with an old timestamp.");
            return null;
        }
        lastTimestamp = responseTimestamp;
        return siri;
    } catch (Exception e) {
        LOG.info("Failed after {} ms", (System.currentTimeMillis() - t1));
        LOG.error("Error reading SIRI feed from " + url, e);
    } finally {
        LOG.info("Updating SX [{}]: Create req: {}, Fetching data: {}, Unmarshalling: {}", requestorRef, creating, fetching, unmarshalling);
    }
    return null;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) InputStream(java.io.InputStream) Siri(uk.org.siri.siri20.Siri) ServiceDelivery(uk.org.siri.siri20.ServiceDelivery)

Example 2 with ServiceDelivery

use of uk.org.siri.siri20.ServiceDelivery 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 3 with ServiceDelivery

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

the class StopMonitoringV2Action method generateSiriResponse.

private Siri generateSiriResponse(List<MonitoredStopVisitStructure> visits, List<AgencyAndId> stopIds, Exception error, long responseTimestamp) {
    StopMonitoringDeliveryStructure stopMonitoringDelivery = new StopMonitoringDeliveryStructure();
    stopMonitoringDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
    ServiceDelivery serviceDelivery = new ServiceDelivery();
    serviceDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
    serviceDelivery.getStopMonitoringDelivery().add(stopMonitoringDelivery);
    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);
        stopMonitoringDelivery.setErrorCondition(errorConditionStructure);
    } else {
        Calendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTimeInMillis(responseTimestamp);
        gregorianCalendar.add(Calendar.MINUTE, 1);
        stopMonitoringDelivery.setValidUntil(DateUtil.toXmlGregorianCalendar(gregorianCalendar.getTimeInMillis()));
        stopMonitoringDelivery.getMonitoredStopVisit().addAll(visits);
        serviceDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
        _serviceAlertsHelper.addSituationExchangeToSiriForStops(serviceDelivery, visits, _transitDataService, stopIds);
        _serviceAlertsHelper.addGlobalServiceAlertsToServiceDelivery(serviceDelivery, _realtimeService);
    }
    Siri siri = new Siri();
    siri.setServiceDelivery(serviceDelivery);
    return siri;
}
Also used : OtherErrorStructure(uk.org.siri.siri_2.OtherErrorStructure) StopMonitoringDeliveryStructure(uk.org.siri.siri_2.StopMonitoringDeliveryStructure) 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 4 with ServiceDelivery

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

Example 5 with ServiceDelivery

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

the class SiriETUpdater 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 {
        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<EstimatedTimetableDeliveryStructure> etds = serviceDelivery.getEstimatedTimetableDeliveries();
            if (etds != null) {
                updaterManager.execute(graph -> {
                    snapshotSource.applyEstimatedTimetable(graph, feedId, fullDataset, etds);
                    if (markPrimed)
                        primed = true;
                });
            }
        }
    } while (moreData);
}
Also used : Siri(uk.org.siri.siri20.Siri) ServiceDelivery(uk.org.siri.siri20.ServiceDelivery) EstimatedTimetableDeliveryStructure(uk.org.siri.siri20.EstimatedTimetableDeliveryStructure)

Aggregations

ServiceDelivery (uk.org.siri.siri20.ServiceDelivery)4 Siri (uk.org.siri.siri20.Siri)4 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 ErrorDescriptionStructure (uk.org.siri.siri_2.ErrorDescriptionStructure)2 OtherErrorStructure (uk.org.siri.siri_2.OtherErrorStructure)2 ServiceDelivery (uk.org.siri.siri_2.ServiceDelivery)2 ServiceDeliveryErrorConditionStructure (uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure)2 Siri (uk.org.siri.siri_2.Siri)2 InputStream (java.io.InputStream)1 ZonedDateTime (java.time.ZonedDateTime)1 EstimatedTimetableDeliveryStructure (uk.org.siri.siri20.EstimatedTimetableDeliveryStructure)1 VehicleMonitoringDeliveryStructure (uk.org.siri.siri20.VehicleMonitoringDeliveryStructure)1 StopMonitoringDeliveryStructure (uk.org.siri.siri_2.StopMonitoringDeliveryStructure)1 VehicleMonitoringDeliveryStructure (uk.org.siri.siri_2.VehicleMonitoringDeliveryStructure)1