コード例 #1
0
  public VanillaSharedHashMap(
      SharedHashMapBuilder builder, File file, Class<K> kClass, Class<V> vClass)
      throws IOException {
    this.kClass = kClass;
    this.vClass = vClass;

    lockTimeOutNS = builder.lockTimeOutMS() * 1000000;

    this.replicas = builder.replicas();
    this.entrySize = builder.entrySize();

    this.errorListener = builder.errorListener();
    this.generatedKeyType = builder.generatedKeyType();
    this.generatedValueType = builder.generatedValueType();
    this.putReturnsNull = builder.putReturnsNull();
    this.removeReturnsNull = builder.removeReturnsNull();

    int segments = builder.actualSegments();
    this.segmentBits = Maths.intLog2(segments);
    int entriesPerSegment = builder.actualEntriesPerSegment();
    this.entriesPerSegment = entriesPerSegment;

    @SuppressWarnings("unchecked")
    Segment[] ss = (VanillaSharedHashMap.Segment[]) new VanillaSharedHashMap.Segment[segments];
    this.segments = ss;

    this.ms = new MappedStore(file, FileChannel.MapMode.READ_WRITE, sizeInBytes());

    long offset = SharedHashMapBuilder.HEADER_SIZE;
    long segmentSize = segmentSize();
    for (int i = 0; i < this.segments.length; i++) {
      this.segments[i] = new Segment(ms.createSlice(offset, segmentSize));
      offset += segmentSize;
    }
  }
コード例 #2
0
 protected DirectBytes acquireBytes() {
   DirectBytes bytes = localBytes.get();
   if (bytes == null) {
     localBytes.set(
         bytes =
             new DirectStore(ms.bytesMarshallerFactory(), builder.entrySize() * 2, false)
                 .createSlice());
   } else {
     bytes.clear();
   }
   return bytes;
 }