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