Esempio n. 1
0
        protected override void OnCommand(ITransport sender, ICommand command)
        {
            _commandReceived.Value = true;
            _inRead.Value          = true;
            try
            {
                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;
            }
        }
Esempio n. 2
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;
         }
     }
 }
Esempio n. 3
0
        public void renegotiateWireFormat(WireFormatInfo info)
        {
            lock (this.marshalLock)
            {
                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;
                }
            }
        }
Esempio n. 4
0
 protected override void OnCommand(ITransport sender, Command command)
 {
     if (command.IsWireFormatInfo)
     {
         WireFormatInfo info = (WireFormatInfo)command;
         try
         {
             if (!info.Valid)
             {
                 throw new IOException("Remote wire format magic is invalid");
             }
             wireInfoSentDownLatch.await(negotiateTimeout);
             wireFormat.RenegotiateWireFormat(info);
         }
         catch (Exception e)
         {
             OnException(this, e);
         }
         finally
         {
             readyCountDownLatch.countDown();
         }
     }
     this.commandHandler(sender, command);
 }
Esempio n. 5
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 is MessageDispatch)
     {
         DispatchMessage((MessageDispatch)command);
     }
     else if (command is WireFormatInfo)
     {
         this.brokerWireFormatInfo = (WireFormatInfo)command;
     }
     else if (command is BrokerInfo)
     {
         this.brokerInfo = (BrokerInfo)command;
     }
     else if (command is ShutdownInfo)
     {
         //ShutdownInfo info = (ShutdownInfo)command;
         if (!closing && !closed)
         {
             OnException(commandTransport, new NMSException("Broker closed this connection."));
         }
     }
     else
     {
         Tracer.Error("Unknown command: " + command);
     }
 }
Esempio n. 6
0
 /// <summary>
 ///     Method invoked when the instance gets disposed.
 /// </summary>
 protected override void Disposed()
 {
     lock ( _monitor )
     {
         _localWireFormatInfo  = null;
         _remoteWireFormatInfo = null;
         _disposing            = true;
         StopMonitorThreads();
     }
 }
Esempio n. 7
0
        protected virtual ICommand ReadConnected(StompFrame frame)
        {
            _remoteWireFormatInfo = new WireFormatInfo();

            if (frame.HasProperty("version"))
            {
                _remoteWireFormatInfo.Version = Single.Parse(frame.RemoveProperty("version"),
                                                             CultureInfo.InvariantCulture);
                if (_remoteWireFormatInfo.Version > 1.0f)
                {
                    _encodeHeaders = true;
                }

                if (frame.HasProperty("session"))
                {
                    _remoteWireFormatInfo.Session = frame.RemoveProperty("session");
                }

                if (frame.HasProperty("heart-beat"))
                {
                    var hearBeats = frame.RemoveProperty("heart-beat")
                                    .Split(",".ToCharArray());
                    if (hearBeats.Length != 2)
                    {
                        throw new IoException("Malformed heartbeat property in Connected Frame.");
                    }

                    _remoteWireFormatInfo.WriteCheckInterval = Int32.Parse(hearBeats[0]
                                                                           .Trim());
                    _remoteWireFormatInfo.ReadCheckInterval = Int32.Parse(hearBeats[1]
                                                                          .Trim());
                }
            }
            else
            {
                _remoteWireFormatInfo.ReadCheckInterval  = 0;
                _remoteWireFormatInfo.WriteCheckInterval = 0;
                _remoteWireFormatInfo.Version            = 1.0f;
            }

            if (_connectedResponseId != -1)
            {
                var answer = new Response {
                    CorrelationId = _connectedResponseId
                };
                SendCommand(answer);
                _connectedResponseId = -1;
            }
            else
            {
                throw new IoException("Received Connected Frame without a set Response Id for it.");
            }

            return(_remoteWireFormatInfo);
        }
Esempio n. 8
0
        //
        // Write the booleans that this object uses to a BooleanStream
        //
        public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs)
        {
            WireFormatInfo info = (WireFormatInfo)o;

            info.BeforeMarshall(wireFormat);

            int rc = base.TightMarshal1(wireFormat, o, bs);

            bs.WriteBoolean(info.MarshalledProperties != null);
            rc += info.MarshalledProperties == null ? 0 : info.MarshalledProperties.Length + 4;

            return(rc + 12);
        }
