Esempio n. 1
0
 /// <summary>
 /// Add a new unit.
 /// </summary>
 /// <param name="infoUnit"></param>
 public void AddTransportInfoUnit(TransportInfoUnit infoUnit)
 {
     lock (this)
     {
         _infoUnits.Add(infoUnit);
     }
 }
 public bool EqualsSenderAndReceiver(TransportInfoUnit other)
 {
     return
         _senderID.HasValue == other._senderID.HasValue &&
         _senderID.Value.Equals(other.SenderID.Value) &&
         _receiverID.HasValue == other._receiverID.HasValue &&
         _receiverID.Value.Equals(other._receiverID.Value);
 }
 public bool EqualsSenderAndReceiver(TransportInfoUnit other)
 {
     return
         (_senderID.HasValue == other._senderID.HasValue &&
          _senderID.Value.Equals(other.SenderID.Value) &&
          _receiverID.HasValue == other._receiverID.HasValue &&
          _receiverID.Value.Equals(other._receiverID.Value));
 }
Esempio n. 4
0
        /// <summary>
        /// Central sending function.
        /// </summary>
        /// <param name="receiverID">The ID of the receiver module. Can be <b>null</b> and this sends to all in the Arbiter.</param>
        protected TransportMessage[] DoSendCustom(bool isRequest, Guid sessionGuid,
                                                  Type expectedResponseMessageClassType, int responsesRequired,
                                                  ArbiterClientId?receiverId, ArbiterClientId?senderId, TransportMessage message, TimeSpan timeOut)
        {
            //TracerHelper.TraceEntry();

            SessionResults session = null;

            if (receiverId.HasValue && receiverId.Value.IsEmpty /*receiverId.Value.CompareTo(ArbiterClientId.Empty) == 0*/)
            {
                SystemMonitor.Error("Can not send an item to empty receiver. Use null to specify broadcast.");
                return(null);
            }

            // Preliminary verification.
            if (Arbiter == null)
            {
                SystemMonitor.OperationWarning("Using a client [" + this.GetType().Name + ":" + senderId.Value.ClientName + " to " + (receiverId.HasValue ? receiverId.Value.Id.Name : string.Empty) + " , " + message.GetType().Name + "] with no Arbiter assigned.");
                return(null);
            }

            message.IsRequest = isRequest;

            TransportInfoUnit infoUnit = new TransportInfoUnit(sessionGuid, senderId, receiverId);

            message.TransportInfo.AddTransportInfoUnit(infoUnit);

            bool sessionEventResult = false;

            if (expectedResponseMessageClassType != null)
            {// Responce waiting session.
                session = new SessionResults(responsesRequired, expectedResponseMessageClassType);
                lock (_communicationSessions)
                {// Register the session.
                    _communicationSessions.Add(sessionGuid, session);
                }
            }

            SystemMonitor.CheckError(message.TransportInfo.CurrentTransportInfo != null);
            Conversation conversation;

            if (receiverId == null)
            {
                // We shall not use the next level time out mechanism.
                conversation = Arbiter.CreateConversation(senderId.Value, message, TimeSpan.Zero);
            }
            else
            {// Addressed conversation.
                // We shall not use the next level time out mechanism.
                conversation = Arbiter.CreateConversation(senderId.Value, receiverId.Value, message, TimeSpan.Zero);
            }

            if (conversation != null && expectedResponseMessageClassType != null)
            {     // Responce waiting session (only if conversation was properly created).
                if (timeOut == TimeSpan.Zero)
                { // Wait forever.
                    sessionEventResult = session.SessionEndEvent.WaitOne();
                }
                else
                {// Wait given period.
                    sessionEventResult = session.SessionEndEvent.WaitOne(timeOut, false);
                }

                lock (_communicationSessions)
                {// Remote the session.
                    _communicationSessions.Remove(sessionGuid);
                }
            }

            message.TransportInfo.PopTransportInfo();

            if (expectedResponseMessageClassType == null)
            {// No responce waiting, just return.
                //TracerHelper.TraceExit();
                return(null);
            }

            // Responce waiting session.
            if (sessionEventResult == false)
            {// Timed out - only send and receives can time out, as the other ones do not have sessions!!
                TracerHelper.TraceError("Session has timed out [" + message.GetType().Name + "].");
                return(null);
            }

            //TracerHelper.TraceExit();
            return(session.Responses.ToArray());
        }