@Override
  public void applySlotChanges(
      Visitable<SlotChange> slotChangeTree, int slotChangeCount, Slot reservedSlot) {
    if (slotChangeCount < 1) {
      return;
    }

    Runnable commitHook = _container.commitHook();
    flushDatabaseFile();

    ensureLogAndLock();
    int length = transactionLogSlotLength(slotChangeCount);
    ByteArrayBuffer logBuffer = new ByteArrayBuffer(length);
    logBuffer.writeInt(length);
    logBuffer.writeInt(slotChangeCount);

    appendSlotChanges(logBuffer, slotChangeTree);
    write(_logFile, logBuffer);
    _logFile.sync();

    writeToLockFile(LOCK_INT);

    writeSlots(slotChangeTree);
    commitHook.run();
    flushDatabaseFile();
    writeToLockFile(0);
  }
 private void writeToLockFile(int lockSignal) {
   ByteArrayBuffer lockBuffer = newLockFileBuffer();
   lockBuffer.writeInt(lockSignal);
   lockBuffer.writeInt(lockSignal);
   write(_lockFile, lockBuffer);
   _lockFile.sync();
 }
Пример #3
0
 public void write(ByteArrayBuffer writer) {
   if (slotModified()) {
     writer.writeInt(_key);
     writer.writeInt(_newSlot.address());
     writer.writeInt(_newSlot.length());
   }
 }
Пример #4
0
 public void write(ByteArrayBuffer writer) {
   writer.writeInt(indexAddress);
   writer.writeInt(indexEntries);
   writer.writeInt(indexLength);
   writer.writeInt(patchAddress);
   writer.writeInt(patchEntries);
   writer.writeInt(patchLength);
 }
Пример #5
0
 public void write(Object a_object, ByteArrayBuffer a_bytes) {
   if (Deploy.debug) {
     a_bytes.writeBegin(Const4.YAPBYTE);
   }
   a_bytes.writeByte(((Byte) a_object).byteValue());
   if (Deploy.debug) {
     a_bytes.writeEnd();
   }
 }
 public RawClassSpec readSpec(Transaction trans, ByteArrayBuffer reader) {
   byte[] nameBytes = readName(trans, reader);
   String className = trans.container().stringIO().read(nameBytes);
   readMetaClassID(reader); // skip
   int ancestorID = reader.readInt();
   reader.incrementOffset(Const4.INT_LENGTH); // index ID
   int numFields = reader.readInt();
   return new RawClassSpec(className, ancestorID, numFields);
 }
Пример #7
0
  public void read(ByteArrayBuffer reader) {
    indexAddress = reader.readInt();
    indexEntries = reader.readInt();
    indexLength = reader.readInt();

    // no longer used apparently
    /*patchAddress = */ reader.readInt();
    /*patchEntries = */ reader.readInt();
    /*patchLength = */ reader.readInt();
  }
Пример #8
0
 Object read1(ByteArrayBuffer a_bytes) {
   if (Deploy.debug) {
     a_bytes.readBegin(Const4.YAPBYTE);
   }
   byte ret = a_bytes.readByte();
   if (Deploy.debug) {
     a_bytes.readEnd();
   }
   return new Byte(ret);
 }
Пример #9
0
 static final void writeShort(int a_short, ByteArrayBuffer a_bytes) {
   if (Deploy.debug) {
     a_bytes.writeBegin(Const4.YAPSHORT);
   }
   for (int i = 0; i < Const4.SHORT_BYTES; i++) {
     a_bytes._buffer[a_bytes._offset++] = (byte) (a_short >> ((Const4.SHORT_BYTES - 1 - i) * 8));
   }
   if (Deploy.debug) {
     a_bytes.writeEnd();
   }
 }
Пример #10
0
 private byte[] readName(LatinStringIO sio, ByteArrayBuffer reader) {
   if (Deploy.debug) {
     reader.readBegin(Const4.YAPCLASS);
   }
   int len = reader.readInt();
   len = len * sio.bytesPerChar();
   byte[] nameBytes = new byte[len];
   System.arraycopy(reader._buffer, reader._offset, nameBytes, 0, len);
   nameBytes = Platform4.updateClassName(nameBytes);
   reader.incrementOffset(len);
   return nameBytes;
 }
Пример #11
0
 public Object read(ByteArrayBuffer buffer) {
   int size = buffer.readInt();
   int address = buffer.readInt();
   if (size > sizeLimit) {
     FreeSlotNode node = new FreeSlotNode(size);
     node.createPeer(address);
     if (Deploy.debug && Debug.xbytes) {
       debugCheckBuffer(buffer, node);
     }
     return node;
   }
   return null;
 }
 private boolean lockFileSignalsInterruptedTransaction() {
   openLockFile();
   ByteArrayBuffer buffer = newLockFileBuffer();
   read(_lockFile, buffer);
   for (int i = 0; i < 2; i++) {
     int checkInt = buffer.readInt();
     if (checkInt != LOCK_INT) {
       closeLockFile();
       return false;
     }
   }
   closeLockFile();
   return true;
 }
Пример #13
0
  public final void read(ObjectContainerBase stream, ClassMetadata clazz, ByteArrayBuffer reader) {
    clazz.setAncestor(stream.classMetadataForId(reader.readInt()));

    if (clazz.callConstructor()) {
      // The logic further down checks the ancestor YapClass, whether
      // or not it is allowed, not to call constructors. The ancestor
      // YapClass may possibly have not been loaded yet.
      clazz.createConstructor(stream, clazz.classReflector(), clazz.getName(), true);
    }

    clazz.checkType();

    readIndex(stream, clazz, reader);

    clazz._aspects = createFields(clazz, reader.readInt());
    readFields(stream, reader, clazz._aspects);
  }
Пример #14
0
  public void write(
      final Transaction trans, final ClassMetadata clazz, final ByteArrayBuffer writer) {

    writer.writeShortString(trans, clazz.nameToWrite());

    int intFormerlyKnownAsMetaClassID = 0;
    writer.writeInt(intFormerlyKnownAsMetaClassID);

    writer.writeIDOf(trans, clazz.i_ancestor);

    writeIndex(trans, clazz, writer);

    writer.writeInt(clazz.declaredAspectCount());
    clazz.forEachDeclaredAspect(
        new Procedure4() {
          public void apply(Object arg) {
            _family._field.write(trans, clazz, (ClassAspect) arg, writer);
          }
        });
  }
 public void completeInterruptedTransaction(int transactionId1, int transactionId2) {
   if (!File4.exists(lockFileName(_fileName))) {
     return;
   }
   if (!lockFileSignalsInterruptedTransaction()) {
     return;
   }
   ByteArrayBuffer buffer = new ByteArrayBuffer(Const4.INT_LENGTH);
   openLogFile();
   read(_logFile, buffer);
   int length = buffer.readInt();
   if (length > 0) {
     buffer = new ByteArrayBuffer(length);
     read(_logFile, buffer);
     buffer.incrementOffset(Const4.INT_LENGTH);
     readWriteSlotChanges(buffer);
   }
   deleteLockFile();
   closeLogFile();
   deleteLogFile();
 }
Пример #16
0
 protected void readIndex(
     ObjectContainerBase stream, ClassMetadata clazz, ByteArrayBuffer reader) {
   int indexID = reader.readInt();
   if (!stream.maintainsIndices() || !(stream instanceof LocalObjectContainer)) {
     return;
   }
   if (btree(clazz) != null) {
     return;
   }
   clazz.index().read(stream, validIndexId(indexID));
   if (isOldClassIndex(indexID)) {
     new ClassIndexesToBTrees_5_5().convert((LocalObjectContainer) stream, indexID, btree(clazz));
     stream.setDirtyInSystemTransaction(clazz);
   }
 }
Пример #17
0
 public Object read(ByteArrayBuffer reader) {
   SlotChange change = new SlotChange(reader.readInt());
   Slot newSlot = new Slot(reader.readInt(), reader.readInt());
   change.newSlot(newSlot);
   return change;
 }
 private void write(Bin storage, ByteArrayBuffer buffer) {
   storage.write(0, buffer._buffer, buffer.length());
 }
 private void read(Bin storage, ByteArrayBuffer buffer) {
   storage.read(0, buffer._buffer, buffer.length());
 }
Пример #20
0
 protected void writeIndex(Transaction trans, ClassMetadata clazz, ByteArrayBuffer writer) {
   int indexID = clazz.index().write(trans);
   writer.writeInt(indexIDForWriting(indexID));
 }
Пример #21
0
 public final void write(ByteArrayBuffer a_writer) {
   // byte order: size, address
   a_writer.writeInt(_key);
   a_writer.writeInt(_peer._key);
 }
Пример #22
0
 public final int readMetaClassID(ByteArrayBuffer reader) {
   return reader.readInt();
 }