Esempio n. 9
0
        protected virtual Command ReadConnected(StompFrame frame)
        {
            this.remoteWireFormatInfo = new WireFormatInfo();

            if (frame.HasProperty("version"))
            {
                remoteWireFormatInfo.Version = Single.Parse(frame.RemoveProperty("version"));

                if (remoteWireFormatInfo.Version > 1.0f)
                {
                    this.encodeHeaders = true;
                }

                if (frame.HasProperty("session"))
                {
                    remoteWireFormatInfo.Session = frame.RemoveProperty("session");
                }

                if (frame.HasProperty("heart-beat"))
                {
                    string[] hearBeats = frame.RemoveProperty("heart-beat").Split(",".ToCharArray());
                    if (hearBeats.Length != 2)
                    {
                        throw new IOException("Malformed heartbeat property in Connected Frame.");
                    }

                    remoteWireFormatInfo.WriteCheckInterval = Int32.Parse(hearBeats[0].Trim());
                    remoteWireFormatInfo.ReadCheckInterval  = Int32.Parse(hearBeats[1].Trim());
                }
            }
            else
            {
                remoteWireFormatInfo.ReadCheckInterval  = 0;
                remoteWireFormatInfo.WriteCheckInterval = 0;
                remoteWireFormatInfo.Version            = 1.0f;
            }

            if (this.connectedResponseId != -1)
            {
                Response answer = new Response();
                answer.CorrelationId = this.connectedResponseId;
                SendCommand(answer);
                this.connectedResponseId = -1;
            }
            else
            {
                throw new IOException("Received Connected Frame without a set Response Id for it.");
            }

            return(remoteWireFormatInfo);
        }
Esempio n. 10
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 is MessageDispatch)
            {
                DispatchMessage((MessageDispatch)command);
            }
            else if (command is KeepAliveInfo)
            {
                OnKeepAliveCommand(commandTransport, (KeepAliveInfo)command);
            }
            else if (command is WireFormatInfo)
            {
                this.brokerWireFormatInfo = (WireFormatInfo)command;
            }
            else if (command is BrokerInfo)
            {
                this.brokerInfo = (BrokerInfo)command;
            }
            else if (command is ShutdownInfo)
            {
                if (!closing && !closed)
                {
                    OnException(commandTransport, new NMSException("Broker closed this connection."));
                }
            }
            else if (command is ConnectionError)
            {
                if (!closing && !closed)
                {
                    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(commandTransport, new NMSConnectionException(message, cause));
                }
            }
            else
            {
                Tracer.Error("Unknown command: " + command);
            }
        }
Esempio n. 11
0
        public void renegotiateWireFormat(WireFormatInfo info)
        {
            if (info.Version < minimumVersion)
            {
                throw new IOException("Remote wire format (" + info.Version + ") is lower the minimum version required (" + minimumVersion + ")");
            }

            this.Version           = Math.Min(PreferedWireFormatInfo.Version, info.Version);
            this.stackTraceEnabled = info.StackTraceEnabled && PreferedWireFormatInfo.StackTraceEnabled;
//            this.tcpNoDelayEnabled = info.TcpNoDelayEnabled && PreferedWireFormatInfo.TcpNoDelayEnabled;
//            this.cacheEnabled = info.CacheEnabled && PreferedWireFormatInfo.CacheEnabled;
            this.tightEncodingEnabled = info.TightEncodingEnabled && PreferedWireFormatInfo.TightEncodingEnabled;
            this.sizePrefixDisabled   = info.SizePrefixDisabled && PreferedWireFormatInfo.SizePrefixDisabled;
        }
Esempio n. 12
0
        //
        // Un-marshal an object instance from the data input stream
        //
        public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs)
        {
            base.TightUnmarshal(wireFormat, o, dataIn, bs);

            WireFormatInfo info = (WireFormatInfo)o;

            info.BeforeUnmarshall(wireFormat);

            info.Magic   = ReadBytes(dataIn, 8);
            info.Version = dataIn.ReadInt32();
            info.MarshalledProperties = ReadBytes(dataIn, bs.ReadBoolean());

            info.AfterUnmarshall(wireFormat);
        }
        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;
        }
