最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - ChronicleMap custom serialisers exception SizeMarshaller is it aliased? - Stack Overflow

programmeradmin5浏览0评论

This is characteristic only if a custom serializer is present.

After the ChronicleMap is created, the process writes the data and closes the Map (using the close() method). However, after restarting, the Map is not opened from the file and I get an exception instead as you can see in the following example:

SomePOJO.java

class SomePOJO {
    int fieldInt;
    long fieldLong;

    public SomePOJO(int i)  {
        fieldInt = i;
        fieldLong = i+1;
    }

    public SomePOJO() {
    }

    public String toString() {
        return "i="+fieldInt+", ;="+fieldLong;
    }
}

SomePOJOSerialyser.java

class SomePOJOSerialyser implements BytesWriter<SomePOJO[]>,
                                    BytesReader<SomePOJO[]>,
                                    ReadResolvable<SomePOJOSerialyser> {

    public static final SomePOJOSerialyser CHR_INSTANCE = new SomePOJOSerialyser();

    public SomePOJO[] read(Bytes input, @Nullable SomePOJO[] using)    {
        int len = input.readInt();

        if (using == null)
            using = new SomePOJO[len];
        else
        if (using.length != len)
            using = Arrays.copyOf(using, len);

        for (int i = 0; i < len; i++)  {
            if(using[i] == null)
                using[i] = new SomePOJO();
            using[i].fieldInt = input.readInt();
            using[i].fieldLong = input.readLong();
        }
        return using;
    }

    public void write(Bytes out, SomePOJO[] toWrite) {
        out.writeInt(toWrite.length);
        for (SomePOJO cp : toWrite) {
            out.writeInt(cp.fieldInt);
            out.writeLong(cp.fieldLong);
        }
    }

    public void writeMarshallable(@.jetbrains.annotations.NotNull WireOut wireOut)  {
    }

    public void readMarshallable(@.jetbrains.annotations.NotNull WireIn wireIn) {
    }

    public SomePOJOSerialyser readResolve()   {
        return CHR_INSTANCE;
    }
}

Tst.java

public class Tst{

    static ChronicleMap<Integer, SomePOJO[]> openMap(File f) throws IOException    {
        ChronicleMapBuilder cmb = ChronicleMapBuilder.of(Integer.class, SomePOJO[].class);
        cmb.valueMarshaller(SomePOJOSerialyser.CHR_INSTANCE);
        cmb.averageValueSize(128);
        cmb.name("map-map").entries(1_000);
        return cmb.createPersistedTo(f);
    }


    static public void main(String args[])    {
        try  {
            Random rnd = new Random();
            File mapfile = new File("chr.map");

            ChronicleMap<Integer, SomePOJO[]> map;

            System.out.println(" write --->");
            map = openMap(mapfile);

            for(int i=0; i<1000; i++) {
                SomePOJO[] arr = new SomePOJO[5+rnd.nextInt(10)];
                for(int j=0;j<arr.length; j++)
                    arr[j] = new SomePOJO(j);
                map.put(i, arr);
            }

            System.out.println(" close");
            map.close();

            System.out.println(" read --->");
            map = openMap(mapfile);

            map.values().stream().forEach(v->System.out.println(v));
            map.close();

        }
        catch (Exception e) {
            e.printStackTrace();
        }

    }

}

If I use the

        <dependency>
            <groupId>net.openhft</groupId>
            <artifactId>chronicle-map</artifactId>
            <version>3.22.9</version>
        </dependency>

then I get:

java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "object" is null
    at net.openhft.chronicle.wire.TextWire$TextValueIn.marshallable(TextWire.java:3207)
    at net.openhft.chronicle.wire.Wires.objectMap(Wires.java:492)
    at net.openhft.chronicle.wire.Wires.object0(Wires.java:573)
    at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:514)
    at net.openhft.chronicle.map.VanillaChronicleMap.readMarshallableFields(VanillaChronicleMap.java:143)
    at net.openhft.chronicle.hash.impl.VanillaChronicleHash.readMarshallable(VanillaChronicleHash.java:248)
    at net.openhft.chronicle.wire.SerializationStrategies$1.readUsing(SerializationStrategies.java:50)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.marshallable(TextWire.java:3222)
    at net.openhft.chronicle.wire.Wires.objectMap(Wires.java:492)
    at net.openhft.chronicle.wire.Wires.object0(Wires.java:573)
    at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:525)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType0(TextWire.java:3509)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType(TextWire.java:3482)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.typedMarshallable(TextWire.java:3284)
    at net.openhft.chronicle.map.ChronicleMapBuilder.openWithExistingFile(ChronicleMapBuilder.java:1899)
    at net.openhft.chronicle.map.ChronicleMapBuilder.createWithFile(ChronicleMapBuilder.java:1706)
    at net.openhft.chronicle.map.ChronicleMapBuilder.createPersistedTo(ChronicleMapBuilder.java:1586)
    at com.crossvista.core.chronicle.tst.Tst.openMap(Tst.java:27)
    at com.crossvista.core.chronicle.tst.Tst.main(Tst.java:41)

If I use the

        <dependency>
            <groupId>net.openhft</groupId>
            <artifactId>chronicle-map</artifactId>
            <version>3.27ea0</version>
        </dependency>

then I get:

et.openhft.chronicle.core.util.ClassNotFoundRuntimeException: java.lang.ClassNotFoundException: failed to create instance of clazz=interface net.openhft.chronicle.hash.serialization.SizeMarshaller is it aliased?
    at net.openhft.chronicle.wire.Wires.objectMap(Wires.java:943)
    at net.openhft.chronicle.wire.Wires.object2(Wires.java:1106)
    at net.openhft.chronicle.wire.Wires.object1(Wires.java:1049)
    at net.openhft.chronicle.wire.Wires.object0(Wires.java:1013)
    at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:1219)
    at net.openhft.chronicle.map.VanillaChronicleMap.readMarshallableFields(VanillaChronicleMap.java:144)
    at net.openhft.chronicle.hash.impl.VanillaChronicleHash.readMarshallable(VanillaChronicleHash.java:248)
    at net.openhft.chronicle.wire.SerializationStrategies$1.readUsing(SerializationStrategies.java:67)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.marshallable(TextWire.java:2521)
    at net.openhft.chronicle.wire.Wires.objectMap(Wires.java:946)
    at net.openhft.chronicle.wire.Wires.object2(Wires.java:1106)
    at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:1265)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType0(TextWire.java:2909)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType(TextWire.java:2854)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.typedMarshallable(TextWire.java:2600)
    at net.openhft.chronicle.map.ChronicleMapBuilder.openWithExistingFile(ChronicleMapBuilder.java:1913)
    at net.openhft.chronicle.map.ChronicleMapBuilder.createWithFile(ChronicleMapBuilder.java:1719)
    at net.openhft.chronicle.map.ChronicleMapBuilder.createPersistedTo(ChronicleMapBuilder.java:1618)

But if I don't use the custom serializer and write simple objects, for example strings, into the table, I won't have any problems.

Can anyone tell me the cause? Or some advice? I can't understand what I'm doing wrong ... Thanks

JNA:

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>5.16.0</version>
</dependency>

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna-platform</artifactId>
    <version>5.16.0</version>
</dependency>

Java 17 with:

--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
--add-opens=java.base/java=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
--add-exports=jdkpiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-opens=jdkpiler/com.sun.tools.javac=ALL-UNNAMED
发布评论

评论列表(0)

  1. 暂无评论