Skip to content

Commit 841b62b

Browse files
author
TeemuP
committed
Merge branch 'fix_mem_leek' into kryo-merge
2 parents 84930d2 + 5c9634c commit 841b62b

19 files changed

+554
-140
lines changed

src/main/java/org/opentripplanner/graph_builder/linking/SimpleStreetSplitter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ private SplitterVertex split (StreetEdge edge, LinearLocation ll, boolean tempor
416416
// every edge can be split exactly once, so this is a valid label
417417
SplitterVertex v;
418418
if (temporarySplit) {
419-
v = new TemporarySplitterVertex(graph, "split from " + edge.getId(), splitPoint.x, splitPoint.y,
419+
v = new TemporarySplitterVertex("split from " + edge.getId(), splitPoint.x, splitPoint.y,
420420
edge, endVertex);
421421
if (edge.isWheelchairAccessible()) {
422422
((TemporarySplitterVertex) v).setWheelchairAccessible(true);

src/main/java/org/opentripplanner/routing/core/RoutingContext.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private Set<StreetEdge> overlappingStreetEdges(Vertex u, Vertex v) {
142142
for (Edge e : Iterables.concat(u.getIncoming(), u.getOutgoing())) {
143143
uIds.add(e.getId());
144144
}
145-
145+
146146
// Intesection of edge IDs between u and v.
147147
uIds.retainAll(vIds);
148148
Set<Integer> overlappingIds = uIds;
@@ -230,7 +230,6 @@ private RoutingContext(RoutingRequest routingRequest, Graph graph, Vertex from,
230230
else
231231
this.streetSpeedSnapshot = null;
232232

233-
234233
Edge fromBackEdge = null;
235234
Edge toBackEdge = null;
236235
if (findPlaces) {
@@ -291,7 +290,7 @@ private RoutingContext(RoutingRequest routingRequest, Graph graph, Vertex from,
291290
makePartialEdgeAlong(pse, fromStreetVertex, toStreetVertex);
292291
}
293292
}
294-
293+
295294
if (opt.startingTransitStopId != null) {
296295
Stop stop = graph.index.stopForId.get(opt.startingTransitStopId);
297296
TransitStop tstop = graph.index.stopVertexForStop.get(stop);
@@ -404,10 +403,12 @@ public boolean isWheelchairAccessible(Vertex v) {
404403
}
405404

406405
/**
407-
* Tear down this routing context, removing any temporary edges.
406+
* Tear down this routing context, removing any temporary edges from
407+
* the "permanent" graph objects. This enables all temporary objects
408+
* for garbage collection.
408409
*/
409410
public void destroy() {
410-
if (origin instanceof TemporaryVertex) ((TemporaryVertex) origin).dispose();
411-
if (target instanceof TemporaryVertex) ((TemporaryVertex) target).dispose();
411+
TemporaryVertex.dispose(fromVertex);
412+
TemporaryVertex.dispose(toVertex);
412413
}
413-
}
414+
}

src/main/java/org/opentripplanner/routing/edgetype/OnBoardDepartPatternHop.java

-5
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,4 @@ public Trip getTrip() {
153153
public String getDirection() {
154154
return tripTimes.getHeadsign(stopIndex);
155155
}
156-
157-
@Override
158-
public void dispose() {
159-
tov.removeIncoming(this);
160-
}
161156
}

src/main/java/org/opentripplanner/routing/edgetype/SampleEdge.java

-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ public SampleEdge(Vertex v1, SampleVertex tov, int distance) {
2727
this.length = distance;
2828
}
2929

30-
@Override
31-
public void dispose() {
32-
tov.removeIncoming(this);
33-
fromv.removeOutgoing(this);
34-
}
35-
3630
@Override
3731
/** We want to use exactly the same logic here as is used in propagating to samples */
3832
public State traverse(State s0) {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
package org.opentripplanner.routing.edgetype;
22

33
/** Marker interface for temporary edges */
4-
public interface TemporaryEdge {
5-
public void dispose();
6-
}
4+
public interface TemporaryEdge { }

src/main/java/org/opentripplanner/routing/edgetype/TemporaryFreeEdge.java

+1-15
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,23 @@
44
import org.opentripplanner.routing.vertextype.TemporaryVertex;
55

66
public class TemporaryFreeEdge extends FreeEdge implements TemporaryEdge {
7-
final private boolean endEdge;
87

98
public TemporaryFreeEdge(TemporaryVertex from, Vertex to) {
109
super((Vertex) from, to);
1110

1211
if (from.isEndVertex()) {
1312
throw new IllegalStateException("A temporary edge is directed away from an end vertex");
14-
} else {
15-
endEdge = false;
1613
}
1714
}
1815

1916
public TemporaryFreeEdge(Vertex from, TemporaryVertex to) {
2017
super(from, (Vertex) to);
2118

22-
if (to.isEndVertex()) {
23-
endEdge = true;
24-
} else {
19+
if (!to.isEndVertex()) {
2520
throw new IllegalStateException("A temporary edge is directed towards a start vertex");
2621
}
2722
}
2823

29-
@Override
30-
public void dispose() {
31-
if (endEdge) {
32-
fromv.removeOutgoing(this);
33-
} else {
34-
tov.removeIncoming(this);
35-
}
36-
}
37-
3824
@Override
3925
public String toString() {
4026
return "Temporary" + super.toString();

src/main/java/org/opentripplanner/routing/edgetype/TemporaryPartialStreetEdge.java

+3-27
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44
import org.opentripplanner.routing.location.TemporaryStreetLocation;
55
import org.opentripplanner.routing.vertextype.StreetVertex;
66
import org.opentripplanner.routing.vertextype.TemporarySplitterVertex;
7-
import org.opentripplanner.routing.vertextype.TemporaryVertex;
87
import org.opentripplanner.util.I18NString;
98

109
final public class TemporaryPartialStreetEdge extends PartialStreetEdge implements TemporaryEdge {
11-
final private Boolean endEdge; // A null value means that the vertices are temporary themselves
12-
1310
public TemporaryPartialStreetEdge(StreetEdge parentEdge, TemporaryStreetLocation v1,
1411
TemporaryStreetLocation v2, LineString geometry, I18NString name, double length) {
1512
super(parentEdge, v1, v2, geometry, name, length);
1613

1714
if (v1.isEndVertex()) {
1815
throw new IllegalStateException("A temporary edge is directed away from an end vertex");
19-
} else if (v2.isEndVertex()) {
20-
endEdge = null;
21-
} else {
16+
} else if (!v2.isEndVertex()) {
2217
throw new IllegalStateException("A temporary edge is directed towards a start vertex");
2318
}
2419
}
@@ -29,8 +24,6 @@ public TemporaryPartialStreetEdge(StreetEdge parentEdge, TemporaryStreetLocation
2924

3025
if (v1.isEndVertex()) {
3126
throw new IllegalStateException("A temporary edge is directed away from an end vertex");
32-
} else {
33-
endEdge = false;
3427
}
3528
}
3629

@@ -40,18 +33,14 @@ public TemporaryPartialStreetEdge(StreetEdge parentEdge, TemporarySplitterVertex
4033

4134
if (v1.isEndVertex()) {
4235
throw new IllegalStateException("A temporary edge is directed away from an end vertex");
43-
} else {
44-
endEdge = false;
4536
}
4637
}
4738

4839
public TemporaryPartialStreetEdge(StreetEdge parentEdge, StreetVertex v1,
4940
TemporaryStreetLocation v2, LineString geometry, I18NString name, double length) {
5041
super(parentEdge, v1, v2, geometry, name, length);
5142

52-
if (v2.isEndVertex()) {
53-
endEdge = true;
54-
} else {
43+
if (!v2.isEndVertex()) {
5544
throw new IllegalStateException("A temporary edge is directed towards a start vertex");
5645
}
5746
}
@@ -60,24 +49,11 @@ public TemporaryPartialStreetEdge(StreetEdge parentEdge, StreetVertex v1,
6049
TemporarySplitterVertex v2, LineString geometry, I18NString name, double length) {
6150
super(parentEdge, v1, v2, geometry, name, length);
6251

63-
if (v2.isEndVertex()) {
64-
endEdge = true;
65-
} else {
52+
if (!v2.isEndVertex()) {
6653
throw new IllegalStateException("A temporary edge is directed towards a start vertex");
6754
}
6855
}
6956

70-
@Override
71-
public void dispose() {
72-
if (endEdge != null) {
73-
if (endEdge) {
74-
fromv.removeOutgoing(this);
75-
} else {
76-
tov.removeIncoming(this);
77-
}
78-
}
79-
}
80-
8157
@Override
8258
public String toString() {
8359
return "Temporary" + super.toString();

src/main/java/org/opentripplanner/routing/impl/StreetVertexIndexServiceImpl.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.opentripplanner.routing.impl;
22

33

4-
import com.google.common.collect.Iterables;
54
import com.vividsolutions.jts.geom.Coordinate;
65
import com.vividsolutions.jts.geom.Envelope;
76
import com.vividsolutions.jts.geom.LineString;
@@ -16,8 +15,6 @@
1615
import org.opentripplanner.common.model.P2;
1716
import org.opentripplanner.graph_builder.linking.SimpleStreetSplitter;
1817
import org.opentripplanner.routing.core.RoutingRequest;
19-
import org.opentripplanner.routing.core.TraversalRequirements;
20-
import org.opentripplanner.routing.core.TraverseModeSet;
2118
import org.opentripplanner.routing.edgetype.*;
2219
import org.opentripplanner.routing.graph.Edge;
2320
import org.opentripplanner.routing.graph.Graph;
@@ -29,8 +26,6 @@
2926
import org.opentripplanner.routing.vertextype.StreetVertex;
3027
import org.opentripplanner.routing.vertextype.TransitStop;
3128
import org.opentripplanner.util.I18NString;
32-
import org.opentripplanner.util.NonLocalizedString;
33-
import org.opentripplanner.util.ResourceBundleSingleton;
3429
import org.slf4j.Logger;
3530
import org.slf4j.LoggerFactory;
3631

@@ -121,12 +116,13 @@ public static TemporaryStreetLocation createTemporaryStreetLocation(Graph graph,
121116
I18NString name, Iterable<StreetEdge> edges, Coordinate nearestPoint, boolean endVertex) {
122117
boolean wheelchairAccessible = false;
123118

124-
TemporaryStreetLocation location = new TemporaryStreetLocation(label, nearestPoint, name,
125-
endVertex);
119+
TemporaryStreetLocation location = new TemporaryStreetLocation(label, nearestPoint, name, endVertex);
120+
126121
for (StreetEdge street : edges) {
127122
Vertex fromv = street.getFromVertex();
128123
Vertex tov = street.getToVertex();
129-
wheelchairAccessible |= ((StreetEdge) street).isWheelchairAccessible();
124+
wheelchairAccessible |= street.isWheelchairAccessible();
125+
130126
/* forward edges and vertices */
131127
Vertex edgeLocation;
132128
if (SphericalDistanceLibrary.distance(nearestPoint, fromv.getCoordinate()) < 1) {

src/main/java/org/opentripplanner/routing/location/TemporaryStreetLocation.java

-7
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,4 @@ public void addOutgoing(Edge edge) {
4545
public boolean isEndVertex() {
4646
return endVertex;
4747
}
48-
49-
@Override
50-
public void dispose() {
51-
for (Object temp : endVertex ? getIncoming() : getOutgoing()) {
52-
((TemporaryEdge) temp).dispose();
53-
}
54-
}
5548
}

src/main/java/org/opentripplanner/routing/vertextype/OnboardDepartVertex.java

-7
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,4 @@ public void addOutgoing(Edge edge) {
3535
public boolean isEndVertex() {
3636
return false;
3737
}
38-
39-
@Override
40-
public void dispose() {
41-
for (Object temp : getOutgoing()) {
42-
((TemporaryEdge) temp).dispose();
43-
}
44-
}
4538
}

src/main/java/org/opentripplanner/routing/vertextype/SampleVertex.java

-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ public SampleVertex (Graph g, Coordinate c) {
3939
super(g, null, c, null);
4040
}
4141

42-
@Override
43-
public void dispose() {
44-
for (Object temp : getOutgoing()) {
45-
((TemporaryEdge) temp).dispose();
46-
}
47-
}
48-
4942
@Override
5043
public String getLabel () {
5144
return "sample-" + getIndex();

src/main/java/org/opentripplanner/routing/vertextype/TemporarySplitterVertex.java

+3-22
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class TemporarySplitterVertex extends SplitterVertex implements Temporary
1616

1717
final private boolean endVertex;
1818

19-
public TemporarySplitterVertex(Graph g, String label, double x, double y, StreetEdge streetEdge,
20-
boolean endVertex) {
19+
public TemporarySplitterVertex(String label, double x, double y, StreetEdge streetEdge, boolean endVertex) {
2120
super(null, label, x, y, streetEdge);
2221
this.endVertex = endVertex;
2322
}
@@ -26,27 +25,16 @@ public TemporarySplitterVertex(Graph g, String label, double x, double y, Street
2625
public void addIncoming(Edge edge) {
2726

2827
if (edge instanceof TemporaryEdge) {
29-
if (endVertex) {
30-
super.addIncoming(edge);
31-
} else {
32-
super.addIncoming(edge);
33-
//throw new UnsupportedOperationException("Can't add incoming edge to start vertex");
34-
}
28+
super.addIncoming(edge);
3529
} else {
3630
throw new UnsupportedOperationException("Can't add permanent edge to temporary vertex");
3731
}
3832
}
3933

4034
@Override
4135
public void addOutgoing(Edge edge) {
42-
4336
if (edge instanceof TemporaryEdge) {
44-
if (endVertex) {
45-
super.addOutgoing(edge);
46-
//throw new UnsupportedOperationException("Can't add outgoing edge to end vertex");
47-
} else {
48-
super.addOutgoing(edge);
49-
}
37+
super.addOutgoing(edge);
5038
} else {
5139
throw new UnsupportedOperationException("Can't add permanent edge to temporary vertex");
5240
}
@@ -57,13 +45,6 @@ public boolean isEndVertex() {
5745
return endVertex;
5846
}
5947

60-
@Override
61-
public void dispose() {
62-
for (Object temp : endVertex ? getIncoming() : getOutgoing()) {
63-
((TemporaryEdge) temp).dispose();
64-
}
65-
}
66-
6748
public boolean isWheelchairAccessible() {
6849
return wheelchairAccessible;
6950
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
package org.opentripplanner.routing.vertextype;
22

3-
/** Marker interface for temporary vertices */
3+
import org.opentripplanner.routing.graph.Vertex;
4+
5+
/**
6+
* Marker interface for temporary vertices.
7+
* <p/>
8+
* Remember to use the {@link #dispose(Vertex)} to delete the temporary vertex
9+
* from the main graph after use.
10+
*/
411
public interface TemporaryVertex {
5-
public boolean isEndVertex();
12+
boolean isEndVertex();
613

7-
public void dispose();
14+
/**
15+
* This method traverse the subgraph of temporary vertices, and cuts that subgraph off from the
16+
* main graph at each point it encounters a non-temporary vertexes. OTP then holds no
17+
* references to the temporary subgraph and it is garbage collected.
18+
* <p/>
19+
* Note! If the {@code vertex} is NOT a TemporaryVertex the method returns. No action taken.
20+
*
21+
* @param vertex Vertex part of the temporary part of the graph.
22+
*/
23+
static void dispose(Vertex vertex) {
24+
TemporaryVertexDispose.dispose(vertex);
25+
}
826
}

0 commit comments

Comments
 (0)