Esempio n. 14
0
        //
        // Write a object instance to data output stream
        //
        public override void TightMarshal2(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut, BooleanStream bs)
        {
            base.TightMarshal2(wireFormat, o, dataOut, bs);

            WireFormatInfo info = (WireFormatInfo)o;

            dataOut.Write(info.Magic, 0, 8);
            dataOut.Write(info.Version);
            if (bs.ReadBoolean())
            {
                dataOut.Write(info.MarshalledProperties.Length);
                dataOut.Write(info.MarshalledProperties);
            }

            info.AfterMarshall(wireFormat);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        //
        // Write a object instance to data output stream
        //
        public override void LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut)
        {
            WireFormatInfo info = (WireFormatInfo)o;

            info.BeforeMarshall(wireFormat);

            base.LooseMarshal(wireFormat, o, dataOut);
            dataOut.Write(info.Magic, 0, 8);
            dataOut.Write(info.Version);
            dataOut.Write(info.MarshalledProperties != null);
            if (info.MarshalledProperties != null)
            {
                dataOut.Write(info.MarshalledProperties.Length);
                dataOut.Write(info.MarshalledProperties);
            }

            info.AfterMarshall(wireFormat);
        }
Esempio n. 17
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;
     }
 }
Esempio n. 18
0
 /// <summary>
 /// Handle incoming commands
 /// </summary>
 /// <param name="transport">An ITransport</param>
 /// <param name="command">A  Command</param>
 protected void OnCommand(ITransport transport, Command command)
 {
     if (command is MessageDispatch)
     {
         MessageDispatch dispatch   = (MessageDispatch)command;
         ConsumerId      consumerId = dispatch.ConsumerId;
         MessageConsumer consumer   = (MessageConsumer)consumers[consumerId];
         if (consumer == null)
         {
             Tracer.Error("No such consumer active: " + consumerId);
         }
         else
         {
             ActiveMQMessage message = (ActiveMQMessage)dispatch.Message;
             consumer.Dispatch(message);
         }
     }
     else if (command is WireFormatInfo)
     {
         this.brokerWireFormatInfo = (WireFormatInfo)command;
     }
     else if (command is BrokerInfo)
     {
         this.brokerInfo = (BrokerInfo)command;
     }
     else if (command is ShutdownInfo)
     {
         //ShutdownInfo info = (ShutdownInfo)command;
         if (!closing && !closed)
         {
             OnException(transport, new NMSException("Broker closed this connection."));
         }
     }
     else
     {
         Tracer.Error("Unknown command: " + command);
     }
 }
Esempio n. 19
0
        protected override void OnCommand(ITransport sender, Command command)
        {
            commandReceived.Value = true;
            inRead.Value          = true;
            try
            {
                if (command.IsWireFormatInfo)
                {
                    lock (monitor)
                    {
                        remoteWireFormatInfo = command as WireFormatInfo;
                        try
                        {
                            StartMonitorThreads();
                        }
                        catch (IOException ex)
                        {
                            OnException(this, ex);
                        }
                    }
                }
                else if (command.IsKeepAliveInfo)
                {
                    if (Tracer.IsDebugEnabled)
                    {
                        Tracer.DebugFormat("InactivityMonitor[{0}]: New Keep Alive Received at -> " +
                                           DateTime.Now.ToLongTimeString().TrimEnd(" APM".ToCharArray()) +
                                           "." + DateTime.Now.Millisecond, instanceId);
                    }
                }

                base.OnCommand(sender, command);
            }
            finally
            {
                inRead.Value = false;
            }
        }
Esempio n. 20
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(PreferedWireFormatInfo.Version, info.Version);
            this.stackTraceEnabled    = info.StackTraceEnabled && PreferedWireFormatInfo.StackTraceEnabled;
            this.tcpNoDelayEnabled    = info.TcpNoDelayEnabled && PreferedWireFormatInfo.TcpNoDelayEnabled;
            this.tightEncodingEnabled = info.TightEncodingEnabled && PreferedWireFormatInfo.TightEncodingEnabled;
            this.sizePrefixDisabled   = info.SizePrefixDisabled && PreferedWireFormatInfo.SizePrefixDisabled;

            TcpTransport tcpTransport = this.transport as TcpTransport;

            if (null != tcpTransport)
            {
                tcpTransport.TcpNoDelayEnabled = this.tcpNoDelayEnabled;
            }

            // The following options is not used client-side.
            // this.cacheEnabled = info.CacheEnabled && PreferedWireFormatInfo.CacheEnabled;
        }
Esempio n. 21
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);
            }
        }
 public virtual Response processWireFormat(WireFormatInfo info)
 {
     return(null);
 }
Esempio n. 23
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);
            }
        }