0

我有以下类我想用作我正在实现的地图的值:

import java.util.ArrayList;
import java.util.List;
import net.openhft.chronicle.bytes.BytesMarshallable;
import org.apache.commons.lang3.tuple.Pair;


public class GlossesLexicalizations implements BytesMarshallable {

    List<String> glosses = new ArrayList<String>();
    List<Pair<String, POS.Tag>> lexicalizations = new ArrayList<Pair<String, POS.Tag>>();

    public GlossesLexicalizations(){

    }

    public GlossesLexicalizations(List<String> g, List<Pair<String, POS.Tag>> l){
        glosses = g;
        lexicalizations = l;
    }

    public void setGlosses(List<String> l){
        glosses = l;
    }

    public void setLexicalizations(List<Pair<String, POS.Tag>> l){
        lexicalizations = l;
    }

    public List<String> getGlosses(){
        return glosses;
    }

    public List<Pair<String, POS.Tag>> getLexicalizations(){  
        return lexicalizations;
    }
}

我实现BytesMarshallable了 ChronicleMap 可以使用它。

然后我创建数据库:

        File file = new File("/home/sandor/Desktop/lexicalizations-and-glosses-map.bin");

        String key = "bn:14232961n"; // example

        List<String> glosses = bn.getGlosses(key, ULocale.US);

        List<Pair<String, POS.Tag>> lexicalizations = bn.getLexicalizations(key, ULocale.US);

        ChronicleMap<String, GlossesLexicalizations> lexicalizationGraph = ChronicleMap
                .of(String.class, GlossesLexicalizations.class)
                .name("lexicalizations-and-glosses")
                .constantKeySizeBySample("bn:14271053n")
                .entries(100) // poner number of entries + 15% extra
                .createOrRecoverPersistedTo(file);

        GlossesLexicalizations gl = new GlossesLexicalizations(glosses, lexicalizations);


        lexicalizationGraph.put(key, gl);

        lexicalizationGraph.close();

这给了我以下错误:

Value size in serialized form must be configured in ChronicleMap, at least approximately. Use builder.averageValue()/.constantValueSizeBySample()/.averageValueSize() methods to configure the size

我可以理解字符串的平均值大小,但是你为一个类做什么?

4

1 回答 1

0

您可以创建值类的对象,GlossesLexicalizations像在实际应用程序中一样填写它,并将其作为示例提供averageValue(),或者您可以尝试猜测您的对象中将拥有多少数据并averageValueSize()使用那个号码。如果数字不准确,请不要担心 - 它只需要在一个球场内。这是 Chronicle Map 能够在内存中分配对象所必需的(您可能知道 Chronicle Map 将对象存储在堆外内存中,因此它必须自己进行内存分配)。

于 2020-03-16T17:57:35.540 回答