Skip to content

Commit

Permalink
use an enum to specify the request source
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Dec 19, 2024
1 parent 07c8964 commit 082dafb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ public RaptorTransferIndex(

/**
* Create an index to be put into the transfer cache
*
* @param isRuntimeRequest true if the request originates from the client during the runtime,
* false if the request comes from transferCacheRequests in router-config.json
*/
public static RaptorTransferIndex create(
List<List<Transfer>> transfersByStopIndex,
StreetSearchRequest request,
boolean isRuntimeRequest
RequestSource requestSource
) {
var forwardTransfers = new ArrayList<List<RaptorTransfer>>(transfersByStopIndex.size());
var reversedTransfers = new ArrayList<List<RaptorTransfer>>(transfersByStopIndex.size());
Expand All @@ -49,7 +46,7 @@ public static RaptorTransferIndex create(
var stopIndices = IntStream.range(0, transfersByStopIndex.size());
// we want to always parallelize the cache building during the startup
// and only parallelize during runtime requests if the feature flag is on
if (!isRuntimeRequest || OTPFeature.ParallelRouting.isOn()) {
if (requestSource == RequestSource.CONFIG || OTPFeature.ParallelRouting.isOn()) {
stopIndices = stopIndices.parallel();
}
stopIndices.forEach(fromStop -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.opentripplanner.routing.algorithm.raptoradapter.transit;

public enum RequestSource {
/**
* The request comes from transferCacheRequests in router-config.json
*/
CONFIG,
/**
* The request comes from a client routing request
*/
RUNTIME,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.RaptorTransferIndex;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.RequestSource;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.Transfer;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.api.request.StreetMode;
Expand Down Expand Up @@ -39,7 +40,7 @@ public void put(List<List<Transfer>> transfersByStopIndex, RouteRequest request)
final RaptorTransferIndex raptorTransferIndex = RaptorTransferIndex.create(
transfersByStopIndex,
cacheKey.request,
false
RequestSource.CONFIG
);

LOG.info("Initializing cache with request: {}", cacheKey.options);
Expand All @@ -59,7 +60,11 @@ private CacheLoader<CacheKey, RaptorTransferIndex> cacheLoader() {
@Override
public RaptorTransferIndex load(CacheKey cacheKey) {
LOG.info("Adding runtime request to cache: {}", cacheKey.options);
return RaptorTransferIndex.create(cacheKey.transfersByStopIndex, cacheKey.request, true);
return RaptorTransferIndex.create(
cacheKey.transfersByStopIndex,
cacheKey.request,
RequestSource.RUNTIME
);
}
};
}
Expand Down

0 comments on commit 082dafb

Please sign in to comment.