Пример #1
0
  public synchronized <E> Queue<E> createCircularQueue(
      String name, Serializer<E> serializer, long size) {
    checkNameNotExists(name);
    if (serializer == null) serializer = getDefaultSerializer();

    //        long headerRecid = engine.put(0L, Serializer.LONG);
    // insert N Nodes empty nodes into a circle
    long prevRecid = 0;
    long firstRecid = 0;
    Serializer<Queues.SimpleQueue.Node> nodeSer = new Queues.SimpleQueue.NodeSerializer(serializer);
    for (long i = 0; i < size; i++) {
      Queues.SimpleQueue.Node n = new Queues.SimpleQueue.Node(prevRecid, null);
      prevRecid = engine.put(n, nodeSer);
      if (firstRecid == 0) firstRecid = prevRecid;
    }
    // update first node to point to last recid
    engine.update(firstRecid, new Queues.SimpleQueue.Node(prevRecid, null), nodeSer);

    long headRecid = engine.put(prevRecid, Serializer.LONG);
    long headInsertRecid = engine.put(prevRecid, Serializer.LONG);

    Queues.CircularQueue<E> ret =
        new Queues.CircularQueue<E>(
            engine,
            catPut(name + ".serializer", serializer),
            catPut(name + ".headRecid", headRecid),
            catPut(name + ".headInsertRecid", headInsertRecid),
            catPut(name + ".size", size));
    catalog.put(name + ".type", "CircularQueue");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Пример #2
0
  /**
   * Creates new HashSet
   *
   * @param name of set to create
   * @param keepCounter if counter should be kept, without counter updates are faster, but entire
   *     collection needs to be traversed to count items.
   * @param serializer used to convert keys into/from binary form. Use null for default value.
   * @param <K> item type
   * @throws IllegalArgumentException if name is already used
   */
  public synchronized <K> Set<K> createHashSet(
      String name, boolean keepCounter, Serializer<K> serializer) {
    checkNameNotExists(name);

    Set<K> ret =
        new HTreeMap<K, Object>(
                engine,
                catPut(name + ".counterRecid", !keepCounter ? 0L : engine.put(0L, Serializer.LONG)),
                catPut(name + ".hashSalt", Utils.RANDOM.nextInt()),
                catPut(name + ".segmentRecids", HTreeMap.preallocateSegments(engine)),
                catPut(name + ".serializer", serializer, getDefaultSerializer()),
                null,
                0L,
                0L,
                0L,
                0L,
                null,
                null,
                null)
            .keySet();

    catalog.put(name + ".type", "HashSet");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Пример #3
0
 public synchronized Atomic.Integer createAtomicInteger(String name, int initValue) {
   checkNameNotExists(name);
   long recid = engine.put(initValue, Serializer.INTEGER);
   Atomic.Integer ret = new Atomic.Integer(engine, catPut(name + ".recid", recid));
   catalog.put(name + ".type", "AtomicInteger");
   collections.put(name, new WeakReference<Object>(ret));
   return ret;
 }
Пример #4
0
 public synchronized Atomic.Long createAtomicLong(String name, long initValue) {
   checkNameNotExists(name);
   long recid = engine.put(initValue, Serializer.LONG);
   Atomic.Long ret = new Atomic.Long(engine, catPut(name + ".recid", recid));
   catalog.put(name + ".type", "AtomicLong");
   collections.put(name, new WeakReference<Object>(ret));
   return ret;
 }
Пример #5
0
 public synchronized Atomic.Boolean createAtomicBoolean(String name, boolean initValue) {
   checkNameNotExists(name);
   long recid = engine.put(initValue, Serializer.BOOLEAN);
   Atomic.Boolean ret = new Atomic.Boolean(engine, catPut(name + ".recid", recid));
   catalog.put(name + ".type", "AtomicBoolean");
   collections.put(name, new WeakReference<Object>(ret));
   return ret;
 }
Пример #6
0
 public synchronized Atomic.String createAtomicString(String name, String initValue) {
   checkNameNotExists(name);
   if (initValue == null) throw new IllegalArgumentException("initValue may not be null");
   long recid = engine.put(initValue, Serializer.STRING_NOSIZE);
   Atomic.String ret = new Atomic.String(engine, catPut(name + ".recid", recid));
   catalog.put(name + ".type", "AtomicString");
   collections.put(name, new WeakReference<Object>(ret));
   return ret;
 }
Пример #7
0
  /**
   * Creates new HashMap with more specific arguments
   *
   * @param <K> key type
   * @param <V> value type
   * @throws IllegalArgumentException if name is already used
   * @return newly created map
   */
  protected synchronized <K, V> HTreeMap<K, V> createHashMap(HTreeMapMaker m) {
    String name = m.name;
    checkNameNotExists(name);

    long expireTimeStart = 0, expire = 0, expireAccess = 0, expireMaxSize = 0;
    long[] expireHeads = null, expireTails = null;

    if (m.expire != 0 || m.expireAccess != 0 || m.expireMaxSize != 0) {
      expireTimeStart = catPut(name + ".expireTimeStart", System.currentTimeMillis());
      expire = catPut(name + ".expire", m.expire);
      expireAccess = catPut(name + ".expireAccess", m.expireAccess);
      expireMaxSize = catPut(name + ".expireMaxSize", m.expireMaxSize);
      expireHeads = new long[16];
      expireTails = new long[16];
      for (int i = 0; i < 16; i++) {
        expireHeads[i] = engine.put(0L, Serializer.LONG);
        expireTails[i] = engine.put(0L, Serializer.LONG);
      }
      catPut(name + ".expireHeads", expireHeads);
      catPut(name + ".expireTails", expireHeads);
    }

    HTreeMap<K, V> ret =
        new HTreeMap<K, V>(
            engine,
            catPut(name + ".counterRecid", !m.keepCounter ? 0L : engine.put(0L, Serializer.LONG)),
            catPut(name + ".hashSalt", Utils.RANDOM.nextInt()),
            catPut(name + ".segmentRecids", HTreeMap.preallocateSegments(engine)),
            catPut(name + ".keySerializer", m.keySerializer, getDefaultSerializer()),
            catPut(name + ".valueSerializer", m.valueSerializer, getDefaultSerializer()),
            expireTimeStart,
            expire,
            expireAccess,
            expireMaxSize,
            expireHeads,
            expireTails,
            m.valueCreator);

    catalog.put(name + ".type", "HashMap");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Пример #8
0
  public synchronized <E> Queue<E> createQueue(String name, Serializer<E> serializer) {
    checkNameNotExists(name);

    long headerRecid = engine.put(0L, Serializer.LONG);
    long nextTail =
        engine.put(Queues.SimpleQueue.Node.EMPTY, new Queues.SimpleQueue.NodeSerializer(null));
    long nextTailRecid = engine.put(nextTail, Serializer.LONG);
    long sizeRecid = engine.put(0L, Serializer.LONG);

    Queues.Queue<E> ret =
        new Queues.Queue<E>(
            engine,
            catPut(name + ".serializer", serializer, getDefaultSerializer()),
            catPut(name + ".headRecid", headerRecid),
            catPut(name + ".nextTailRecid", nextTailRecid),
            catPut(name + ".sizeRecid", sizeRecid));
    catalog.put(name + ".type", "Queue");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Пример #9
0
  public synchronized <K> NavigableSet<K> createTreeSet(BTreeSetMaker m) {
    checkNameNotExists(m.name);
    m.serializer = fillNulls(m.serializer);
    m.serializer =
        catPut(
            m.name + ".keySerializer",
            m.serializer,
            new BTreeKeySerializer.BasicKeySerializer(getDefaultSerializer()));
    m.comparator = catPut(m.name + ".comparator", m.comparator, Utils.COMPARABLE_COMPARATOR);

    if (m.pumpPresortBatchSize != -1) {
      m.pumpSource =
          Pump.sort(
              m.pumpSource,
              m.pumpPresortBatchSize,
              Collections.reverseOrder(m.comparator),
              getDefaultSerializer());
    }

    long counterRecid = !m.keepCounter ? 0L : engine.put(0L, Serializer.LONG);
    long rootRecidRef;

    if (m.pumpSource == null) {
      rootRecidRef = BTreeMap.createRootRef(engine, m.serializer, null, m.comparator);
    } else {
      rootRecidRef =
          Pump.buildTreeMap(
              m.pumpSource,
              engine,
              Fun.noTransformExtractor(),
              null,
              m.nodeSize,
              false,
              counterRecid,
              m.serializer,
              null,
              m.comparator);
    }

    NavigableSet<K> ret =
        new BTreeMap<K, Object>(
                engine,
                catPut(m.name + ".rootRecidRef", rootRecidRef),
                catPut(m.name + ".maxNodeSize", m.nodeSize),
                false,
                catPut(m.name + ".counterRecid", counterRecid),
                m.serializer,
                null,
                m.comparator)
            .keySet();
    catalog.put(m.name + ".type", "TreeSet");
    collections.put(m.name, new WeakReference<Object>(ret));
    return ret;
  }
Пример #10
0
 public synchronized <E> Atomic.Var<E> createAtomicVar(
     String name, E initValue, Serializer<E> serializer) {
   checkNameNotExists(name);
   if (serializer == null) serializer = getDefaultSerializer();
   long recid = engine.put(initValue, serializer);
   Atomic.Var ret =
       new Atomic.Var(
           engine, catPut(name + ".recid", recid), catPut(name + ".serializer", serializer));
   catalog.put(name + ".type", "AtomicVar");
   collections.put(name, new WeakReference<Object>(ret));
   return ret;
 }
Пример #11
0
  protected synchronized <K, V> BTreeMap<K, V> createTreeMap(BTreeMapMaker m) {
    String name = m.name;
    checkNameNotExists(name);
    m.keySerializer = fillNulls(m.keySerializer);
    m.keySerializer =
        catPut(
            name + ".keySerializer",
            m.keySerializer,
            new BTreeKeySerializer.BasicKeySerializer(getDefaultSerializer()));
    m.valueSerializer =
        catPut(name + ".valueSerializer", m.valueSerializer, getDefaultSerializer());
    m.comparator = catPut(name + ".comparator", m.comparator, Utils.COMPARABLE_COMPARATOR);

    long counterRecid = !m.keepCounter ? 0L : engine.put(0L, Serializer.LONG);

    long rootRecidRef;
    if (m.pumpSource == null) {
      rootRecidRef =
          BTreeMap.createRootRef(engine, m.keySerializer, m.valueSerializer, m.comparator);
    } else {
      rootRecidRef =
          Pump.buildTreeMap(
              m.pumpSource,
              engine,
              m.pumpKeyExtractor,
              m.pumpValueExtractor,
              m.nodeSize,
              m.valuesStoredOutsideNodes,
              counterRecid,
              m.keySerializer,
              m.valueSerializer,
              m.comparator);
    }

    BTreeMap<K, V> ret =
        new BTreeMap<K, V>(
            engine,
            catPut(name + ".rootRecidRef", rootRecidRef),
            catPut(name + ".maxNodeSize", m.nodeSize),
            catPut(name + ".valuesOutsideNodes", m.valuesStoredOutsideNodes),
            catPut(name + ".counterRecid", counterRecid),
            m.keySerializer,
            m.valueSerializer,
            m.comparator);
    catalog.put(name + ".type", "TreeMap");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Пример #12
0
  public synchronized <E> Queue<E> createStack(
      String name, Serializer<E> serializer, boolean useLocks) {
    checkNameNotExists(name);

    long headerRecid = engine.put(0L, Serializer.LONG);

    Queues.Stack<E> ret =
        new Queues.Stack<E>(
            engine,
            catPut(name + ".serializer", serializer, getDefaultSerializer()),
            catPut(name + ".headRecid", headerRecid),
            catPut(name + ".useLocks", useLocks));
    catalog.put(name + ".type", "Stack");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }