상속: BaseCommand, Command, MarshallAware
예제 #1
0
        public void SetUp()
        {
            this.received = new List<Command>();
            this.exceptions = new List<Exception>();

            Uri uri = new Uri("mock://mock?wireformat=openwire");
            MockTransportFactory factory = new MockTransportFactory();

            this.transport = factory.CompositeConnect( uri ) as MockTransport;

            this.localWireFormatInfo = new WireFormatInfo();

            this.localWireFormatInfo.Version = 5;
            this.localWireFormatInfo.MaxInactivityDuration = 3000;
            this.localWireFormatInfo.TightEncodingEnabled = false;
        }
예제 #2
0
        /// <summary>
        /// Handle incoming commands
        /// </summary>
        /// <param name="commandTransport">An ITransport</param>
        /// <param name="command">A  Command</param>
        protected void OnCommand(ITransport commandTransport, Command command)
        {
            if(command.IsMessageDispatch)
            {
                WaitForTransportInterruptionProcessingToComplete();
                DispatchMessage((MessageDispatch) command);
            }
            else if(command.IsKeepAliveInfo)
            {
                OnKeepAliveCommand(commandTransport, (KeepAliveInfo) command);
            }
            else if(command.IsWireFormatInfo)
            {
                this.brokerWireFormatInfo = (WireFormatInfo) command;
            }
            else if(command.IsBrokerInfo)
            {
                this.brokerInfo = (BrokerInfo) command;
                this.brokerInfoReceived.countDown();
            }
            else if(command.IsShutdownInfo)
            {
                if(!closing.Value && !closed.Value)
                {
                    OnException(new NMSException("Broker closed this connection."));
                }
            }
            else if(command.IsProducerAck)
            {
                ProducerAck ack = (ProducerAck) command as ProducerAck;
                if(ack.ProducerId != null)
                {
                    MessageProducer producer = producers[ack.ProducerId] as MessageProducer;
                    if(producer != null)
                    {
                        if(Tracer.IsDebugEnabled)
                        {
                            Tracer.Debug("Connection: Received a new ProducerAck -> " + ack);
                        }

                        producer.OnProducerAck(ack);
                    }
                }
            }
            else if(command.IsConnectionError)
            {
                if(!closing.Value && !closed.Value)
                {
                    ConnectionError connectionError = (ConnectionError) command;
                    BrokerError brokerError = connectionError.Exception;
                    string message = "Broker connection error.";
                    string cause = "";

                    if(null != brokerError)
                    {
                        message = brokerError.Message;
                        if(null != brokerError.Cause)
                        {
                            cause = brokerError.Cause.Message;
                        }
                    }

                    OnException(new NMSConnectionException(message, cause));
                }
            }
            else
            {
                Tracer.Error("Unknown command: " + command);
            }
        }
예제 #3
0
		public override void Oneway(Command command)
		{
			// Disable inactivity monitoring while processing a command.
			// synchronize this method - its not synchronized
			// further down the transport stack and gets called by more
			// than one thread  by this class
			lock(inWrite)
			{
				inWrite.Value = true;
				try
				{
					if(failed.Value)
					{
						throw new IOException("Channel was inactive for too long: " + next.RemoteAddress.ToString());
					}
					if(command.IsWireFormatInfo)
					{
						lock(monitor)
						{
							localWireFormatInfo = command as WireFormatInfo;
							StartMonitorThreads();
						}
					}
					next.Oneway(command);
				}
				finally
				{
					commandSent.Value = true;
					inWrite.Value = false;
				}
			}
		}
예제 #4
0
		protected override void OnCommand(ITransport sender, Command command)
		{
			commandReceived.Value = true;
			inRead.Value = true;
			try
			{
				if(command.IsKeepAliveInfo)
				{
					KeepAliveInfo info = command as KeepAliveInfo;
					if(info.ResponseRequired)
					{
						try
						{
							info.ResponseRequired = false;
							Oneway(info);
						}
						catch(IOException ex)
						{
							OnException(this, ex);
						}
					}
				}
				else if(command.IsWireFormatInfo)
				{
					lock(monitor)
					{
						remoteWireFormatInfo = command as WireFormatInfo;
						try
						{
							StartMonitorThreads();
						}
						catch(IOException ex)
						{
							OnException(this, ex);
						}
					}
				}
				base.OnCommand(sender, command);
			}
			finally
			{
				inRead.Value = false;
			}
		}
