示例#1
0
  @SuppressWarnings("restriction")
  public FixMessageContainer<FixMessage> getFixMessageContainer() {
    int localTakePointer;

    FixMessageContainer<FixMessage> localObject = fixLocal.get();
    if (localObject != null) {
      if (localObject.state.compareAndSet(
          FixMessageContainer.AVAILABLE_STATE, FixMessageContainer.IN_USE_STATE)) {
        return localObject;
      }
    }

    while (objectPutPosition != (localTakePointer = objGetPosition)) {
      int index = localTakePointer & mask;
      FixMessageContainer<FixMessage> fixMsgContainer = fixMessageArr[index];
      if (fixMsgContainer != null
          && NativeBytes.UNSAFE.compareAndSwapObject(
              fixMessageArr, (index << TAIL_ADJUSTMENT) + BASE_ADDR, fixMsgContainer, null)) {
        objGetPosition = localTakePointer + 1;
        if (fixMsgContainer.state.compareAndSet(
            FixMessageContainer.AVAILABLE_STATE, FixMessageContainer.IN_USE_STATE)) {
          fixLocal.set(fixMsgContainer);
          return fixMsgContainer;
        }
      }
    }
    return null;
  }
 public Entry<K, V> getNextEntry(K prevKey) {
   try {
     int pos;
     if (prevKey == null) {
       pos = smallMap.firstPos();
     } else {
       long hash = hasher.hash(prevKey);
       pos = smallMap.nextDifferentHashNonEmptyPosition(hash);
     }
     while (true) {
       if (pos < 0) {
         return null;
       } else {
         bytes.storePositionAndSize(store, pos * smallEntrySize, smallEntrySize);
         K key = getKey();
         if (prevKey == null || !equals(key, prevKey)) {
           if (bytesMarshallable) {
             V value = (V) NativeBytes.UNSAFE.allocateInstance(vClass);
             ((BytesMarshallable) value).readMarshallable(bytes);
             return new SimpleEntry<K, V>(key, value);
           } else {
             V value = (V) bytes.readObject();
             return new SimpleEntry<K, V>(key, value);
           }
         }
       }
       pos = smallMap.nextPos();
     }
   } catch (InstantiationException e) {
     throw new AssertionError(e);
   }
 }
 synchronized V get(long hash, K key, V value) {
   smallMap.startSearch(hash);
   while (true) {
     int pos = smallMap.nextPos();
     if (pos < 0) {
       K key2 = key instanceof CharSequence ? (K) key.toString() : key;
       final DirectStore store = map.get(key2);
       if (store == null) return null;
       bytes.storePositionAndSize(store, 0, store.size());
       break;
     } else {
       bytes.storePositionAndSize(store, pos * smallEntrySize, smallEntrySize);
       K key2 = getKey();
       if (equals(key, key2)) break;
     }
   }
   if (bytesMarshallable) {
     try {
       V v = value == null ? (V) NativeBytes.UNSAFE.allocateInstance(vClass) : value;
       ((BytesMarshallable) v).readMarshallable(bytes);
       return v;
     } catch (InstantiationException e) {
       throw new AssertionError(e);
     }
   }
   return (V) bytes.readObject();
 }
示例#4
0
 @SuppressWarnings("restriction")
 public void putFixMessageContainer(FixMessageContainer<FixMessage> fixMsgContainer)
     throws Exception {
   int localPosition = objectPutPosition;
   long index = ((localPosition & mask) << TAIL_ADJUSTMENT) + BASE_ADDR;
   if (fixMsgContainer.state.compareAndSet(
       FixMessageContainer.IN_USE_STATE, FixMessageContainer.AVAILABLE_STATE)) {
     NativeBytes.UNSAFE.putOrderedObject(fixMessageArr, index, fixMsgContainer);
     objectPutPosition = localPosition + 1;
   } else {
     throw new Exception("Not a valid position address");
   }
 }
示例#5
0
  @SuppressWarnings({"unchecked", "restriction"})
  public FixMessagePool(
      FixPoolFactory<FixMessage> fixPoolFactory, int poolSize, boolean useDefault) {

    if (fixPoolFactory == null) {
      fixPoolFactory = this;
    }
    int currentSize = 1;
    while (currentSize < poolSize) {
      currentSize = currentSize << 1;
    }
    poolSize = currentSize;
    fixMessageArr = new FixMessageContainer[poolSize];
    for (int i = 0; i < poolSize; i++) {
      fixMessageArr[i] = new FixMessageContainer<FixMessage>(fixPoolFactory.create(useDefault));
    }
    mask = poolSize - 1;
    objectPutPosition = poolSize;
    BASE_ADDR = NativeBytes.UNSAFE.arrayBaseOffset(FixMessageContainer[].class);
    ARR_INDEX = NativeBytes.UNSAFE.arrayIndexScale(FixMessageContainer[].class);
    TAIL_ADJUSTMENT = 31 - Integer.numberOfLeadingZeros((int) ARR_INDEX);
  }