Пример #1
0
        /// <summary>
        /// Creates a BrokerClient instance and connects to an agent.
        /// </summary>
        /// <param name="hostInfo">Information about an agent.</param>
        public BrokerClient(HostInfo hostInfo)
        {
            IList<HostInfo> hosts = new List<HostInfo>(1);
            hosts.Add(hostInfo);

            this.hosts = hosts;
            NetworkHandler networkHandler = new NetworkHandler(hosts);
            protocolHandler = new BrokerProtocolHandler(messageSerializer, networkHandler);
            protocolHandler.OnCommunicationFailed += new CommunicationFailed(HandleOnCommunicationFailed);
        }
        public BrokerProtocolHandler(IMessageSerializer messageSerializer, NetworkHandler networkHandler)
        {
            this.messageSerializer = messageSerializer;
            this.networkHandler = networkHandler;

            subscriptions.Add(NetAction.DestinationType.TOPIC, new Dictionary<string, Subscription>());
            subscriptions.Add(NetAction.DestinationType.QUEUE, new Dictionary<string, Subscription>());

            networkHandler.MessageReceived += delegate(byte[] encodedData) {
                try{
                    NetMessage netMessage = DecodeMessage(encodedData);

                    HandleIncommingMessage(netMessage);
                }catch(Exception ex){
                    DealWithException(ex);
                }
            };

            networkHandler.IoFailed += new NetworkHandler.IoFailureHandler(IoFailHandler);

            networkHandler.Start();
        }
        private void IoFailHandler(NetworkHandler.IoSyncStatus syncStatus)
        {
            sendSuspended = true;
            sendOk = false;

            syncStatus.OnChange.OnEvent += delegate(NetworkHandler.IoStatus status)
            {
                if (status == NetworkHandler.IoStatus.Ok)
                {
                    log.Info("Connection re-established");

                    lock (sendLock)
                    {
                        this.sendSuspended = false;
                        Monitor.PulseAll(sendLock);
                    }

                    if (usingAuth)
                    {
                        lock (this)
                        {
                            Authenticate(this.provider);
                        }
                    }

                    SendSubscriptions();
                }
                else
                {
                    log.Error("Communication Failed");

                    if( OnCommunicationFailed != null)
                        OnCommunicationFailed();
                }
            };
        }
Пример #4
0
 /// <summary>
 /// Creates a BrokerClient instance and connects to an agent.
 /// </summary>
 /// <param name="hosts">Information about agents.</param>
 public BrokerClient(IList<HostInfo> hosts)
 {
     this.hosts = hosts;
     NetworkHandler networkHandler = new NetworkHandler(hosts);
     protocolHandler = new BrokerProtocolHandler(messageSerializer, networkHandler);
 }