/// <summary>
        ///
        /// </summary>
        /// <param name="clientProxy"></param>
        /// <param name="dpea"></param>
        /// <param name="publishHandler"></param>
        public void AddPublish(ClientProxy clientProxy, PublishEventArgs dpea, PublishEventHandler publishHandler)
        {
            if (clientProxy.PublishingThread == null)
            {
                lock (clientProxy)
                {
                    if (clientProxy.PublishingThread == null)
                    {
                        lock (this.publishThreadList)
                        {
                            foreach (PublishThread curPublishThread in this.publishThreadList)
                            {
                                if (curPublishThread.ClientCount == 0)
                                {
                                    clientProxy.PublishingThread = curPublishThread;
                                    break;
                                }
                            }

                            if (clientProxy.PublishingThread == null)
                            {
                                PublishThread publishThread = null;
                                if (this.publishThreadList.Count < MaxThreads)
                                {
                                    publishThread = new PublishThread(this.publishThreadList.Count);
                                    this.publishThreadList.Add(publishThread);
                                }
                                else
                                {
                                    int minClientCount = int.MaxValue;
                                    foreach (PublishThread curPublishThread in this.publishThreadList)
                                    {
                                        if (curPublishThread.ClientCount < minClientCount)
                                        {
                                            publishThread  = curPublishThread;
                                            minClientCount = curPublishThread.ClientCount;
                                        }
                                    }
                                }
                                clientProxy.PublishingThread = publishThread;
                            }
                        }
                    }
                }
            }

            clientProxy.PublishingThread.AddPublish(clientProxy, dpea, publishHandler);
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dpea"></param>
 /// <param name="publishHandler"></param>
 public void AddPendingMessage(PublishEventArgs dpea, PublishEventHandler publishHandler)
 {
     lock (this.pendingMessageList)
         this.pendingMessageList.Add(new KeyValuePair <PublishEventArgs, PublishEventHandler>(dpea, publishHandler));
 }
        private void PublishSendResponseTicketHandlerProc(ClientProxy clientProxy, PublishEventArgs pea)
        {
            PublishSendResponseTicketEventArg psrtea = (PublishSendResponseTicketEventArg)pea;

            clientProxy.CallBack.OnPendingResponseObject(psrtea.Message, psrtea.Payload.PayloadTicket, psrtea.MessageTimeUtc, psrtea.Response);
        }
        private void Publish(Dictionary <Guid, ClientProxy> targetClientProxyMap, bool isMapPrivateCopy, PublishEventArgs dpea, PublishEventHandler publishHandler)
        {
            DateTime           messageTime = DateTime.UtcNow;
            List <ClientProxy> tmpSubscribersList;

            if (isMapPrivateCopy == false)
            {
                lock (targetClientProxyMap)
                    tmpSubscribersList = new List <ClientProxy>(targetClientProxyMap.Values);
            }
            else
            {
                tmpSubscribersList = new List <ClientProxy>(targetClientProxyMap.Values);
            }

            //not going to call the publish in the same order
            //each time so that one subscriber does not get precedence
            //with network and other things between the server and
            //the client this might not matter, but we will do our best
            //to make sure we are fair

            int randomNum = this.GetRandomNumber();

            int startIndex = randomNum % tmpSubscribersList.Count;
            int incrament  = (randomNum % 2 == 0) ? 1 : -1;

            int randomIndex = startIndex;

            for (int subscriberIndex = 0; subscriberIndex < tmpSubscribersList.Count; subscriberIndex++)
            {
                this.publishThreadPool.AddPublish(tmpSubscribersList[randomIndex], dpea, publishHandler);

                randomIndex += incrament;
                if (randomIndex < 0)
                {
                    randomIndex = tmpSubscribersList.Count - 1;
                }
                else if (randomIndex >= tmpSubscribersList.Count)
                {
                    randomIndex = 0;
                }
            }
        }
        private void PublishMessageHandlerProc(ClientProxy clientProxy, PublishEventArgs dpea)
        {
            PublishMessageEventArg dpmea = (PublishMessageEventArg)dpea;

            clientProxy.CallBack.OnServerMessage(dpmea.Message, dpmea.MessageTimeUtc, dpmea.Response);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="clientProxy"></param>
 /// <param name="dpea"></param>
 /// <param name="publishHandler"></param>
 public PublishParameters(ClientProxy clientProxy, PublishEventArgs dpea, PublishEventHandler publishHandler)
 {
     this.ClientProxy     = clientProxy;
     this.PublishEventArg = dpea;
     this.PublishHandler  = publishHandler;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="clientProxy"></param>
 /// <param name="dpea"></param>
 /// <param name="publishHandler"></param>
 public void AddPublish(ClientProxy clientProxy, PublishEventArgs dpea, PublishEventHandler publishHandler)
 {
     this.waitQueue.Enqueue(new PublishParameters(clientProxy, dpea, publishHandler));
 }