Skip to content

Commit 0d4ffa4

Browse files
committed
kryo5 upgrade
1 parent dc980dd commit 0d4ffa4

File tree

13 files changed

+70
-57
lines changed

13 files changed

+70
-57
lines changed

jena-geosparql/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
</dependency>
6666

6767
<dependency>
68-
<groupId>com.esotericsoftware</groupId>
69-
<artifactId>kryo-shaded</artifactId>
68+
<groupId>com.esotericsoftware.kryo</groupId>
69+
<artifactId>kryo5</artifactId>
7070
</dependency>
7171

7272
<!-- Non-free; testing only -->

jena-geosparql/src/main/java/org/apache/jena/geosparql/kryo/EnvelopeSerializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
import org.locationtech.jts.geom.Envelope;
2222

23-
import com.esotericsoftware.kryo.Kryo;
24-
import com.esotericsoftware.kryo.Serializer;
25-
import com.esotericsoftware.kryo.io.Input;
26-
import com.esotericsoftware.kryo.io.Output;
23+
import com.esotericsoftware.kryo.kryo5.Kryo;
24+
import com.esotericsoftware.kryo.kryo5.Serializer;
25+
import com.esotericsoftware.kryo.kryo5.io.Input;
26+
import com.esotericsoftware.kryo.kryo5.io.Output;
2727

