Skip to content

Commit

Permalink
Made code multithread safe. (#1653)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpitre authored Jan 19, 2024
1 parent 86f9484 commit 18952e4
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.mobilitydata.gtfsvalidator.input.DateForValidation;
import org.mobilitydata.gtfsvalidator.input.GtfsInput;
import org.mobilitydata.gtfsvalidator.notice.IOError;
Expand All @@ -51,7 +52,6 @@ public class ValidationRunner {

private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String GTFS_ZIP_FILENAME = "gtfs.zip";
private static NoticeContainer noticeContainer;

private final VersionResolver versionResolver;

Expand Down Expand Up @@ -96,11 +96,11 @@ public Status run(ValidationRunnerConfig config) {
final long startNanos = System.nanoTime();
// Input.
feedLoader.setNumThreads(config.numThreads());
noticeContainer = new NoticeContainer();
NoticeContainer noticeContainer = new NoticeContainer();
GtfsFeedContainer feedContainer;
GtfsInput gtfsInput = null;
try {
gtfsInput = createGtfsInput(config, versionInfo.currentVersion().get());
gtfsInput = createGtfsInput(config, versionInfo.currentVersion().get(), noticeContainer);
} catch (IOException e) {
logger.atSevere().withCause(e).log("Cannot load GTFS feed");
noticeContainer.addSystemError(new IOError(e));
Expand Down Expand Up @@ -311,6 +311,14 @@ public static void exportReport(
*/
public static GtfsInput createGtfsInput(ValidationRunnerConfig config, String validatorVersion)
throws IOException, URISyntaxException {
return createGtfsInput(config, validatorVersion, new NoticeContainer());
}

private static GtfsInput createGtfsInput(
ValidationRunnerConfig config,
String validatorVersion,
@Nonnull NoticeContainer noticeContainer)
throws IOException, URISyntaxException {
URI source = config.gtfsSource();
if (source.getScheme().equals("file")) {
return GtfsInput.createFromPath(Paths.get(source), noticeContainer);
Expand Down

0 comments on commit 18952e4

Please sign in to comment.