@Test
 public void testEntityProcessorSystem() {
   TestEntityProcessorSystem system = new TestEntityProcessorSystem();
   Engine engine = new Engine(new EngineConfig().addSystem(system));
   Mask entities = new Mask();
   int a, b, c;
   entities.set(a = engine.createEntity());
   entities.set(b = engine.createEntity());
   entities.set(c = engine.createEntity());
   engine.update();
   assertEquals(system.processedEntities.getMask(), entities);
   system.processedEntities.edit().clear();
   engine.destroyEntity(b);
   entities.clear(b);
   engine.update();
   assertEquals(system.processedEntities.getMask(), entities);
   system.processedEntities.edit().clear();
   entities.set(b = engine.createEntity());
   engine.update();
   assertEquals(system.processedEntities.getMask(), entities);
   system.processedEntities.edit().clear();
   engine.destroyEntity(a);
   engine.destroyEntity(b);
   engine.destroyEntity(c);
   entities.clear(a);
   entities.clear(b);
   entities.clear(c);
 }
Ejemplo n.º 2
0
Archivo: DB.java Proyecto: rhauch/MapDB
  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;
  }
  @Test
  public void test() {
    Volume.Factory fab = Volume.memoryFactory(false, 0L, false);
    Engine e = new StoreDirect(fab);
    e = new EngineWrapper.ImmutabilityCheckEngine(e);

    List rec = new ArrayList();
    rec.add("aa");
    long recid = e.put(rec, Serializer.BASIC);
    rec.add("bb");

    try {
      e.update(recid, rec, Serializer.BASIC);
      fail("should throw exception");
    } catch (AssertionError ee) {
      assertTrue(ee.getMessage().startsWith("Record instance was modified"));
    }

    try {
      e.close();
      fail("should throw exception");
    } catch (AssertionError ee) {
      assertTrue(ee.getMessage().startsWith("Record instance was modified"));
    }
  }
Ejemplo n.º 4
0
  @Override
  public void update() {
    super.update();

    if (tile.isRedstonePowered) {
      if ((tile.worldObj.getWorldTime() % 20) == 0) {
        energy++;
      }
    }
  }
Ejemplo n.º 5
0
  @Override
  public void update() {
    super.update();

    ItemStack itemInInventory = tile.getStackInSlot(0);

    if (itemInInventory != null) {
      int liquidId = BuildCraftAPI.getLiquidForFilledItem(itemInInventory);

      if (liquidId != 0) {
        if (fill(Orientations.Unknown, BuildCraftAPI.BUCKET_VOLUME, liquidId, false)
            == BuildCraftAPI.BUCKET_VOLUME) {
          fill(Orientations.Unknown, BuildCraftAPI.BUCKET_VOLUME, liquidId, true);

          tile.setInventorySlotContents(0, Utils.consumeItem(itemInInventory));
        }
      }
    }

    if (heat > COOLANT_THRESHOLD) {
      int extraHeat = heat - COOLANT_THRESHOLD;

      if (coolantQty > extraHeat) {
        coolantQty -= extraHeat;
        heat = COOLANT_THRESHOLD;
      } else {
        heat -= coolantQty;
        coolantQty = 0;
      }
    }

    if (heat > 0 && (penatlyCooling > 0 || !tile.isRedstonePowered)) {
      heat -= 10;
    }

    if (heat <= 0 && penatlyCooling > 0) {
      penatlyCooling--;
    }
  }
 @Benchmark
 public void insert_remove() {
   engine.update();
 }
Ejemplo n.º 7
0
 /**
  * Unconditionally sets to the given value.
  *
  * @param newValue the new value
  */
 public final void set(E newValue) {
   engine.update(recid, newValue, serializer);
 }
Ejemplo n.º 8
0
 /**
  * Unconditionally sets to the given value.
  *
  * @param newValue the new value
  */
 public final void set(java.lang.String newValue) {
   engine.update(recid, newValue, Serializer.STRING_NOSIZE);
 }
Ejemplo n.º 9
0
 /**
  * Unconditionally sets to the given value.
  *
  * @param newValue the new value
  */
 public final void set(boolean newValue) {
   engine.update(recid, newValue, Serializer.BOOLEAN);
 }
Ejemplo n.º 10
0
 /**
  * Sets to the given value.
  *
  * @param newValue the new value
  */
 public final void set(long newValue) {
   engine.update(recid, newValue, Serializer.LONG);
 }
Ejemplo n.º 11
0
 /**
  * Sets to the given value.
  *
  * @param newValue the new value
  */
 public final void set(int newValue) {
   engine.update(recid, newValue, Serializer.INTEGER);
 }
Ejemplo n.º 12
0
  /** constructs Engine using current settings */
  public Engine makeEngine() {

    final boolean readOnly = propsGetBool(Keys.readOnly);
    final File file = props.containsKey(Keys.file) ? new File(props.getProperty(Keys.file)) : null;
    final String volume = props.getProperty(Keys.volume);
    final String store = props.getProperty(Keys.store);

    if (readOnly && file == null)
      throw new UnsupportedOperationException("Can not open in-memory DB in read-only mode.");

    if (readOnly && !file.exists() && !Keys.store_append.equals(store)) {
      throw new UnsupportedOperationException("Can not open non-existing file in read-only mode.");
    }

    if (propsGetLong(Keys.sizeLimit, 0) > 0 && Keys.store_append.equals(store))
      throw new UnsupportedOperationException("Append-Only store does not support Size Limit");

    extendArgumentCheck();

    Engine engine;

    if (!Keys.store_append.equals(store)) {
      Volume.Factory folFac = extendStoreVolumeFactory();

      engine =
          propsGetBool(Keys.transactionDisable)
              ? extendStoreDirect(folFac)
              : extendStoreWAL(folFac);

    } else {
      if (Keys.volume_heap.equals(volume) || Keys.volume_offheap.equals(volume))
        throw new UnsupportedOperationException(
            "Append Storage format is not supported with in-memory dbs");
      engine = extendStoreAppend();
    }

    engine = extendWrapStore(engine);

    if (propsGetBool(Keys.asyncWrite) && !readOnly) {
      engine = extendAsyncWriteEngine(engine);
    }

    final String cache = props.getProperty(Keys.cache, CC.DEFAULT_CACHE);

    if (Keys.cache_disable.equals(cache)) {
      // do not wrap engine in cache
    } else if (Keys.cache_hashTable.equals(cache)) {
      engine = extendCacheHashTable(engine);
    } else if (Keys.cache_hardRef.equals(cache)) {
      engine = extendCacheHardRef(engine);
    } else if (Keys.cache_weakRef.equals(cache)) {
      engine = extendCacheWeakRef(engine);
    } else if (Keys.cache_softRef.equals(cache)) {
      engine = extendCacheSoftRef(engine);
    } else if (Keys.cache_lru.equals(cache)) {
      engine = extendCacheLRU(engine);
    } else {
      throw new IllegalArgumentException("unknown cache type: " + cache);
    }

    engine = extendWrapCache(engine);

    if (propsGetBool(Keys.snapshots)) engine = extendSnapshotEngine(engine);

    engine = extendWrapSnapshotEngine(engine);

    if (readOnly) engine = new ReadOnlyEngine(engine);

    if (propsGetBool(Keys.closeOnJvmShutdown)) {
      engine = new EngineWrapper.CloseOnJVMShutdown(engine);
    }

    // try to read one record from DB, to make sure encryption and compression are correctly set.
    Fun.Tuple2<Integer, byte[]> check = null;
    try {
      check = (Fun.Tuple2<Integer, byte[]>) engine.get(Engine.CHECK_RECORD, Serializer.BASIC);
      if (check != null) {
        if (check.a.intValue() != Arrays.hashCode(check.b))
          throw new RuntimeException("invalid checksum");
      }
    } catch (Throwable e) {
      throw new IllegalArgumentException(
          "Error while opening store. Make sure you have right password, compression or encryption is well configured.",
          e);
    }
    if (check == null && !engine.isReadOnly()) {
      // new db, so insert testing record
      byte[] b = new byte[127];
      new Random().nextBytes(b);
      check = Fun.t2(Arrays.hashCode(b), b);
      engine.update(Engine.CHECK_RECORD, check, Serializer.BASIC);
      engine.commit();
    }

    return engine;
  }