Ejemplo n.º 1
0
        /// <summary>
        /// Notifies that there is a new channel available
        /// </summary>
        public void OnChannelAvailable(IMessageChannel ch)
        {
            PeerAdvertisementInteractionMessage msg = new PeerAdvertisementInteractionMessage();

            msg.InteractionClassHandle = SerializerManager.GetHandle(typeof(PeerAdvertisementInteractionMessage));
            msg.PeerName        = PeerName;
            msg.PeerDescription = PeerDescription;
            msg.PeerChannels    = new ConnectionList();
            foreach (MessageChannelAcceptor channel in channelManager.ChannelAcceptorsList)
            {
                msg.PeerChannels.Add(channel.Uri);
            }

            IList <IMessageChannel> list = channelManager.ChannelsList(ChannelType.MULTICAST);

            if (list != null)
            {
                foreach (IMessageChannel channel in list)
                {
                    msg.PeerChannels.Add(channel.Uri);
                }
            }

            if (ch is TCPMessageChannel)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("New Channel detected. Sending a PeerAdvertisement message");
                }

                SendRealiableInteraction(ch as StreamMessageChannel, msg);
            }
            else if (ch is MulticastMessageChannel)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("New Channel detected. Sending a PeerAdvertisement message");
                }

                SendBestEffortInteraction(ch as DGramMessageChannel, msg);
            }
        }
        ///<summary> Reads this PeerAdvertisementInteractionMessage from the specified stream.</summary>
        ///<param name="reader"> the input stream to read from</param>
        ///<returns> the object</returns>
        ///<exception cref="System.IO.IOException"> if an error occurs</exception>
        public override object Deserialize(HlaEncodingReader reader, ref object msg)
        {
            PeerAdvertisementInteractionMessage decodedValue;

            if (!(msg is PeerAdvertisementInteractionMessage))
            {
                decodedValue = new PeerAdvertisementInteractionMessage();
                BaseInteractionMessage baseMsg = msg as BaseInteractionMessage;
                decodedValue.InteractionClassHandle    = baseMsg.InteractionClassHandle;
                decodedValue.FederationExecutionHandle = baseMsg.FederationExecutionHandle;
                decodedValue.UserSuppliedTag           = baseMsg.UserSuppliedTag;
            }
            else
            {
                decodedValue = msg as PeerAdvertisementInteractionMessage;
            }
            //object tmp = decodedValue;
            //decodedValue = base.Deserialize(reader, ref tmp) as PeerAdvertisementInteractionMessage;
            try
            {
                decodedValue.PeerName        = reader.ReadHLAunicodeString();
                decodedValue.PeerDescription = reader.ReadHLAunicodeString();
                decodedValue.PeerChannels    = new ConnectionList();
                int PeerChannelsLength = reader.ReadHLAinteger32BE();

                for (int i = 0; i < PeerChannelsLength; i++)
                {
                    decodedValue.PeerChannels.Add(reader.ReadHLAunicodeString());
                }
            }
            catch (System.IO.IOException ioe)
            {
                throw new RTIinternalError(ioe.ToString());
            }
            return(decodedValue);
        }