public override long VersionForId(int id) { MsgD msg = Msg.VersionForId.GetWriterForInt(SystemTransaction(), id); _client.Write(msg); return(_client.ExpectedBufferResponse(Msg.VersionForId).ReadLong()); }
public override ClassMetadata ClassMetadataForID(int clazzId) { if (clazzId == 0) { return(null); } ClassMetadata yc = base.ClassMetadataForID(clazzId); if (yc != null) { return(yc); } MsgD msg = Msg.ClassNameForId.GetWriterForInt(SystemTransaction(), clazzId); Write(msg); MsgD message = (MsgD)ExpectedResponse(Msg.ClassNameForId); string className = Config().ResolveAliasStoredName(message.ReadString()); if (className != null && className.Length > 0) { IReflectClass claxx = Reflector().ForName(className); if (claxx != null) { return(ProduceClassMetadata(claxx)); } } // TODO inform client class not present return(null); }
public void WriteBatchedMessages() { lock (Lock()) { if (_batchedMessages.IsEmpty()) { return; } Msg msg; MsgD multibytes = Msg.WriteBatchedMessages.GetWriterForLength(Transaction, _batchedQueueLength ); multibytes.WriteInt(_batchedMessages.Size()); IEnumerator iter = _batchedMessages.GetEnumerator(); while (iter.MoveNext()) { msg = (Msg)iter.Current; if (msg == null) { multibytes.WriteInt(0); } else { multibytes.WriteInt(msg.PayLoad().Length()); multibytes.PayLoad().Append(msg.PayLoad()._buffer); } } WriteMessageToSocket(multibytes); ClearBatchedObjects(); } }
public sealed override void WriteNew(Transaction trans, Pointer4 pointer, ClassMetadata classMetadata, ByteArrayBuffer buffer) { MsgD msg = Msg.WriteNew.GetWriter(trans, pointer, classMetadata, buffer); WriteBatchedMessage(msg); }
public sealed override void WriteUpdate(Transaction trans, Pointer4 pointer, ClassMetadata classMetadata, ArrayType arrayType, ByteArrayBuffer buffer) { MsgD msg = Msg.WriteUpdate.GetWriter(trans, pointer, classMetadata, arrayType.Value (), buffer); WriteBatchedMessage(msg); }
public override AbstractQueryResult QueryAllObjects(Transaction trans) { int mode = Config().EvaluationMode().AsInt(); MsgD msg = Msg.GetAll.GetWriterForInts(trans, new int[] { mode, PrefetchDepth(), PrefetchCount() }); Write(msg); return(ReadQueryResult(trans)); }
public override void ReadBytes(byte[] a_bytes, int a_address, int a_length) { MsgD msg = Msg.ReadSlot.GetWriterForInts(_transaction, new int[] { a_address, a_length }); Write(msg); ByteArrayBuffer reader = ExpectedBufferResponse(Msg.ReadSlot); System.Array.Copy(reader._buffer, 0, a_bytes, 0, a_length); }
public override int InstanceCount(ClassMetadata clazz, Transaction trans) { MsgD msg = Msg.InstanceCount.GetWriterForInt(trans, clazz.GetID()); Write(msg); MsgD response = (MsgD)ExpectedResponse(Msg.InstanceCount); return(response.ReadInt()); }
private int AskServer(MsgD message, int param) { _client.Write(message.GetWriterForInts(_transaction, new[] { _queryResultID, param })); return(((MsgD)_client.ExpectedResponse(message)).ReadInt()); }
public sealed override bool Delete4(Transaction ta, ObjectReference yo, object obj , int a_cascade, bool userCall) { MsgD msg = Msg.Delete.GetWriterForInts(_transaction, new int[] { yo.GetID(), userCall ? 1 : 0 }); WriteBatchedMessage(msg); return(true); }
public override int ClassMetadataIdForName(string name) { MsgD msg = Msg.ClassMetadataIdForName.GetWriterForString(SystemTransaction(), name ); msg.Write(_socket); MsgD response = (MsgD)ExpectedResponse(Msg.ClassId); return(response.ReadInt()); }
public override IQueryResult ExecuteQuery(QQuery query) { Transaction trans = query.Transaction(); query.CaptureQueryResultConfig(); query.Marshall(); MsgD msg = Msg.QueryExecute.GetWriter(Serializer.Marshall(trans, query)); Write(msg); return(ReadQueryResult(trans)); }
public override bool Delete(ObjectReference @ref, int id, int cascade) { if (!base.Delete(@ref, id, cascade)) { return(false); } MsgD msg = Msg.TaDelete.GetWriterForInts(this, new int[] { id, cascade }); _client.WriteBatchedMessage(msg); return(true); }
private void AssertPrefetchingBehaviorFor(IQuery query, MsgD expectedFirstMessage ) { StoreFlatItemGraph(); Client().Config().PrefetchObjectCount(2); Client().Config().PrefetchDepth(1); AssertQueryIterationProtocol(query, expectedFirstMessage, new PrefetchConfigurationTestCase.Stimulus [] { new PrefetchConfigurationTestCase.Stimulus(new MsgD[] { }), new PrefetchConfigurationTestCase.Stimulus (new MsgD[] { }), new PrefetchConfigurationTestCase.Stimulus(new MsgD[] { Msg.ReadMultipleObjects }), new PrefetchConfigurationTestCase.Stimulus(new MsgD[] { }), new PrefetchConfigurationTestCase.Stimulus (new MsgD[] { Msg.ReadMultipleObjects }) }); }
private long[] GetIDsForClass(Transaction trans, ClassMetadata clazz, bool triggerQueryEvents ) { MsgD msg = Msg.GetInternalIds.GetWriterForInts(trans, new int[] { clazz.GetID(), PrefetchDepth(), PrefetchCount(), triggerQueryEvents ? 1 : 0 }); Write(msg); ByRef result = ByRef.NewInstance(); WithEnvironment(new _IRunnable_901(this, trans, result)); return((long[])result.value); }
private ByteArrayBuffer FetchSlotBuffer(Transaction transaction, int id, bool lastCommitted ) { MsgD msg = Msg.ReadReaderById.GetWriterForInts(transaction, new int[] { id, lastCommitted ? 1 : 0 }); Write(msg); ByteArrayBuffer buffer = ((MReadBytes)ExpectedResponse(Msg.ReadBytes)).Unmarshall (); return(buffer); }
private void AssertNonRecoverableExceptionForMessage(MsgD message, Exception throwable ) { // Make sure the ClassMetadata of the exception is in the // ObjectContainer otherwise we get side effects from producing it. IReflectClass reflectClass = Client().Reflector().ForClass(throwable.GetType()); Client().ProduceClassMetadata(reflectClass); _storage.SyncAllowed(false); Client().Write(message.GetWriterForSingleObject(Trans(), throwable)); AssertDatabaseClosedException(); AssertServerContainerStateClosed(true); }
public override bool IsDeleted(Transaction trans, int id) { // This one really is a hack. // It only helps to get information about the current // transaction. // We need a better strategy for C/S concurrency behaviour. MsgD msg = Msg.TaIsDeleted.GetWriterForInt(trans, id); Write(msg); int res = ExpectedBufferResponse(Msg.TaIsDeleted).ReadInt(); return(res == 1); }
private void SendReadMultipleObjectsMessage(MReadMultipleObjects message, Transaction transaction, int prefetchDepth, IList idsToRead) { MsgD msg = message.GetWriterForLength(transaction, Const4.IntLength + Const4.IntLength + Const4.IdLength * idsToRead.Count); msg.WriteInt(prefetchDepth); msg.WriteInt(idsToRead.Count); for (IEnumerator idIter = idsToRead.GetEnumerator(); idIter.MoveNext();) { int id = ((int)idIter.Current); msg.WriteInt(id); } Write(msg); }
// do nothing public override bool SetSemaphore(Transaction trans, string name, int timeout) { lock (_lock) { CheckClosed(); trans = CheckTransaction(trans); if (name == null) { throw new ArgumentNullException(); } MsgD msg = Msg.SetSemaphore.GetWriterForIntString(trans, timeout, name); Write(msg); Msg message = GetResponse(); return(message.Equals(Msg.Success)); } }
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 sealed override HardObjectReference GetHardReferenceBySignature(Transaction trans, long uuid, byte[] signature) { int messageLength = Const4.LongLength + Const4.IntLength + signature.Length; MsgD message = Msg.ObjectByUuid.GetWriterForLength(trans, messageLength); message.WriteLong(uuid); message.WriteInt(signature.Length); message.WriteBytes(signature); Write(message); message = (MsgD)ExpectedResponse(Msg.ObjectByUuid); int id = message.ReadInt(); if (id > 0) { return(GetHardObjectReferenceById(trans, id)); } return(HardObjectReference.Invalid); }
/// <exception cref="System.IO.IOException"></exception> internal virtual Socket4Adapter CreateParallelSocket() { Write(Msg.GetThreadId); int serverThreadID = ExpectedBufferResponse(Msg.IdList).ReadInt(); Socket4Adapter sock = _socket.OpenParalellSocket(); LoginToServer(sock); if (switchedToFile != null) { MsgD message = Msg.SwitchToFile.GetWriterForString(SystemTransaction(), switchedToFile ); message.Write(sock); if (!(Msg.Ok.Equals(Msg.ReadMessage(this, SystemTransaction(), sock)))) { throw new IOException(Db4objects.Db4o.Internal.Messages.Get(42)); } } Msg.UseTransaction.GetWriterForInt(_transaction, serverThreadID).Write(sock); return(sock); }
public sealed override int IdForNewUserObject(Transaction trans) { int prefetchIDCount = Config().PrefetchIDCount(); EnsureIDCacheAllocated(prefetchIDCount); ByteArrayBuffer reader = null; if (remainingIDs < 1) { MsgD msg = Msg.PrefetchIds.GetWriterForInt(_transaction, prefetchIDCount); Write(msg); reader = ExpectedBufferResponse(Msg.IdList); for (int i = prefetchIDCount - 1; i >= 0; i--) { _prefetchedIDs[i] = reader.ReadInt(); } remainingIDs = prefetchIDCount; } remainingIDs--; return(_prefetchedIDs[remainingIDs]); }
private void FetchMissingSlotBuffers(Transaction transaction, ArrayList missing, IDictionary buffers, int prefetchDepth) { if (missing.Count == 0) { return; } int safePrefetchDepth = Math.Max(1, prefetchDepth); SendReadMultipleObjectsMessage(Msg.ReadMultipleObjects, transaction, safePrefetchDepth , missing); MsgD response = (MsgD)ExpectedResponse(Msg.ReadMultipleObjects); IEnumerator slots = new CacheContributingObjectReader((ClientTransaction)transaction , _clientSlotCache, response.PayLoad()).Buffers(); while (slots.MoveNext()) { Pair pair = ((Pair)slots.Current); buffers[((int)pair.first)] = ((ByteArrayBuffer)pair.second); } }
private void AssertQueryIterationProtocol(IQuery query, MsgD expectedResultMessage , Stimulus[] stimuli) { var messages = MessageCollector.ForServerDispatcher(ServerDispatcher()); var result = query.Execute(); AssertMessages(messages, new IMessage[] { expectedResultMessage }); messages.Clear(); for (var stimulusIndex = 0; stimulusIndex < stimuli.Length; ++stimulusIndex) { var stimulus = stimuli[stimulusIndex]; stimulus.ActUpon(result); AssertMessages(messages, stimulus.expectedMessagesAfter); messages.Clear(); } if (result.HasNext()) { Assert.Fail("Unexpected item: " + ((Item)result.Next ())); } AssertMessages(messages, new IMessage[] {}); }
private void AssertQueryIterationProtocol(IQuery query, MsgD expectedResultMessage , PrefetchConfigurationTestCase.Stimulus[] stimuli) { IList messages = MessageCollector.ForServerDispatcher(ServerDispatcher()); IObjectSet result = query.Execute(); AssertMessages(messages, new IMessage[] { expectedResultMessage }); messages.Clear(); for (int stimulusIndex = 0; stimulusIndex < stimuli.Length; ++stimulusIndex) { PrefetchConfigurationTestCase.Stimulus stimulus = stimuli[stimulusIndex]; stimulus.ActUpon(result); AssertMessages(messages, stimulus.expectedMessagesAfter); messages.Clear(); } if (result.HasNext()) { Assert.Fail("Unexpected item: " + ((PrefetchConfigurationTestCase.Item)result.Next ())); } AssertMessages(messages, new IMessage[] { }); }
/// <exception cref="Db4objects.Db4o.Ext.InvalidPasswordException"></exception> private void LoginToServer(Socket4Adapter iSocket) { UnicodeStringIO stringWriter = new UnicodeStringIO(); int length = stringWriter.Length(_userName) + stringWriter.Length(_password); MsgD message = Msg.Login.GetWriterForLength(SystemTransaction(), length); message.WriteString(_userName); message.WriteString(_password); message.Write(iSocket); Msg msg = ReadLoginMessage(iSocket); ByteArrayBuffer payLoad = msg.PayLoad(); BlockSize(payLoad.ReadInt()); int doEncrypt = payLoad.ReadInt(); if (doEncrypt == 0) { _handlers.OldEncryptionOff(); } if (payLoad.RemainingByteCount() > 0) { _serverSideID = payLoad.ReadInt(); } }