예제 #1
0
 public void open() throws IOException {
   _mappingDb = DefragmentServicesImpl.freshTempFile(_fileName, 1);
   _idTree =
       (_treeSpec == null
           ? new BTree(trans(), 0, new MappedIDPairHandler())
           : new BTree(trans(), 0, new MappedIDPairHandler(), _treeSpec.nodeSize()));
   _slotTree =
       (_treeSpec == null
           ? new BTree(trans(), 0, new BTreeIdSystem.IdSlotMappingHandler())
           : new BTree(
               trans(), 0, new BTreeIdSystem.IdSlotMappingHandler(), _treeSpec.nodeSize()));
 }
  public void processClassCollection(final DefragmentServicesImpl services)
      throws CorruptionException, IOException {
    DefragmentContextImpl.processCopy(
        services,
        services.sourceClassCollectionID(),
        new SlotCopyHandler() {
          public void processCopy(DefragmentContextImpl context) {
            if (Deploy.debug) {
              context.readBegin(Const4.YAPCLASSCOLLECTION);
            }

            int acceptedClasses = 0;
            int numClassesOffset = context.targetBuffer().offset();
            acceptedClasses = copyAcceptedClasses(context, acceptedClasses);
            writeIntAt(context.targetBuffer(), numClassesOffset, acceptedClasses);

            if (Deploy.debug) {
              context.readEnd();
            }
          }

          private int copyAcceptedClasses(DefragmentContextImpl context, int acceptedClasses) {
            int numClasses = context.readInt();
            for (int classIdx = 0; classIdx < numClasses; classIdx++) {
              int classId = context.sourceBuffer().readInt();
              if (!accept(classId)) {
                continue;
              }
              ++acceptedClasses;
              context.writeMappedID(classId);
            }
            return acceptedClasses;
          }

          private void writeIntAt(ByteArrayBuffer target, int offset, int value) {
            int currentOffset = target.offset();
            target.seek(offset);
            target.writeInt(value);
            target.seek(currentOffset);
          }

          private boolean accept(int classId) {
            return services.accept(services.classMetadataForId(classId));
          }
        });
  }
 public void processClass(
     final DefragmentServicesImpl services,
     final ClassMetadata classMetadata,
     int id,
     final int classIndexID)
     throws CorruptionException, IOException {
   if (services.mappedID(id, -1) == -1) {
     System.err.println("MAPPING NOT FOUND: " + id);
   }
   DefragmentContextImpl.processCopy(
       services,
       id,
       new SlotCopyHandler() {
         public void processCopy(DefragmentContextImpl context) {
           classMetadata.defragClass(context, classIndexID);
         }
       });
 }
 public void processObjectSlot(
     final DefragmentServicesImpl services, final ClassMetadata classMetadata, int id)
     throws CorruptionException, IOException {
   ByteArrayBuffer sourceBuffer = services.sourceBufferByID(id);
   DefragmentContextImpl.processCopy(
       services,
       id,
       new SlotCopyHandler() {
         public void processCopy(DefragmentContextImpl context) {
           ClassMetadata.defragObject(context);
           if (_objectCommitFrequency > 0) {
             _objectCount++;
             if (_objectCount == _objectCommitFrequency) {
               services.targetCommit();
               services.mapping().commit();
               _objectCount = 0;
             }
           }
         }
       },
       sourceBuffer);
 }