Ignore:
Timestamp:
2013-04-07T17:07:27+02:00 (11 years ago)
Author:
akks
Message:

JOSM/ImageryCache: updated MapDB (no more deadlocks, Java 1.6 compatible), less crashes, multiple-JOSM support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagerycache/src/org/mapdb/HTreeMap.java

    r29363 r29484  
    5252    protected final int hashSalt;
    5353
     54    protected final Atomic.Long counter;
    5455
    5556    protected final Serializer<K> keySerializer;
     
    8687            out.writeBoolean(value.hasValues);
    8788            out.writeInt(value.hashSalt);
     89            out.writeLong(value.counterRecid);
    8890            for(int i=0;i<16;i++){
    8991                Utils.packLong(out, value.segmentRecids[i]);
     
    100102            r.hasValues = in.readBoolean();
    101103            r.hashSalt = in.readInt();
     104            r.counterRecid = in.readLong();
    102105            r.segmentRecids = new long[16];
    103106            for(int i=0;i<16;i++){
     
    116119        boolean hasValues;
    117120        int hashSalt;
     121        long counterRecid;
    118122        Serializer keySerializer;
    119123        Serializer valueSerializer;
     124
    120125    }
    121126
     
    212217     * @param valueSerializer Serializer used for values. May be null for default value
    213218     */
    214     public HTreeMap(Engine engine, boolean hasValues, int hashSalt, Serializer defaultSerializer, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
     219    public HTreeMap(Engine engine, boolean hasValues, boolean keepCounter, int hashSalt, Serializer defaultSerializer, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
    215220        this.engine = engine;
    216221        this.hasValues = hasValues;
    217222        this.hashSalt = hashSalt;
     223
     224
    218225        SerializerBase.assertSerializable(keySerializer);
    219226        SerializerBase.assertSerializable(valueSerializer);
     227
    220228
    221229        if(defaultSerializer == null) defaultSerializer = Serializer.BASIC_SERIALIZER;
     
    229237        for(int i=0;i<16;i++)
    230238            segmentRecids[i] = engine.put(new long[16][], DIR_SERIALIZER);
     239
     240        long counterRecid = 0;
     241        if(keepCounter){
     242            counterRecid = engine.put(0L, Serializer.LONG_SERIALIZER);
     243            this.counter = new Atomic.Long(engine,counterRecid);
     244            Bind.size(this,counter);
     245        }else{
     246            this.counter = null;
     247        }
     248
    231249        HashRoot r = new HashRoot();
    232250        r.hasValues = hasValues;
    233251        r.hashSalt = hashSalt;
     252        r.counterRecid = counterRecid;
    234253        r.segmentRecids = segmentRecids;
    235254        r.keySerializer = this.keySerializer;
    236255        r.valueSerializer = this.valueSerializer;
    237256        this.rootRecid = engine.put(r, new HashRootSerializer(defaultSerializer));
     257
    238258    }
    239259
     
    259279        this.keySerializer = r.keySerializer;
    260280        this.valueSerializer = r.valueSerializer;
     281
     282        if(r.counterRecid!=0){
     283            counter = new Atomic.Long(engine,r.counterRecid);
     284            Bind.size(this,counter);
     285        }else{
     286            this.counter = null;
     287        }
    261288    }
    262289
     
    294321    @Override
    295322    public int size() {
     323        if(counter!=null)
     324            return (int) counter.get(); //TODO larger then MAX_INT
     325
     326
    296327        long counter = 0;
    297328
Note: See TracChangeset for help on using the changeset viewer.