Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PathService implementations that used to take an SPTService object in…
… their constructor now take a SPTServiceFactory instead, which is used to instantiate a new PathService every time getPath() is called. As instances of SPTService could contain algorithm state, PathService using the same instance across simultaneous calls to getPath wasn't threadsafe
- Loading branch information
Showing
12 changed files
with
97 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/org/opentripplanner/routing/impl/GenericAStarFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.opentripplanner.routing.impl; | ||
|
||
import org.opentripplanner.routing.algorithm.GenericAStar; | ||
import org.opentripplanner.routing.services.SPTService; | ||
import org.opentripplanner.visualizer.VisualTraverseVisitor; | ||
|
||
public class GenericAStarFactory implements SPTServiceFactory{ | ||
|
||
private VisualTraverseVisitor traverseVisitor=null; | ||
|
||
@Override | ||
public SPTService instantiate() { | ||
GenericAStar ret = new GenericAStar(); | ||
if(traverseVisitor!=null){ | ||
ret.setTraverseVisitor(traverseVisitor); | ||
} | ||
return ret; | ||
} | ||
|
||
public void setTraverseVisitor(VisualTraverseVisitor visitor) { | ||
this.traverseVisitor = visitor; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/org/opentripplanner/routing/impl/SPTServiceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.opentripplanner.routing.impl; | ||
|
||
import org.opentripplanner.routing.services.SPTService; | ||
|
||
public interface SPTServiceFactory { | ||
|
||
SPTService instantiate(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,10 @@ | |
import org.opentripplanner.inspector.TileRendererManager; | ||
import org.opentripplanner.routing.algorithm.GenericAStar; | ||
import org.opentripplanner.routing.core.RoutingRequest; | ||
import org.opentripplanner.routing.impl.GenericAStarFactory; | ||
import org.opentripplanner.routing.impl.LongDistancePathService; | ||
import org.opentripplanner.routing.impl.RetryingPathServiceImpl; | ||
import org.opentripplanner.routing.impl.SPTServiceFactory; | ||
import org.opentripplanner.routing.services.GraphService; | ||
import org.opentripplanner.routing.services.PathService; | ||
import org.opentripplanner.routing.services.SPTService; | ||
|
@@ -47,7 +49,7 @@ public class OTPServer { | |
public PathService pathService; | ||
public RoutingRequest routingRequest; // the prototype routing request which establishes default parameter values | ||
public PlanGenerator planGenerator; | ||
public SPTService sptService; | ||
public SPTServiceFactory sptServiceFactory; | ||
|
||
// Optional Analyst Modules | ||
public Renderer renderer; | ||
|
@@ -74,15 +76,15 @@ public OTPServer (CommandLineParameters params, GraphService gs) { | |
// Core OTP modules | ||
graphService = gs; | ||
routingRequest = new RoutingRequest(); | ||
sptService = new GenericAStar(); | ||
sptServiceFactory = new GenericAStarFactory(); | ||
This comment has been minimized.
Sorry, something went wrong.
abyrd
Member
|
||
|
||
// Choose a PathService to wrap the SPTService, depending on expected maximum path lengths | ||
if (params.longDistance) { | ||
LongDistancePathService pathService = new LongDistancePathService(graphService, sptService); | ||
LongDistancePathService pathService = new LongDistancePathService(graphService, sptServiceFactory); | ||
pathService.timeout = 10; | ||
this.pathService = pathService; | ||
} else { | ||
RetryingPathServiceImpl pathService = new RetryingPathServiceImpl(graphService, sptService); | ||
RetryingPathServiceImpl pathService = new RetryingPathServiceImpl(graphService, sptServiceFactory); | ||
pathService.setFirstPathTimeout(10.0); | ||
pathService.setMultiPathTimeout(1.0); | ||
this.pathService = pathService; | ||
|
@@ -96,10 +98,10 @@ public OTPServer (CommandLineParameters params, GraphService gs) { | |
// Optional Analyst Modules. | ||
if (params.analyst) { | ||
tileCache = new TileCache(graphService); | ||
sptCache = new SPTCache(sptService, graphService); | ||
sptCache = new SPTCache(sptServiceFactory, graphService); | ||
renderer = new Renderer(tileCache, sptCache); | ||
sampleGridRenderer = new SampleGridRenderer(graphService, sptService); | ||
isoChroneSPTRenderer = new IsoChroneSPTRendererAccSampling(graphService, sptService, sampleGridRenderer); | ||
sampleGridRenderer = new SampleGridRenderer(graphService, sptServiceFactory); | ||
isoChroneSPTRenderer = new IsoChroneSPTRendererAccSampling(graphService, sptServiceFactory, sampleGridRenderer); | ||
surfaceCache = new SurfaceCache(30); | ||
pointSetCache = new DiskBackedPointSetCache(100, new File(params.pointSetDirectory)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ the License, or (at your option) any later version. | |
import org.opentripplanner.routing.graph.Edge; | ||
import org.opentripplanner.routing.graph.Graph; | ||
import org.opentripplanner.routing.graph.Vertex; | ||
import org.opentripplanner.routing.impl.GenericAStarFactory; | ||
import org.opentripplanner.routing.impl.LongDistancePathService; | ||
import org.opentripplanner.routing.impl.ParetoPathService; | ||
import org.opentripplanner.routing.impl.SPTVisitor; | ||
|
@@ -374,7 +375,7 @@ public String toString(){ | |
|
||
private PathService pathservice; | ||
|
||
private GenericAStar sptService = new GenericAStar(); | ||
private GenericAStarFactory sptServiceFactory = new GenericAStarFactory(); | ||
|
||
private DefaultListModel<String> metadataModel; | ||
|
||
|
@@ -466,7 +467,7 @@ public GraphVisualizer(GraphService graphService) { | |
|
||
this.graphService = graphService; | ||
this.graph = graphService.getGraph(); | ||
this.pathservice = new ParetoPathService(graphService, sptService); | ||
this.pathservice = new ParetoPathService(graphService, sptServiceFactory); | ||
setTitle("GraphVisualizer"); | ||
|
||
init(); | ||
|
@@ -591,7 +592,7 @@ private Container makeMainTab() { | |
// init center graphical panel | ||
showGraph = new ShowGraph(this, getGraph()); | ||
pane.add(showGraph, BorderLayout.CENTER); | ||
sptService.setTraverseVisitor(new VisualTraverseVisitor(showGraph)); | ||
sptServiceFactory.setTraverseVisitor(new VisualTraverseVisitor(showGraph)); | ||
|
||
// init left panel | ||
leftPanel = new JPanel(); | ||
|
@@ -779,9 +780,9 @@ public void itemStateChanged(ItemEvent e) { | |
|
||
protected void setLongDistanceMode(boolean selected) { | ||
if( selected ){ | ||
this.pathservice = new LongDistancePathService(graphService, sptService); | ||
this.pathservice = new LongDistancePathService(graphService, sptServiceFactory); | ||
} else { | ||
this.pathservice = new ParetoPathService(graphService, sptService); | ||
this.pathservice = new ParetoPathService(graphService, sptServiceFactory); | ||
} | ||
|
||
} | ||
|
@@ -1478,9 +1479,9 @@ protected void route(String from, String to) { | |
|
||
// apply callback if the options call for it | ||
if( dontUseGraphicalCallbackCheckBox.isSelected() ){ | ||
sptService.setTraverseVisitor(null); | ||
sptServiceFactory.setTraverseVisitor(null); | ||
} else { | ||
sptService.setTraverseVisitor(new VisualTraverseVisitor(showGraph)); | ||
sptServiceFactory.setTraverseVisitor(new VisualTraverseVisitor(showGraph)); | ||
This comment has been minimized.
Sorry, something went wrong.
abyrd
Member
|
||
} | ||
|
||
// set up a visitor to the path service so we can get the SPT as it's generated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm wary of one-liner source files, and of adding more factory interfaces. It seems much simpler and more readable if the pathservice just looks at the server config or request and instantiates the proper type of SPT or search algorithm as needed, rather than having to specify different components in the proper configuration at startup time. I doubt we're ever going to have more SPT types or search algorithms that can fit in a short conditional.
I think we should just get rid of most of these pluggable service interfaces in OTP, as they are essentially holdovers from Spring. But that's another ticket. This solves the problem for now.