예제 #5
0
		protected override void Dispose(bool disposing)
		{
			if(disposing)
			{
				// get rid of unmanaged stuff
			}

			lock(monitor)
			{
				this.localWireFormatInfo = null;
				this.remoteWireFormatInfo = null;
				this.disposing = true;
				StopMonitorThreads();
			}

			base.Dispose(disposing);
		}
예제 #6
0
 public virtual Response processWireFormat(WireFormatInfo info)
 {
     return null;
 }
예제 #7
0
        public void RenegotiateWireFormat(WireFormatInfo info)
        {
            if(info.Version < minimumVersion)
            {
                throw new IOException("Remote wire format (" + info.Version + ") is lower than the minimum version required (" + minimumVersion + ")");
            }

            this.Version = Math.Min(PreferredWireFormatInfo.Version, info.Version);
            this.cacheEnabled = info.CacheEnabled && PreferredWireFormatInfo.CacheEnabled;
            this.stackTraceEnabled = info.StackTraceEnabled && PreferredWireFormatInfo.StackTraceEnabled;
            this.tcpNoDelayEnabled = info.TcpNoDelayEnabled && PreferredWireFormatInfo.TcpNoDelayEnabled;
            this.sizePrefixDisabled = info.SizePrefixDisabled && PreferredWireFormatInfo.SizePrefixDisabled;
            this.tightEncodingEnabled = info.TightEncodingEnabled && PreferredWireFormatInfo.TightEncodingEnabled;
            this.maxInactivityDuration = info.MaxInactivityDuration;
            this.maxInactivityDurationInitialDelay = info.MaxInactivityDurationInitialDelay;
            this.cacheSize = info.CacheSize;

            TcpTransport tcpTransport = this.transport as TcpTransport;
            if(null != tcpTransport)
            {
                tcpTransport.TcpNoDelayEnabled = this.tcpNoDelayEnabled;
            }
        }
예제 #8
0
        /// <summary>
        /// Handle incoming commands
        /// </summary>
        /// <param name="commandTransport">An ITransport</param>
        /// <param name="command">A  Command</param>
        protected void OnCommand(ITransport commandTransport, Command command)
        {
            if(command.IsMessageDispatch)
            {
                WaitForTransportInterruptionProcessingToComplete();
                DispatchMessage((MessageDispatch)command);
            }
            else if(command.IsKeepAliveInfo)
            {
                OnKeepAliveCommand(commandTransport, (KeepAliveInfo)command);
            }
            else if(command.IsWireFormatInfo)
            {
                this.brokerWireFormatInfo = (WireFormatInfo)command;
            }
            else if(command.IsBrokerInfo)
            {
                this.brokerInfo = (BrokerInfo)command;
                this.brokerInfoReceived.countDown();
            }
            else if(command.IsShutdownInfo)
            {
                // Only terminate the connection if the transport we use is not fault
                // tolerant otherwise we let the transport deal with the broker closing
                // our connection and deal with IOException if it is sent to use.
                if(!closing.Value && !closed.Value && this.transport != null && !this.transport.IsFaultTolerant)
                {
                    OnException(new NMSException("Broker closed this connection via Shutdown command."));
                }
            }
            else if(command.IsProducerAck)
            {
                ProducerAck ack = (ProducerAck)command as ProducerAck;
                if(ack.ProducerId != null)
                {
                    MessageProducer producer = producers[ack.ProducerId] as MessageProducer;
                    if(producer != null)
                    {
                        if(Tracer.IsDebugEnabled)
                        {
                            Tracer.DebugFormat("Connection[{0}]: Received a new ProducerAck -> ",
                                               this.ConnectionId, ack);
                        }

                        producer.OnProducerAck(ack);
                    }
                }
            }
            else if(command.IsConnectionError)
            {
                if(!closing.Value && !closed.Value)
                {
                    ConnectionError connectionError = (ConnectionError)command;
                    BrokerError brokerError = connectionError.Exception;
                    string message = "Broker connection error.";
                    string cause = "";

                    if(null != brokerError)
                    {
                        message = brokerError.Message;
                        if(null != brokerError.Cause)
                        {
                            cause = brokerError.Cause.Message;
                        }
                    }

                    Tracer.ErrorFormat("Connection[{0}]: ConnectionError: " + message + " : " + cause, this.ConnectionId);
                    OnAsyncException(new NMSConnectionException(message, cause));
                }
            }
            else
            {
                Tracer.ErrorFormat("Connection[{0}]: Unknown command: " + command, this.ConnectionId);
            }
        }