public override void Execute(RemoteEntity entity)
        {
            Publisher pEntity = (Publisher)entity;
            PublisherFaultManager fManager = pEntity.FManager;
            TimeoutMonitor tMonitor = fManager.TMonitor;
            IRemoteBroker broker = fManager.ChooseBroker(this.targetSite, this.e.Publisher);
            string brokerName = pEntity.RemoteNetwork.GetBrokerName(broker);
            int timeoutID = tMonitor.NewActionPerformed(e, outSeqNumber, targetSite, brokerName);

            try { broker.DifundPublishEvent(e, entity.RemoteNetwork.SiteName, entity.Name, outSeqNumber, timeoutID); } catch (Exception) { /*ignore*/ }
        }
        public BrokerFaultManager(RemoteEntity re)
            : base(re, QUEUE_SIZE, NUM_THREADS)
        {
            actionID = 1;
            this.actionIDObject = new Object();
            this.waitingEvents = new Dictionary<int, EventInfo>();
            this.timeoutIDMap = new Dictionary<int, int>();
            this.PassiveDead = false;

            Thread t = new Thread(SendHearthBeats); //send hearth beats
            t.Start();
        }
        public override void Execute(RemoteEntity entity)
        {
            Broker broker = (Broker) entity;

            if (!broker.ForwardingTable.TryAddEntity(this.topic, this.source))
                return; //already processed

            ;

            //if the rout policy is flooding we do not need to send the sub event to other brokers
            if (entity.SysConfig.RoutingPolicy.Equals(SysConfig.FILTER))
                ProcessFilteredDelivery(broker);
        }
        public FaultManager(RemoteEntity re, int queueSize, int numThreads)
        {
            this.TMonitor = new TimeoutMonitor(this);
            this.RemoteEntity = re;
            this.missedACKs = new Dictionary<string, Dictionary<string, Pair<DateTime, int>>>();
            this.Events = new EventQueue(queueSize);

            for (int i = 0; i < numThreads; i++)
            {
                Thread t = new Thread(ProcessQueue);
                t.Start();
            }
        }
        public override void Execute(RemoteEntity entity)
        {
            Publisher pEntity = (Publisher)entity;
            PublisherFaultManager fManager = pEntity.FManager;

            foreach (IRemoteBroker broker in pEntity.RemoteNetwork.InBrokersList)
            {
                string brokerName = pEntity.RemoteNetwork.GetBrokerName(broker);

                if (!fManager.IsDead(pEntity.RemoteNetwork.SiteName, brokerName))
                {
                    try { broker.NewEventPublished(topic, publisher, eventNr); } catch (Exception) { /*ignore*/ }
                }
            }
        }
        public override void Execute(RemoteEntity entity)
        {
            foreach (KeyValuePair<string, IRemoteBroker> entry in entity.RemoteNetwork.InBrokers)
            {
                try
                {
                    try { entry.Value.DifundSubscribeEvent(topic, entity.Name); }
                    catch (Exception) { /*ignore*/}
                }
                catch(Exception)
                {
                    //ignore
                }

            }

            Console.WriteLine("[SUBSCRIBED] " + topic);
        }
 public abstract void Execute(RemoteEntity entity);
        public override void Execute(RemoteEntity entity)
        {
            Broker broker = (Broker)entity;

            if(broker.SysConfig.ParentSite.Equals(SysConfig.NO_PARENT))
            {
                if (broker.IsSequencer || broker.IsPassiveSequencer) //current broker is the sequencer
                {
                    Event seqEvent = new Event(publisher, this.topic, new DateTime().Ticks, this.eventNr);
                    seqEvent.IsSequencerMessage = true;
                    string sourceEntity = broker.IsSequencer ? Sequencer.SEQUENCER_BASE_NAME : Sequencer.SEQUENCER_PASSIVE_NAME;

                    broker.PEventManager.ExecuteDistribution(broker.RemoteNetwork.SiteName, sourceEntity, seqEvent, broker.Sequencer.GetNextSeqNumber());

                }
            }
            else
            {
                List<IRemoteBroker> parentBrokers = broker.RemoteNetwork.OutBrokers[broker.SysConfig.ParentSite];

                foreach (IRemoteBroker parentBroker in parentBrokers)
                {
                    string brokerName = broker.RemoteNetwork.GetBrokerName(parentBroker);

                    if (!broker.FManager.IsDead(broker.SysConfig.ParentSite, brokerName))
                    {
                        try
                        {
                            parentBroker.NewEventPublished(this.topic, this.publisher, this.eventNr);
                        }
                        catch(Exception) { broker.FManager.MarkAsDead(broker.SysConfig.ParentSite, brokerName); }
                    }
                }

                broker.Sequencer.DispatchedNewEventMessage(publisher, eventNr, topic);
            }
        }
 public override void Execute(RemoteEntity entity)
 {
     Broker b = (Broker) entity;
     b.PEventManager.ExecuteDistribution(this.sourceSite, this.sourceEntity, this.e, this.inSeqNumber);
 }
        public override void Execute(RemoteEntity entity)
        {
            Broker broker = (Broker) entity;
            IRemoteEntity source;

            if (!broker.FManager.PassiveDead)
            {
                try
                {
                    passiveServer.StoreNewEvent(e, sourceSite, sourceEntity, inSeqNumber);
                } catch (Exception) { broker.FManager.PassiveDead = true; }
            }

            /*
             *  SEND ACK
             */
            if (sourceSite.Equals(entity.RemoteNetwork.SiteName))
                source = entity.RemoteNetwork.Publishers[sourceEntity];
            else
                source = entity.RemoteNetwork.OutBrokersNames[sourceEntity];

            try
            {
                source.ReceiveACK(timeoutID, entity.Name, entity.RemoteNetwork.SiteName);
            } catch (Exception) {}
        }
        public override void Execute(RemoteEntity entity)
        {
            Broker bEntity = (Broker)entity;
            BrokerFaultManager fManager = bEntity.FManager;
            TimeoutMonitor tMonitor = fManager.TMonitor;
            IRemoteBroker broker = fManager.ChooseBroker(this.targetSite, this.e.Publisher);
            string brokerName = bEntity.RemoteNetwork.GetBrokerName(broker);

            tMonitor.NewActionPerformed(e, outSeqNumber, targetSite, brokerName, oldTimeoutID);

            try { broker.DifundPublishEvent(e, entity.RemoteNetwork.SiteName, entity.Name, outSeqNumber, oldTimeoutID); }
            catch (Exception) { /*ignore*/ }

            Console.WriteLine(String.Format("[FORWARD EVENT RETRANSMISSION] Topic: {0} Publisher: {1} EventNr: {2} To: {3}", e.Topic, e.Publisher, e.EventNr, entity.RemoteNetwork.GetBrokerName(broker)));
        }
        public override void Execute(RemoteEntity entity)
        {
            Broker broker = (Broker) entity;

            if (!broker.FManager.PassiveDead)
            {
                try
                {
                    this.passiveServer.EventDispatched(eventNumber, publisher);
                } catch (Exception) { broker.FManager.PassiveDead = true; }
            }
        }
        public override void Execute(RemoteEntity entity)
        {
            Publisher publisher = (Publisher)entity;

            for (int i = 0; i < this.nrEvents; i++)
            {
                publisher.CheckFreeze();
                publisher.FManager.ExecuteEventPublication(this.topic);
                Thread.Sleep(this.ms);
            }
        }