Examples of IExclusiveDataAccessSession


Examples of net.sf.joafip.service.IExclusiveDataAccessSession

    // final int maxObjectState = 4 * 1000;
    // win seven sun jvm 64 bits
    final int maxObjectState = 2 * 100 * 1000;

    final int max = 100000;
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();

    List<Integer> bigList;
    final IInstanceFactory instanceFactory = session.getInstanceFactory();
    bigList = PLinkedList.newInstance(instanceFactory);

    session.save();
    assertTrue("must be a proxy", ProxyManager2.isProxyOrEnhanced(bigList));
    for (int count = 0; count < max; count++) {
      final int value = aValue(count);
      bigList.add(value); // this make bigList growing in memory
      if (count % 1000 == 999) {
        try {
          session.save();
        } catch (OutOfMemoryError error) {
          MEMORY_EATER.releaseMemory();
          final List<ObjectAndPersistInfo> list = filePersistence
              .getObjectAndPersistInfoOfObjectFromQueue();
          int weakCount = 0;
          int noRefCount = 0;
          for (ObjectAndPersistInfo objpi : list) {
            if (objpi.hasNoReferences()) {
              noRefCount++;
            } else if (objpi.isWeak()) {
              weakCount++;
            }
          }
          final String message = "out of memory at #" + count
              + ", total " + list.size() + ", no ref "
              + noRefCount + ", weak " + weakCount;
          throw new RuntimeException(message, error);// NOPMD
        }
        assertTrue("must be unloaded",
            ProxyManager2.isUnloaded(bigList));

        if (logger.debugEnabled) {
          final String stateMessage = HelperTestHugeList
              .objectState(filePersistence);
          logger.debug(stateMessage);
        }
        final int numberOfObjectState = filePersistence
            .getNumberOfObjectState();
        assertTrue("too much object state " + numberOfObjectState
            + ", count #" + count,
            numberOfObjectState < maxObjectState);
      }
    }

    session.save();

    session.setObject("myBigList", bigList);
    bigList = null; // NOPMD no more reference the big list
    session.save(); // after this the garbage collector can free memory
            // of
    // the big list
    // witchery of lazy load: all the big list is not loaded in memory
    bigList = (List<Integer>) session.getObject("myBigList");
    int count = 0;
    for (final int value : bigList) {
      doSomething(value);
      if (count % 1000 == 999) {
        session.save();
        final int numberOfObjectState = filePersistence
            .getNumberOfObjectState();
        assertTrue("too much object state " + numberOfObjectState
            + ", count #" + count,
            numberOfObjectState < maxObjectState);
      }
      count++;
    }
    session.close();
    assertTrue("object state map never cleaned", decreaseCount > 0);
    logger.debug("object state map decrease count=" + decreaseCount);
  }
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

      FilePersistenceClassNotFoundException,
      FilePersistenceInvalidClassException,
      FilePersistenceDataCorruptedException,
      FilePersistenceNotSerializableException,
      FilePersistenceTooBigForSerializationException {
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();

    final IInstanceFactory instanceFactory = session.getInstanceFactory();
    session.open();
    final TreeSupport<String> tree = TreeSupport.newInstance(
        instanceFactory, null, true, false);
    tree.add(ID_KEY_NAME);
    tree.add(TYPE_KEY_NAME);
    final Iterator<String> iterator = tree.iterator();
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

    filePersistence.autoSaveSetup(0);// 0 is important for the test
    filePersistence.setAutoSaveEnabled(true);
    filePersistence.maintainInMemorySetup(500);
    filePersistence.setMaintainedInMemoryEnabled(true);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();
    session.setObject("key1", new Object());
    session.save();
    session.setObject("key2", new Object());
    session.save();
    session.close();
    filePersistence.close();
  }
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

      FilePersistenceClassNotFoundException,
      FilePersistenceDataCorruptedException,
      FilePersistenceTooBigForSerializationException, RBTException {
    final IFilePersistence filePersistence = createFilePersistence();
    // filePersistence.setAutoSaveEventListener(this);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();

    session.open();

    try {
      TypeA typeA = TypeA.newInstance(instanceFactory);
      TypeB typeB = TypeB.newInstance(instanceFactory);
      typeA.setTypeB(typeB);
      typeB.setTypeA(typeA);
      session.setObject("key", typeA);

      for (int count = 0; count < 1000; count++) {
        typeA = (TypeA) session.getObject("key");
        typeB = typeA.getTypeB();
        if (typeB.getTypeA() != typeA) {
          throw new Exception("not same object count=" + count);
        }
        typeA = null;// NOPMD
        typeB = null;// NOPMD
      }

    } catch (Exception e) {
      e.printStackTrace();// NOPMD
    } finally {
      session.close();
    }

    filePersistence.xmlExport("runtime", "runtime/temp", false);
    filePersistence.close();
  }
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

    builder.setMaxBufferSize(8 * 1024);
    builder.setMaxNumberOfBuffer(32);
    builder.setPathName(TestConstant.getWinRamDiskRuntimeDir());
    builder.setProxyMode(true);
    final IFilePersistence filePersistence = builder.build();
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    final IInstanceFactory instancefactory = session.getInstanceFactory();
    session.open();
    final PHashMap map = PHashMap.newInstance(instancefactory);
    assertNotNull("must succeed create an iterator", map.keySet()
        .iterator());
    session.close();
    filePersistence.close();
  }
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

      FilePersistenceDataCorruptedException,
      FilePersistenceNotSerializableException, ProxyException,
      TestException, ObjectIOException, ObjectIODataCorruptedException,
      HeapException, FilePersistenceTooBigForSerializationException,
      HeapRecordableException {
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();

    garbageDataIntegrityChecker.check(filePersistence);

    final IInstanceFactory instanceFactory = session.getInstanceFactory();
    Bob1 bob1 = Bob1.newInstance(instanceFactory, true);
    bob1.setVal(10);
    session.save();

    assertTrue("must be unloaded", ProxyManager2.isUnloaded(bob1));
    final DataRecordIdentifier dataRecordIdentifier = filePersistence
        .getCurrentDataRecordIdentifierAssociatedToObject(bob1);
    assertNotNull("bob1 must be saved as a detached object",
        dataRecordIdentifier);

    garbageDataIntegrityChecker.check(filePersistence);
    assertAttachedState(dataRecordIdentifier, false);
    assertTrue("bob1 #" + dataRecordIdentifier// NOPMD
        + " must be a garbage candidate",
        garbageDataIntegrityChecker
            .isKnownCandidate(dataRecordIdentifier));
    assertFalse("bob1 #" + dataRecordIdentifier + "must not be to garbage",
        garbageDataIntegrityChecker
            .isKnownToGarbage(dataRecordIdentifier));
    session.setObject("bob1",bob1);
   
    session.close(EnumFilePersistenceCloseAction.SAVE);
    filePersistence.garbageSweep("runtime/set");
    session.open();
   
    garbageDataIntegrityChecker.check(filePersistence);
    assertAttachedState(dataRecordIdentifier, true);
    assertFalse("bob1 #" + dataRecordIdentifier
        + " must not be a garbage candidate",
        garbageDataIntegrityChecker
            .isKnownCandidate(dataRecordIdentifier));
    assertFalse("bob1 #" + dataRecordIdentifier + "must not be to garbage",
        garbageDataIntegrityChecker
            .isKnownToGarbage(dataRecordIdentifier));

    // check if kept in file
    bob1 = (Bob1) filePersistence
        .createObjectReadingInStoreOrGetExisting(dataRecordIdentifier);
    assertEquals("bad value", 10, bob1.getVal());
   
    session.close();

    garbageDataIntegrityChecker.check(filePersistence);
    assertAttachedState(dataRecordIdentifier, true);
    filePersistence.garbageSweep("runtime/set");
    garbageDataIntegrityChecker.check(filePersistence);
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

      FilePersistenceDataCorruptedException,
      FilePersistenceNotSerializableException, ProxyException,
      TestException, ObjectIOException, ObjectIODataCorruptedException,
      FilePersistenceTooBigForSerializationException, HeapException {
    filePersistence.setGarbageListener(this);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();
    final Bob1 bob1 = Bob1.newInstance(instanceFactory, true);
    bob1.setVal(10);
    session.save();
    final DataRecordIdentifier dataRecordIdentifier = filePersistence
        .getCurrentDataRecordIdentifierAssociatedToObject(bob1);
    assertNotNull("bob1 must be saved as a detached object",
        dataRecordIdentifier);

    garbageDataIntegrityChecker.check(filePersistence);
    assertAttachedState(dataRecordIdentifier, false);
    backgroundGarbageSweep();
    // check if kept in file
    assertTrue("must be unloaded", ProxyManager2.isUnloaded(bob1));
    assertEquals("bad value", 10, bob1.getVal());
    session.close();

    garbageDataIntegrityChecker.check(filePersistence);
    assertAttachedState(dataRecordIdentifier, false);
    backgroundGarbageSweep();
    garbageDataIntegrityChecker.check(filePersistence);

    session.open();
    assertDeleted(dataRecordIdentifier);
    final Integer integer = (Integer) session.getObject("K0");
    assertNotNull("must have value", integer);
    assertEquals("bad balue", 0, integer.intValue());
    session.close();
  }
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

      FilePersistenceInvalidClassException,
      FilePersistenceDataCorruptedException,
      FilePersistenceNotSerializableException, ProxyException,
      ObjectIOException, ObjectIODataCorruptedException, TestException,
      FilePersistenceTooBigForSerializationException, HeapException {
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();
    Bob1 bob1 = Bob1.newInstance(instanceFactory, true);
    bob1.setVal(10);
    session.save();
    final DataRecordIdentifier dataRecordIdentifier = filePersistence
        .getCurrentDataRecordIdentifierAssociatedToObject(bob1);
    assertNotNull("bob1 must be saved as a detached object",
        dataRecordIdentifier);

    garbageDataIntegrityChecker.check(filePersistence);
    assertAttachedState(dataRecordIdentifier, false);

    session.close(EnumFilePersistenceCloseAction.SAVE);
    filePersistence.garbageSweep("runtime/set");
//    session.open();

//    // check if kept in file
//    assertTrue("must be unloaded", ProxyManager2.isUnloaded(bob1));
//    assertEquals("bad value", 10, bob1.getVal());
//
//    bob1 = null;// NOPMD release object

//    _LOG.debug("session close");
//    session.close();

    garbageDataIntegrityChecker.check(filePersistence);
    assertAttachedState(dataRecordIdentifier, false);
    garbageDataIntegrityChecker.check(filePersistence);

    _LOG.debug("garbage sweep");
    filePersistence.garbageSweep("runtime/set");

    session.open();

    assertDeleted(dataRecordIdentifier);
    final Integer integer = (Integer) session.getObject("K0");
    assertNotNull("must have value", integer);
    assertEquals("bad balue", 0, integer.intValue());
    session.close();
  }
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

      FilePersistenceClassNotFoundException,
      FilePersistenceDataCorruptedException,
      FilePersistenceTooBigForSerializationException, RBTException {
    filePersistence = (FilePersistence) createFilePersistence();
    // filePersistence.setAutoSaveEventListener(this);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();

    session.open();

    int count = 0;
    try {
      final SimpleTreeOp<String> tree = SimpleTreeOp
          .newInstance(instanceFactory);
      session.setObject("tree", tree);

      RBTNode<String> nodeQ = RBTNode.newInstance(instanceFactory, "Q");
      RBTNode<String> nodeP = RBTNode.newInstance(instanceFactory, "P");

      RBTNode<String> nodeC = RBTNode.newInstance(instanceFactory, "C");
      RBTSentinel<String> nodeCLeft = RBTSentinel
          .newInstance(instanceFactory);
      nodeC.setLeft(nodeCLeft);
      nodeCLeft.setParent(nodeC);
      nodeCLeft = null;// NOPMD
      RBTSentinel<String> nodeCRight = RBTSentinel
          .newInstance(instanceFactory);
      nodeC.setRight(nodeCRight);
      nodeCRight.setParent(nodeC);
      nodeCRight = null;// NOPMD

      RBTNode<String> nodeA = RBTNode.newInstance(instanceFactory, "A");
      RBTSentinel<String> nodeALeft = RBTSentinel
          .newInstance(instanceFactory);
      nodeA.setLeft(nodeALeft);
      nodeALeft.setParent(nodeA);
      nodeALeft = null;// NOPMD
      RBTSentinel<String> nodeARight = RBTSentinel
          .newInstance(instanceFactory);
      nodeA.setRight(nodeARight);
      nodeARight.setParent(nodeA);
      nodeARight = null;// NOPMD

      RBTNode<String> nodeB = RBTNode.newInstance(instanceFactory, "B");
      RBTSentinel<String> nodeBLeft = RBTSentinel
          .newInstance(instanceFactory);
      nodeB.setLeft(nodeBLeft);
      nodeBLeft.setParent(nodeB);
      nodeBLeft = null;// NOPMD
      RBTSentinel<String> nodeBRight = RBTSentinel
          .newInstance(instanceFactory);
      nodeB.setRight(nodeBRight);
      nodeBRight.setParent(nodeB);
      nodeBRight = null;// NOPMD

      nodeQ.setRight(nodeC);
      nodeC.setParent(nodeQ);
      nodeQ.setLeft(nodeP);
      nodeP.setParent(nodeQ);
      nodeP.setRight(nodeB);
      nodeB.setParent(nodeP);
      nodeP.setLeft(nodeA);
      nodeA.setParent(nodeP);
      tree.setRootNode(nodeQ);

      nodeQ = nodeP = nodeA = nodeB = nodeC = null;// NOPMD

      for (count = 0; count < 1000; count++) {
        check1(tree);
        tree.rotateRight();
        check2(tree);
        tree.rotateLeft();
      }

    } catch (Exception e) {
      System.err.println("count=" + count);// NOPMD
      e.printStackTrace();// NOPMD
    } finally {
      session.close();
    }

    filePersistence.xmlExport("runtime", "runtime/temp", false);
    filePersistence.close();
  }
View Full Code Here

Examples of net.sf.joafip.service.IExclusiveDataAccessSession

      FilePersistenceClassNotFoundException,
      FilePersistenceInvalidClassException,
      FilePersistenceDataCorruptedException,
      FilePersistenceNotSerializableException, ProxyException,
      FilePersistenceTooBigForSerializationException {
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();
    saveDone = false;
    final BobContainer bobContainer = BobContainer.newBobContainer(session
        .getInstanceFactory());
    assertSaved();
    assertTrue("must be a proxy",
        ProxyManager2.isProxyOrEnhanced(bobContainer));
    // not be loaded because of auto save
    assertFalse("must not be loaded",
        ProxyManager2.proxiedObjectIsLoaded(bobContainer));
    saveDone = false;
    session.setObject(KEY, bobContainer);
    assertSaved();
    assertFalse("must not be loaded",
        ProxyManager2.proxiedObjectIsLoaded(bobContainer));
    bobContainer.getObject1();
    final BobContainer readBobContainer = (BobContainer) session
        .getObject(KEY);
    assertSame("must be the same proxy instance", bobContainer,
        readBobContainer);
    readBobContainer.getObject1();
    session.close();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.