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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations