public override void WriteFixedPart(LocalObjectContainer file, bool startFileLockingThread , bool shuttingDown, StatefulBuffer writer, int blockSize) { SystemData systemData = file.SystemData(); writer.Append(Signature); writer.WriteByte(Version()); writer.WriteInt((int)TimeToWrite(_timerFileLock.OpenTime(), shuttingDown)); writer.WriteLong(TimeToWrite(_timerFileLock.OpenTime(), shuttingDown)); writer.WriteLong(TimeToWrite(Runtime.CurrentTimeMillis(), shuttingDown)); writer.WriteInt(blockSize); writer.WriteInt(systemData.ClassCollectionID()); writer.WriteByte(systemData.IdSystemType()); writer.WriteInt(((FileHeaderVariablePart2)_variablePart).Address()); writer.WriteInt(((FileHeaderVariablePart2)_variablePart).Length()); writer.WriteInt(_transactionPointerAddress); writer.Write(); if (shuttingDown) { WriteVariablePart(file, true); } else { file.SyncFiles(); } if (startFileLockingThread) { file.ThreadPool().Start("db4o lock thread", _timerFileLock); } }
public override void WriteFixedPart(LocalObjectContainer file, bool startFileLockingThread , bool shuttingDown, StatefulBuffer writer, int blockSize) { var systemData = file.SystemData(); writer.Append(Signature); writer.WriteByte(Version()); writer.WriteInt((int) TimeToWrite(_timerFileLock.OpenTime(), shuttingDown)); writer.WriteLong(TimeToWrite(_timerFileLock.OpenTime(), shuttingDown)); writer.WriteLong(TimeToWrite(Runtime.CurrentTimeMillis(), shuttingDown)); writer.WriteInt(blockSize); writer.WriteInt(systemData.ClassCollectionID()); writer.WriteByte(systemData.IdSystemType()); writer.WriteInt(((FileHeaderVariablePart2) _variablePart).Address()); writer.WriteInt(((FileHeaderVariablePart2) _variablePart).Length()); writer.WriteInt(_transactionPointerAddress); writer.Write(); if (shuttingDown) { WriteVariablePart(file, true); } else { file.SyncFiles(); } if (startFileLockingThread) { file.ThreadPool().Start("db4o lock thread", _timerFileLock); } }
public virtual StatefulBuffer PayLoad() { StatefulBuffer writer = new StatefulBuffer(Transaction(), Const4.MessageLength); writer.WriteInt(_msgID); return(writer); }
public void ProcessAtServer() { IServerMessageDispatcher dispatcher = (IServerMessageDispatcher)MessageDispatcher (); int count = ReadInt(); Transaction ta = Transaction(); for (int i = 0; i < count; i++) { StatefulBuffer writer = _payLoad.ReadStatefulBuffer(); int messageId = writer.ReadInt(); Msg message = Msg.GetMessage(messageId); Msg clonedMessage = message.PublicClone(); clonedMessage.SetMessageDispatcher(MessageDispatcher()); clonedMessage.SetTransaction(ta); if (clonedMessage is MsgD) { MsgD msgd = (MsgD)clonedMessage; msgd.PayLoad(writer); if (msgd.PayLoad() != null) { msgd.PayLoad().IncrementOffset(Const4.IntLength); Transaction t = CheckParentTransaction(ta, msgd.PayLoad()); msgd.SetTransaction(t); dispatcher.ProcessMessage(msgd); } } else { dispatcher.ProcessMessage(clonedMessage); } } }
public DeleteContextImpl(StatefulBuffer buffer, ObjectHeader objectHeader, IReflectClass fieldClass, Config4Field fieldConfig) : base(buffer .Transaction(), buffer, objectHeader) { _fieldClass = fieldClass; _fieldConfig = fieldConfig; }
// FIXME: This code has not been called in any test case when the // new ArrayMarshaller was written. // Apparently it only frees slots. // For now the code simply returns without freeing. /// <param name="classPrimitive"></param> public void DeletePrimitiveEmbedded(StatefulBuffer buffer, PrimitiveTypeMetadata classPrimitive) { buffer.ReadInt(); //int address = a_bytes.readInt(); buffer.ReadInt(); }
public virtual void WriteIndexEntry(IContext context, ByteArrayBuffer writer, object entry) { if (entry == null) { writer.WriteInt(0); writer.WriteInt(0); return; } if (entry is StatefulBuffer) { StatefulBuffer entryAsWriter = (StatefulBuffer)entry; writer.WriteInt(entryAsWriter.GetAddress()); writer.WriteInt(entryAsWriter.Length()); return; } if (entry is Slot) { Slot s = (Slot)entry; writer.WriteInt(s.Address()); writer.WriteInt(s.Length()); return; } throw new ArgumentException(); }
public Msg ReplyFromServer() { try { lock (ContainerLock()) { IReflectClass claxx = SystemTransaction().Reflector().ForName(ReadString()); if (claxx != null) { ClassMetadata classMetadata = Container().ProduceClassMetadata(claxx); if (classMetadata != null) { Container().CheckStillToSet(); StatefulBuffer returnBytes = Container().ReadStatefulBufferById(SystemTransaction (), classMetadata.GetID()); MsgD createdClass = Msg.ObjectToClient.GetWriter(returnBytes); return(createdClass); } } } } catch (Db4oException) { } // TODO: send the exception to the client return(Msg.Failed); }
private void DebugCheckBuffer(ByteArrayBuffer buffer, Db4objects.Db4o.Internal.Freespace.FreeSlotNode node) { if (!(buffer is StatefulBuffer)) { return; } Transaction trans = ((StatefulBuffer)buffer).Transaction(); if (!(trans.Container() is IoAdaptedObjectContainer)) { return; } StatefulBuffer checker = trans.Container().CreateStatefulBuffer(trans, node._peer ._key, node._key); checker.Read(); for (int i = 0; i < node._key; i++) { if (checker.ReadByte() != (byte)'X') { Sharpen.Runtime.Out.WriteLine("!!! Free space corruption at:" + node._peer._key); break; } } }
public virtual Msg ReplyFromServer() { Unmarshall(); try { lock (ContainerLock()) { ClassInfo classInfo = (ClassInfo)ReadObjectFromPayLoad(); ClassInfoHelper classInfoHelper = ServerMessageDispatcher().ClassInfoHelper(); GenericClass genericClass = classInfoHelper.ClassMetaToGenericClass(Container().Reflector (), classInfo); if (genericClass != null) { Transaction trans = Container().SystemTransaction(); ClassMetadata classMetadata = Container().ProduceClassMetadata(genericClass); if (classMetadata != null) { Container().CheckStillToSet(); classMetadata.SetStateDirty(); classMetadata.Write(trans); trans.Commit(); StatefulBuffer returnBytes = Container().ReadStatefulBufferById(trans, classMetadata .GetID()); return(Msg.ObjectToClient.GetWriter(returnBytes)); } } } } catch (Exception e) { } return(Msg.Failed); }
private void AppendPayLoad(StatefulBuffer target, Pointer4 pointer, ByteArrayBuffer payLoad) { target.WriteInt(payLoad.Length()); target.WriteInt(pointer.Id()); target.WriteInt(pointer.Address()); target.Append(payLoad._buffer); }
/// <summary>generates a new Db4oDatabase object with a unique signature.</summary> /// <remarks>generates a new Db4oDatabase object with a unique signature.</remarks> public static Db4objects.Db4o.Ext.Db4oDatabase Generate() { StatefulBuffer writer = new StatefulBuffer(null, 300); new LatinStringIO().Write(writer, SignatureGenerator.GenerateSignature()); return(new Db4objects.Db4o.Ext.Db4oDatabase(writer.GetWrittenBytes(), Runtime.CurrentTimeMillis ())); }
public virtual Db4objects.Db4o.CS.Internal.Messages.MsgD GetWriter(StatefulBuffer bytes) { Db4objects.Db4o.CS.Internal.Messages.MsgD message = GetWriterForLength(bytes.Transaction (), bytes.Length()); message._payLoad.Append(bytes._buffer); return(message); }
public override MsgD GetWriter(StatefulBuffer bytes) { var message = GetWriterForLength(bytes.Transaction(), bytes.Length() + Const4.IntLength ); message._payLoad.WriteInt(bytes.GetAddress()); message._payLoad.Append(bytes._buffer); return(message); }
public virtual MsgD GetWriter(StatefulBuffer bytes) { var message = GetWriterForLength(bytes.Transaction (), bytes.Length()); message._payLoad.Append(bytes._buffer); return(message); }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public static Db4objects.Db4o.CS.Internal.Messages.Msg ReadMessage(IMessageDispatcher messageDispatcher, Db4objects.Db4o.Internal.Transaction trans, Socket4Adapter socket ) { StatefulBuffer reader = ReadMessageBuffer(trans, socket); Db4objects.Db4o.CS.Internal.Messages.Msg message = _messages[reader.ReadInt()].ReadPayLoad (messageDispatcher, trans, socket, reader); return(message); }
public virtual void Test() { StatefulBuffer writer = new StatefulBuffer(null, 300); string stringRepresentation = SignatureGenerator.GenerateSignature(); new LatinStringIO().Write(writer, stringRepresentation); Signature signature = new Signature(writer.GetWrittenBytes()); Assert.AreEqual(stringRepresentation, signature.ToString()); }
/// <exception cref="Db4objects.Db4o.Internal.FieldIndexException"></exception> protected virtual void RebuildIndexForObject(LocalObjectContainer container, int objectId) { StatefulBuffer writer = container.ReadStatefulBufferById(container.SystemTransaction (), objectId); if (writer != null) { RebuildIndexForWriter(container, writer, objectId); } }
internal static void SlotEntryToZeroes(LocalObjectContainer file, int address) { var writer = new StatefulBuffer(file.SystemTransaction(), address, SlotLength ()); for (var i = 0; i < IntsInSlot; i++) { writer.WriteInt(0); } writer.WriteEncrypt(); }
/// <summary>This readIndexEntry method reads from the parent slot.</summary> /// <remarks>This readIndexEntry method reads from the parent slot.</remarks> /// <exception cref="Db4objects.Db4o.CorruptionException"></exception> /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public virtual object ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer buffer) { var payLoadOffSet = buffer.ReadInt(); var length = buffer.ReadInt(); if (payLoadOffSet == 0) { return null; } return buffer.ReadPayloadWriter(payLoadOffSet, length); }
/// <summary>This readIndexEntry method reads from the parent slot.</summary> /// <remarks>This readIndexEntry method reads from the parent slot.</remarks> /// <exception cref="Db4objects.Db4o.CorruptionException"></exception> /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public virtual object ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer buffer) { int payLoadOffSet = buffer.ReadInt(); int length = buffer.ReadInt(); if (payLoadOffSet == 0) { return(null); } return(buffer.ReadPayloadWriter(payLoadOffSet, length)); }
private MsgD BuildQueryResultMessage(int queryResultId, IIntIterator4 ids, int maxCount , ObjectExchangeConfiguration config) { ByteArrayBuffer payload = ObjectExchangeStrategyFactory.ForConfig(config).Marshall ((LocalTransaction)Transaction(), ids, maxCount); MsgD message = QueryResult.GetWriterForLength(Transaction(), Const4.IntLength + payload .Length()); StatefulBuffer writer = message.PayLoad(); writer.WriteInt(queryResultId); writer.WriteBytes(payload._buffer); return(message); }
protected virtual void WriteTransactionPointer(Transaction systemTransaction, int transactionPointer, int address, int offset) { StatefulBuffer bytes = new StatefulBuffer(systemTransaction, address, TransactionPointerLength ); bytes.MoveForward(offset); bytes.WriteInt(transactionPointer); bytes.WriteInt(transactionPointer); // Dangerous write. // On corruption transaction pointers will not be the same and nothing will happen. bytes.Write(); }
public void Visit(object treeInt) { int id = ((TreeInt)treeInt)._key; StatefulBuffer reader = stream.ReadStatefulBufferById(this._enclosing._enclosing. _trans, id); if (reader != null) { ObjectHeader oh = new ObjectHeader(stream, reader); CollectIdContext context = new CollectIdContext(this._enclosing._enclosing._trans , oh, reader); oh.ClassMetadata().CollectIDs(context, fieldName); Tree.Traverse(context.Ids(), new _IVisitor4_394(idsNew)); } }
public static Db4objects.Db4o.Internal.Marshall.CollectIdContext ForID(Transaction transaction, IdObjectCollector collector, int id) { StatefulBuffer reader = transaction.Container().ReadStatefulBufferById(transaction , id); if (reader == null) { return(null); } ObjectHeader oh = new ObjectHeader(transaction.Container(), reader); return(new Db4objects.Db4o.Internal.Marshall.CollectIdContext(transaction, collector , oh, reader)); }
public sealed override StatefulBuffer ReadStatefulBufferById(Transaction a_ta, int a_id, bool lastCommitted) { MsgD msg = Msg.ReadObject.GetWriterForInts(a_ta, new int[] { a_id, lastCommitted ? 1 : 0 }); Write(msg); StatefulBuffer bytes = ((MsgObject)ExpectedResponse(Msg.ObjectToClient)).Unmarshall (); if (bytes != null) { bytes.SetTransaction(a_ta); } return(bytes); }
public override bool CreateClassMetadata(ClassMetadata clazz, IReflectClass claxx , ClassMetadata superClazz) { Write(Msg.CreateClass.GetWriterForString(SystemTransaction(), Config().ResolveAliasRuntimeName (claxx.GetName()))); Msg resp = GetResponse(); if (resp == null) { return(false); } if (resp.Equals(Msg.Failed)) { // if the class can not be created on the server, send class meta to the server. SendClassMeta(claxx); resp = GetResponse(); } if (resp.Equals(Msg.Failed)) { if (ConfigImpl.ExceptionsOnNotStorable()) { throw new ObjectNotStorableException(claxx); } return(false); } if (!resp.Equals(Msg.ObjectToClient)) { return(false); } MsgObject message = (MsgObject)resp; StatefulBuffer bytes = message.Unmarshall(); if (bytes == null) { return(false); } bytes.SetTransaction(SystemTransaction()); if (!base.CreateClassMetadata(clazz, claxx, superClazz)) { return(false); } clazz.SetID(message.GetId()); clazz.ReadName1(SystemTransaction(), bytes); ClassCollection().AddClassMetadata(clazz); ClassCollection().ReadClassMetadata(clazz, claxx); return(true); }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> protected static StatefulBuffer ReadMessageBuffer(Db4objects.Db4o.Internal.Transaction trans, Socket4Adapter socket, int length) { StatefulBuffer buffer = new StatefulBuffer(trans, length); int offset = 0; while (length > 0) { int read = socket.Read(buffer._buffer, offset, length); if (read < 0) { throw new Db4oIOException(); } offset += read; length -= read; } return(buffer); }
public Msg ReplyFromServer() { StatefulBuffer bytes = null; // readWriterByID may fail in certain cases, for instance if // and object was deleted by another client int id = _payLoad.ReadInt(); int lastCommitted = _payLoad.ReadInt(); lock (ContainerLock()) { bytes = Container().ReadStatefulBufferById(Transaction(), id, lastCommitted == 1); } if (bytes == null) { bytes = new StatefulBuffer(Transaction(), 0, 0); } return(Msg.ObjectToClient.GetWriter(bytes)); }
public Msg ReplyFromServer() { var address = ReadInt(); var length = ReadInt(); lock (ContainerLock()) { var bytes = new StatefulBuffer(Transaction(), address, length); try { Container().ReadBytes(bytes._buffer, address, length); return(GetWriter(bytes)); } catch (Exception) { // TODO: not nicely handled on the client side yet return(Null); } } }
public override void CompleteInterruptedTransaction(int transactionId1, int transactionId2 ) { if (transactionId1 <= 0 || transactionId1 != transactionId2) { return; } var bytes = new StatefulBuffer(_container.SystemTransaction(), transactionId1 , Const4.IntLength); bytes.Read(); var length = bytes.ReadInt(); if (length > 0) { bytes = new StatefulBuffer(_container.SystemTransaction(), transactionId1, length ); bytes.Read(); bytes.IncrementOffset(Const4.IntLength); ReadWriteSlotChanges(bytes); } _container.WriteTransactionPointer(0); FlushDatabaseFile(); }
protected virtual void RebuildIndexForWriter(LocalObjectContainer container, StatefulBuffer buffer, int objectId) { var objectHeader = new ObjectHeader(container, buffer); var context = new ObjectIdContextImpl(container.SystemTransaction (), buffer, objectHeader, objectId); var classMetadata = context.ClassMetadata(); if (classMetadata.IsStruct()) { // We don't keep version information for structs. return; } if (classMetadata.SeekToField(container.SystemTransaction(), buffer, versionFieldMetadata ) != HandlerVersion.Invalid) { var version = ((long) versionFieldMetadata.Read(context)); if (version != 0) { var t = (LocalTransaction) container.SystemTransaction(); t.CommitTimestampSupport().Put(container.SystemTransaction(), objectId, version); } } }
public override ITypeHandler4 ReadCandidateHandler(QueryingReadContext context) { int id = 0; int offset = context.Offset(); try { id = context.ReadInt(); } catch (Exception) { } context.Seek(offset); if (id != 0) { StatefulBuffer reader = context.Container().ReadStatefulBufferById(context.Transaction (), id); if (reader != null) { ObjectHeader oh = new ObjectHeader(context.Container(), reader); try { if (oh.ClassMetadata() != null) { context.Buffer(reader); return(oh.ClassMetadata().SeekCandidateHandler(context)); } } catch (Exception e) { } } } // TODO: Check Exception Types // Errors typically occur, if classes don't match return(null); }
public override void CompleteInterruptedTransaction(int transactionId1, int transactionId2 ) { if (transactionId1 <= 0 || transactionId1 != transactionId2) { return; } StatefulBuffer bytes = new StatefulBuffer(_container.SystemTransaction(), transactionId1 , Const4.IntLength); bytes.Read(); int length = bytes.ReadInt(); if (length > 0) { bytes = new StatefulBuffer(_container.SystemTransaction(), transactionId1, length ); bytes.Read(); bytes.IncrementOffset(Const4.IntLength); ReadWriteSlotChanges(bytes); } _container.WriteTransactionPointer(0); FlushDatabaseFile(); }
protected virtual void RebuildIndexForWriter(LocalObjectContainer container, StatefulBuffer buffer, int objectId) { var objectHeader = new ObjectHeader(container, buffer); var context = new ObjectIdContextImpl(container.SystemTransaction (), buffer, objectHeader, objectId); var classMetadata = context.ClassMetadata(); if (classMetadata.IsStruct()) { // We don't keep version information for structs. return; } if (classMetadata.SeekToField(container.SystemTransaction(), buffer, versionFieldMetadata ) != HandlerVersion.Invalid) { var version = ((long)versionFieldMetadata.Read(context)); if (version != 0) { var t = (LocalTransaction)container.SystemTransaction(); t.CommitTimestampSupport().Put(container.SystemTransaction(), objectId, version); } } }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public override object ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer buffer) { return buffer.Container().ReadWriterByAddress(buffer.Transaction(), buffer.ReadInt (), buffer.ReadInt()); }
/// <param name="mf"></param> /// <param name="buffer"></param> /// <param name="redirect"></param> /// <exception cref="Db4objects.Db4o.CorruptionException"></exception> public virtual object Read(MarshallerFamily mf, StatefulBuffer buffer, bool redirect ) { return Read1(buffer); }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> public object ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer statefulBuffer ) { return Read(mf, statefulBuffer, true); }
// TODO: freespaceID should not be passed here, it should be taken from SystemData public abstract void WriteFixedPart(LocalObjectContainer file, bool startFileLockingThread , bool shuttingDown, StatefulBuffer writer, int blockSize);
protected virtual void WriteTransactionPointer(Transaction systemTransaction, int transactionPointer, int address, int offset) { var bytes = new StatefulBuffer(systemTransaction, address, TransactionPointerLength ); bytes.MoveForward(offset); bytes.WriteInt(transactionPointer); bytes.WriteInt(transactionPointer); // Dangerous write. // On corruption transaction pointers will not be the same and nothing will happen. bytes.Write(); }
public override void WriteFixedPart(LocalObjectContainer file, bool startFileLockingThread , bool shuttingDown, StatefulBuffer writer, int blockSize) { throw new InvalidOperationException(); }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> public object ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer statefulBuffer ) { return ReadIndexEntry(statefulBuffer.Transaction().Context(), statefulBuffer); }
public override void ApplySlotChanges(IVisitable slotChangeTree, int slotChangeCount , Slot reservedSlot) { if (slotChangeCount > 0) { var transactionLogSlot = SlotLongEnoughForLog(slotChangeCount, reservedSlot) ? reservedSlot : AllocateSlot(true, slotChangeCount); var buffer = new StatefulBuffer(_container.SystemTransaction(), transactionLogSlot ); buffer.WriteInt(transactionLogSlot.Length()); buffer.WriteInt(slotChangeCount); AppendSlotChanges(buffer, slotChangeTree); buffer.Write(); var commitHook = _container.CommitHook(); FlushDatabaseFile(); _container.WriteTransactionPointer(transactionLogSlot.Address()); FlushDatabaseFile(); if (WriteSlots(slotChangeTree)) { FlushDatabaseFile(); } _container.WriteTransactionPointer(0); commitHook.Run(); FlushDatabaseFile(); if (transactionLogSlot != reservedSlot) { FreeSlot(transactionLogSlot); } } FreeSlot(reservedSlot); }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> public override object Read(MarshallerFamily mf, StatefulBuffer buffer, bool redirect ) { return mf._primitive.ReadShort(buffer); }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> public override object Read(MarshallerFamily mf, StatefulBuffer writer, bool redirect ) { return mf._primitive.ReadFloat(writer); }