2828
public class EnvelopeSerializer extends Serializer<Envelope> {
2929
@Override
@@ -35,7 +35,7 @@ public void write(Kryo kryo, Output output, Envelope envelope) {
3535
}
3636

3737
@Override
38-
public Envelope read(Kryo kryo, Input input, Class<Envelope> type) {
38+
public Envelope read(Kryo kryo, Input input, Class<? extends Envelope> type) {
3939
double xMin = input.readDouble();
4040
double xMax = input.readDouble();
4141
double yMin = input.readDouble();

jena-geosparql/src/main/java/org/apache/jena/geosparql/kryo/GeometrySerializerJtsWkb.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import org.locationtech.jts.io.WKBReader;
2424
import org.locationtech.jts.io.WKBWriter;
2525

26-
import com.esotericsoftware.kryo.Kryo;
27-
import com.esotericsoftware.kryo.Serializer;
28-
import com.esotericsoftware.kryo.io.Input;
29-
import com.esotericsoftware.kryo.io.Output;
26+
import com.esotericsoftware.kryo.kryo5.Kryo;
27+
import com.esotericsoftware.kryo.kryo5.Serializer;
28+
import com.esotericsoftware.kryo.kryo5.io.Input;
29+
import com.esotericsoftware.kryo.kryo5.io.Output;
3030

3131
/** Geometry de-/serialization via the WKB facilities of JTS. */
3232
public class GeometrySerializerJtsWkb
@@ -57,7 +57,7 @@ public void write(Kryo kryo, Output output, Geometry geometry) {
5757
}
5858

5959
@Override
60-
public Geometry read(Kryo kryo, Input input, Class<Geometry> type) {
60+
public Geometry read(Kryo kryo, Input input, Class<? extends Geometry> type) {
6161
byte[] bytes = kryo.readObject(input, byte[].class);
6262
Geometry geometry;
6363
try {

jena-geosparql/src/main/java/org/apache/jena/geosparql/kryo/NodeSerializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
import org.apache.jena.vocabulary.RDFS;
4444
import org.apache.jena.vocabulary.XSD;
4545

46-
import com.esotericsoftware.kryo.Kryo;
47-
import com.esotericsoftware.kryo.Serializer;
48-
import com.esotericsoftware.kryo.io.Input;
49-
import com.esotericsoftware.kryo.io.Output;
46+
import com.esotericsoftware.kryo.kryo5.Kryo;
47+
import com.esotericsoftware.kryo.kryo5.Serializer;
48+
import com.esotericsoftware.kryo.kryo5.io.Input;
49+
import com.esotericsoftware.kryo.kryo5.io.Output;
5050

5151
/**
5252
* An RDF 1.2 node serializer for kryo.
@@ -262,7 +262,7 @@ public void write(Kryo kryo, Output output, Node node) {
262262
}
263263

264264
@Override
265-
public Node read(Kryo kryo, Input input, Class<Node> cls) {
265+
public Node read(Kryo kryo, Input input, Class<? extends Node> cls) {
266266
Node result;
267267
String v1, v2;
268268
Triple t;

jena-geosparql/src/main/java/org/apache/jena/geosparql/kryo/TripleSerializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import org.apache.jena.graph.Node;
2121
import org.apache.jena.graph.Triple;
2222

23-
import com.esotericsoftware.kryo.Kryo;
24-
import com.esotericsoftware.kryo.Serializer;
25-
import com.esotericsoftware.kryo.io.Input;
26-
import com.esotericsoftware.kryo.io.Output;
23+
import com.esotericsoftware.kryo.kryo5.Kryo;
24+
import com.esotericsoftware.kryo.kryo5.Serializer;
25+
import com.esotericsoftware.kryo.kryo5.io.Input;
26+
import com.esotericsoftware.kryo.kryo5.io.Output;
2727

2828
/** Kryo serializer for {@link Triple}. Depends on registered {@link Node} serializers. */
2929
public class TripleSerializer extends Serializer<Triple> {
@@ -35,7 +35,7 @@ public void write(Kryo kryo, Output output, Triple obj) {
3535
}
3636

3737
@Override
38-
public Triple read(Kryo kryo, Input input, Class<Triple> objClass) {
38+
public Triple read(Kryo kryo, Input input, Class<? extends Triple> objClass) {
3939
Node s = (Node)kryo.readClassAndObject(input);
4040
Node p = (Node)kryo.readClassAndObject(input);
4141
Node o = (Node)kryo.readClassAndObject(input);

jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v2/KryoRegistratorSpatialIndexV2.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.HashMap;
2121
import java.util.LinkedHashMap;
2222
import java.util.Map;
23+
import java.util.concurrent.ConcurrentHashMap;
2324

2425
import org.apache.jena.geosparql.kryo.EnvelopeSerializer;
2526
import org.apache.jena.geosparql.kryo.NodeSerializer;
@@ -40,9 +41,9 @@
4041
import org.slf4j.Logger;
4142
import org.slf4j.LoggerFactory;
4243

43-
import com.esotericsoftware.kryo.Kryo;
44-
import com.esotericsoftware.kryo.Serializer;
45-
import com.esotericsoftware.kryo.serializers.MapSerializer;
44+
import com.esotericsoftware.kryo.kryo5.Kryo;
45+
import com.esotericsoftware.kryo.kryo5.Serializer;
46+
import com.esotericsoftware.kryo.kryo5.serializers.MapSerializer;
4647

4748
/**
4849
* The class is used to configure the kryo serialization
@@ -58,10 +59,10 @@ public static void registerClasses(Kryo kryo, Serializer<Geometry> geometrySeria
5859
LOGGER.debug("Registering kryo serializers for spatial index v2.");
5960

6061
// Java
61-
Serializer<?> mapSerializer = new MapSerializer();
62+
Serializer<?> mapSerializer = new MapSerializer<>();
6263
kryo.register(Map.class, mapSerializer);
6364
kryo.register(HashMap.class, mapSerializer);
64-
kryo.register(LinkedHashMap.class, mapSerializer);
65+
kryo.register(ConcurrentHashMap.class, mapSerializer);
6566

6667
// Jena
6768
NodeSerializer.register(kryo);

jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v2/STRtreePerGraphSerializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import org.apache.jena.graph.Node;
2323
import org.locationtech.jts.index.strtree.STRtree;
2424

25-
import com.esotericsoftware.kryo.Kryo;
26-
import com.esotericsoftware.kryo.Serializer;
27-
import com.esotericsoftware.kryo.io.Input;
28-
import com.esotericsoftware.kryo.io.Output;
25+
import com.esotericsoftware.kryo.kryo5.Kryo;
26+
import com.esotericsoftware.kryo.kryo5.Serializer;
27+
import com.esotericsoftware.kryo.kryo5.io.Input;
28+
import com.esotericsoftware.kryo.kryo5.io.Output;
2929

3030
public class STRtreePerGraphSerializer
3131
extends Serializer<STRtreePerGraph>
@@ -37,7 +37,7 @@ public void write(Kryo kryo, Output output, STRtreePerGraph index) {
3737
}
3838

3939
@Override
40-
public STRtreePerGraph read(Kryo kryo, Input input, Class<STRtreePerGraph> type) {
40+
public STRtreePerGraph read(Kryo kryo, Input input, Class<? extends STRtreePerGraph> type) {
4141
boolean isBuilt = input.readBoolean();
4242
@SuppressWarnings("unchecked")
4343
Map<Node, STRtree> treeMap = (Map<Node, STRtree>)kryo.readClassAndObject(input);

jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v2/STRtreeUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.LinkedHashMap;
2323
import java.util.List;
2424
import java.util.Map;
25+
import java.util.concurrent.ConcurrentHashMap;
2526

2627
import org.apache.jena.atlas.iterator.Iter;
2728
import org.apache.jena.atlas.iterator.IteratorCloseable;
@@ -54,7 +55,7 @@ public static STRtree buildSpatialIndexTree(Graph graph, String srsURI) throws S
5455

5556
// XXX This method overlaps function-wise with SpatialIndexerComputation. Consolidate?
5657
public static STRtreePerGraph buildSpatialIndexTree(DatasetGraph datasetGraph, String srsURI) throws SpatialIndexException {
57-
Map<Node, STRtree> treeMap = new LinkedHashMap<>();
58+
Map<Node, STRtree> treeMap = new ConcurrentHashMap<>();
5859

5960
// Process default graph.
6061
// LOGGER.info("building spatial index for default graph ...");

jena-geosparql/src/main/java/org/apache/jena/geosparql/spatial/index/v2/SpatialIndexIoKryo.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.nio.file.Files;
2525
import java.nio.file.Path;
2626
import java.util.Objects;
27+
import java.util.Set;
2728

2829
import org.apache.jena.atlas.RuntimeIOException;
2930
import org.apache.jena.atlas.io.IOX;
@@ -37,10 +38,10 @@
3738
import org.slf4j.Logger;
3839
import org.slf4j.LoggerFactory;
3940

40-
import com.esotericsoftware.kryo.Kryo;
41-
import com.esotericsoftware.kryo.Serializer;
42-
import com.esotericsoftware.kryo.io.Input;
43-
import com.esotericsoftware.kryo.io.Output;
41+
import com.esotericsoftware.kryo.kryo5.Kryo;
42+
import com.esotericsoftware.kryo.kryo5.Serializer;
43+
import com.esotericsoftware.kryo.kryo5.io.Input;
44+
import com.esotericsoftware.kryo.kryo5.io.Output;
4445
import com.google.gson.Gson;
4546
import com.google.gson.JsonObject;
4647

@@ -51,6 +52,12 @@ public class SpatialIndexIoKryo {
5152
// The current version of the index only stores the envelopes so this feature is not needed.
5253
private static boolean enableGeometrySerde = false;
5354

55+
/** Kryo4-based serialization is now obsolete. */
56+
private static final Set<String> OBSOLETE_VERSIONS = Set.of("2.0.0");
57+
58+
/** The version of the index that is created by this class. */
59+
public static final String VERSION = "3.0.0";
60+
5461
public static SpatialIndex loadOrBuildSpatialIndex(Dataset dataset, Path spatialIndexFile) throws SpatialIndexException {
5562
SpatialIndex spatialIndex = loadOrBuildSpatialIndex(dataset, null, spatialIndexFile);
5663
return spatialIndex;
@@ -149,7 +156,7 @@ public static final void save(Path spatialIndexFile, SpatialIndexPerGraph index)
149156
public static void writeToOutputStream(OutputStream os, SpatialIndexPerGraph index) {
150157
SpatialIndexHeader header = new SpatialIndexHeader();
151158
header.setType(SpatialIndexHeader.TYPE_VALUE);
152-
header.setVersion("2.0.0");
159+
header.setVersion(VERSION);
153160
header.setSrsUri(index.getSrsInfo().getSrsURI());
154161

155162
GeometrySerializerJtsWkb geometrySerializer = null;
@@ -207,8 +214,12 @@ public static final SpatialIndexPerGraph load(Path spatialIndexFile) throws Spat
207214
}
208215

209216
String version = header.getVersion();
210-
if (!"2.0.0".equals(version)) {
211-
throw new SpatialIndexException("The version of the spatial index does not match the version of this loader class.");
217+
if (!VERSION.equals(version)) {
218+
if (OBSOLETE_VERSIONS.contains(version)) {
219+
throw new SpatialIndexException("The version of the spatial index (" + version + ") is not longer supported. Move or delete this file to allow creation of a new index in its place: " + spatialIndexFile);
220+
} else {
221+
throw new SpatialIndexException("The version of the spatial index (" + version + ") is not supported by this loader class (" + VERSION + ").");
222+
}
212223
}
213224

214225
srsUri = header.getSrsUri();

jena-geosparql/src/main/java/org/locationtech/jts/index/strtree/STRtreeSerializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
import org.locationtech.jts.geom.Envelope;
2525

26-
import com.esotericsoftware.kryo.Kryo;
27-
import com.esotericsoftware.kryo.Serializer;
28-
import com.esotericsoftware.kryo.io.Input;
29-
import com.esotericsoftware.kryo.io.Output;
26+
import com.esotericsoftware.kryo.kryo5.Kryo;
27+
import com.esotericsoftware.kryo.kryo5.Serializer;
28+
import com.esotericsoftware.kryo.kryo5.io.Input;
29+
import com.esotericsoftware.kryo.kryo5.io.Output;
3030

3131
/*
3232
* This file is an adapted copy of org.locationtech.jts.index.strtree.IndexSerde from
@@ -53,7 +53,7 @@ public class STRtreeSerializer
5353
extends Serializer<STRtree>
5454
{
5555
@Override
56-
public STRtree read(Kryo kryo, Input input, Class<STRtree> type) {
56+
public STRtree read(Kryo kryo, Input input, Class<? extends STRtree> type) {
5757
int nodeCapacity = input.readInt();
5858
boolean notEmpty = (input.readByte() & 0x01) == 1;
5959
if (notEmpty) {

0 commit comments

Comments
 (0)