示例#1
0
 /// <param name="socket"></param>
 internal virtual Db4objects.Db4o.CS.Internal.Messages.Msg ReadPayLoad(IMessageDispatcher
                                                                       messageDispatcher, Db4objects.Db4o.Internal.Transaction a_trans, Socket4Adapter
                                                                       socket, ByteArrayBuffer reader)
 {
     Db4objects.Db4o.CS.Internal.Messages.Msg msg = PublicClone();
     msg.SetMessageDispatcher(messageDispatcher);
     msg.SetTransaction(CheckParentTransaction(a_trans, reader));
     return(msg);
 }
示例#2
0
        /// <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 void OnMessage(Msg msg)
			{
				if (msg is MQueryExecute)
				{
					this._enclosing.processingMessage = true;
					barrier.Add(new object());
					Runtime4.Sleep(500);
					this._enclosing.processingMessage = false;
				}
				else
				{
					if (msg is MIsAlive)
					{
						Assert.IsFalse(this._enclosing.processingMessage);
					}
				}
			}
示例#4
0
		public void AddToBatch(Msg msg)
		{
			lock (Lock())
			{
				_batchedMessages.Add(msg);
				// the first INT_LENGTH is for buffer.length, and then buffer content.
				_batchedQueueLength += Const4.IntLength + msg.PayLoad().Length();
			}
		}
示例#5
0
		public virtual bool WriteMessageToSocket(Msg msg)
		{
			if (_messageListener != null)
			{
				_messageListener.OnMessage(msg);
			}
			return msg.Write(_socket);
		}
示例#6
0
		public void WriteMsg(Msg msg, bool flush)
		{
			if (_config.BatchMessages())
			{
				if (flush && _batchedMessages.IsEmpty())
				{
					// if there's nothing batched, just send this message directly
					WriteMessageToSocket(msg);
				}
				else
				{
					AddToBatch(msg);
					if (flush || _batchedQueueLength > _config.MaxBatchQueueSize())
					{
						WriteBatchedMessages();
					}
				}
			}
			else
			{
				if (!_batchedMessages.IsEmpty())
				{
					AddToBatch(msg);
					WriteBatchedMessages();
				}
				else
				{
					WriteMessageToSocket(msg);
				}
			}
		}
示例#7
0
		public void WriteBatchedMessage(Msg msg)
		{
			WriteMsg(msg, false);
		}
 public virtual bool Write(Msg msg)
 {
     _container.Write(msg);
     return true;
 }
示例#9
0
			// null denotes password not necessary
			// initial value of _batchedQueueLength is
			// used for to write the number of messages.
			public void OnMessage(Msg msg)
			{
			}
示例#10
0
		private void CheckExceptionMessage(Msg msg)
		{
			if (msg is MRuntimeException)
			{
				((MRuntimeException)msg).ThrowPayload();
			}
		}
示例#11
0
 public virtual void Write(Db4objects.Db4o.CS.Internal.Messages.Msg msg)
 {
     _messageDispatcher.Write(msg);
 }
		public bool Write(Msg msg)
		{
			lock (_lock)
			{
				if (!IsMessageDispatcherAlive())
				{
					return false;
				}
				return msg.Write(_socket);
			}
		}
		private void WriteException(Msg message, Exception exc)
		{
			if (!(message is IMessageWithResponse))
			{
				Sharpen.Runtime.PrintStackTrace(exc);
				return;
			}
			if (!(exc is Exception))
			{
				exc = new Db4oException(exc);
			}
			// Writing exceptions can produce ClassMetadata in
			// the main ObjectContainer.
			lock (_mainLock)
			{
				message.WriteException((Exception)exc);
			}
		}
		public bool ProcessMessage(Msg message)
		{
			if (IsMessageDispatcherAlive())
			{
				if (message is IMessageWithResponse)
				{
					IMessageWithResponse msgWithResp = (IMessageWithResponse)message;
					try
					{
						Msg reply = msgWithResp.ReplyFromServer();
						Write(reply);
					}
					catch (Db4oRecoverableException exc)
					{
						WriteException(message, exc);
						return true;
					}
					catch (Exception t)
					{
						Sharpen.Runtime.PrintStackTrace(t);
						FatalShutDownServer(t);
						return false;
					}
					try
					{
						msgWithResp.PostProcessAtServer();
						return true;
					}
					catch (Exception exc)
					{
						Sharpen.Runtime.PrintStackTrace(exc);
					}
					return true;
				}
				try
				{
					((IServerSideMessage)message).ProcessAtServer();
					return true;
				}
				catch (Db4oRecoverableException exc)
				{
					Sharpen.Runtime.PrintStackTrace(exc);
					return true;
				}
				catch (Exception t)
				{
					Sharpen.Runtime.PrintStackTrace(t);
					FatalShutDownServer(t);
				}
			}
			return false;
		}
示例#15
0
		internal ByteArrayBuffer ExpectedBufferResponse(Msg expectedMessage)
		{
			Msg msg = ExpectedResponse(expectedMessage);
			if (msg == null)
			{
				// TODO: throw Exception to allow
				// smooth shutdown
				return null;
			}
			return msg.GetByteLoad();
		}
示例#16
0
		public Msg ExpectedResponse(Msg expectedMessage)
		{
			Msg message = GetResponse();
			if (expectedMessage.Equals(message))
			{
				return message;
			}
			CheckExceptionMessage(message);
			throw new InvalidOperationException("Unexpected Message:" + message + "  Expected:"
				 + expectedMessage);
		}
示例#17
0
		public virtual void BroadcastMsg(Msg message, IBroadcastFilter filter)
		{
			IEnumerator i = IterateDispatchers();
			while (i.MoveNext())
			{
				IServerMessageDispatcher dispatcher = (IServerMessageDispatcher)i.Current;
				if (filter.Accept(dispatcher))
				{
					dispatcher.Write(message);
				}
			}
		}
示例#18
0
		private bool IsClientSideMessage(Msg message)
		{
			return message is IClientSideMessage;
		}
示例#19
0
			public void OnMessage(Msg msg)
			{
				messages.Add(msg);
			}
示例#20
0
		// do nothing
		public bool Write(Msg msg)
		{
			WriteMsg(msg, true);
			return true;
		}
示例#21
0
文件: Msg.cs 项目: masroore/db4o
 public virtual void Write(Msg msg)
 {
     _messageDispatcher.Write(msg);
 }