Code/SifCommonFramework/Systemic.Sif.Framework/Agent/DoubleAgent.cs
/// <summary>
/// Connect to the Zones and configure the Publishers and Subscribers.
/// </summary>
/// <exception cref="System.InvalidOperationException">The Agent has not been initialised first.</exception>
/// <exception cref="Edustructures.SifWorks.AdkException">The Agent was unable to connect to a Zone, or there is an error with the event processing for a Subscriber.</exception>
Connect to the Zones and configure the Publishers and Subscribers.
Connect to the Zones and configure the Publishers and Subscribers .
protected override void StartAgent()
        {
            if (!Initialized)
            {
                throw new InvalidOperationException("Publishing/subscribing Agent " + this.Id + " has not been initialised.");
            }
            IList<IBasePublisher> publishers;
            IList<IBaseSubscriber> subscribers;
            try
            {
                publishers = GetPublishers();
                subscribers = GetSubscribers();
            }
            catch (TargetException)
            {
                Shutdown();
                throw;
            }
            if (log.IsDebugEnabled) log.Debug("Starting publishing/subscribing Agent " + this.Id + "...");
            IZone[] zones = ZoneFactory.GetAllZones();
            if (zones.Length == 0)
            {
                if (log.IsWarnEnabled) log.Warn("No Zones specified for publishing/subscribing Agent " + this.Id + ". This publishing/subscribing Agent will do nothing.");
            }
            else
            {
                try
                {
                    foreach (IZone zone in zones)
                    {
                        foreach (IBasePublisher publisher in publishers)
                        {
                            zone.SetPublisher(publisher, publisher.SifObjectType, new PublishingOptions(true));
                            if (log.IsDebugEnabled) log.Debug("Registered Publisher " + publisher.GetType().FullName + " with Zone " + zone.ZoneId + ".");
                        }
                        foreach (IBaseSubscriber subscriber in subscribers)
                        {
                            zone.SetSubscriber(subscriber, subscriber.SifObjectType, new SubscriptionOptions());
                            zone.SetQueryResults(subscriber, subscriber.SifObjectType, new QueryResultsOptions());
                            if (log.IsDebugEnabled) log.Debug("Registered Subscriber " + subscriber.GetType().FullName + " with Zone " + zone.ZoneId + ".");
                        }
                        try
                        {
                            zone.Connect(ProvisioningFlags.Register);
                            if (log.IsDebugEnabled) log.Debug("Connected publishing/subscribing Agent " + this.Id + " to zone " + zone.ZoneId + ".");
                        }
                        catch (AdkException e)
                        {
                            if (log.IsErrorEnabled) log.Error("Publishing/subscribing Agent " + this.Id + " was unable to connect to Zone " + zone.ZoneId + ".", e);
                            throw;
                        }
                    }
                    foreach (IBasePublisher publisher in publishers)
                    {
                        try
                        {
                            publisher.StartEventProcessing(zones);
                        }
                        catch (AdkException e)
                        {
                            if (log.IsErrorEnabled) log.Error("Error with event processing of Publisher " + publisher.GetType().FullName + ".", e);
                            throw;
                        }
                    }
                    foreach (IBaseSubscriber subscriber in subscribers)
                    {
                        try
                        {
                            subscriber.StartRequestProcessing(zones);
                        }
                        catch (AdkException e)
                        {
                            if (log.IsErrorEnabled) log.Error("Error with request processing of Subscriber " + subscriber.GetType().FullName + ".", e);
                            throw;
                        }
                    }
                }
                catch (AdkException)
                {
                    foreach (IZone zone in zones)
                    {
                        if (zone.Connected)
                        {
                            zone.Disconnect(ProvisioningFlags.Unregister);
                        }
                    }
                    throw;
                }
            }
        }
protected override void StartAgent ( ) { if ( ! Initialized ) { throw new InvalidOperationException ( " " + this . Id + " " ) ; } IList < IBasePublisher > publishers ; IList < IBaseSubscriber > subscribers ; try { publishers = GetPublishers ( ) ; subscribers = GetSubscribers ( ) ; } catch ( TargetException ) { Shutdown ( ) ; throw ; } if ( log . IsDebugEnabled ) log . Debug ( " " + this . Id + " " ) ; IZone [ ] zones = ZoneFactory . GetAllZones ( ) ; if ( zones . Length == 0 ) { if ( log . IsWarnEnabled ) log . Warn ( " " + this . Id + " " ) ; } else { try { foreach ( IZone zone in zones ) { foreach ( IBasePublisher publisher in publishers ) { zone . SetPublisher ( publisher , publisher . SifObjectType , new PublishingOptions ( true ) ) ; if ( log . IsDebugEnabled ) log . Debug ( " " + publisher . GetType ( ) . FullName + " " + zone . ZoneId + " " ) ; } foreach ( IBaseSubscriber subscriber in subscribers ) { zone . SetSubscriber ( subscriber , subscriber . SifObjectType , new SubscriptionOptions ( ) ) ; zone . SetQueryResults ( subscriber , subscriber . SifObjectType , new QueryResultsOptions ( ) ) ; if ( log . IsDebugEnabled ) log . Debug ( " " + subscriber . GetType ( ) . FullName + " " + zone . ZoneId + " " ) ; } try { zone . Connect ( ProvisioningFlags . Register ) ; if ( log . IsDebugEnabled ) log . Debug ( " " + this . Id + " " + zone . ZoneId + " " ) ; } catch ( AdkException e ) { if ( log . IsErrorEnabled ) log . Error ( " " + this . Id + " " + zone . ZoneId + " " , e ) ; throw ; } } foreach ( IBasePublisher publisher in publishers ) { try { publisher . StartEventProcessing ( zones ) ; } catch ( AdkException e ) { if ( log . IsErrorEnabled ) log . Error ( " " + publisher . GetType ( ) . FullName + " " , e ) ; throw ; } } foreach ( IBaseSubscriber subscriber in subscribers ) { try { subscriber . StartRequestProcessing ( zones ) ; } catch ( AdkException e ) { if ( log . IsErrorEnabled ) log . Error ( " " + subscriber . GetType ( ) . FullName + " " , e ) ; throw ; } } } catch ( AdkException ) { foreach ( IZone zone in zones ) { if ( zone . Connected ) { zone . Disconnect ( ProvisioningFlags . Unregister ) ; } } throw ; } } }
Connect to the Zones and configure the Publishers and Subscribers.
Connect to the Zones and configure the Publishers and Subscribers .
// If the Agent has not been initialised, throw an exception. // Get the Publishers and Subscribers handled by this Agent. // Connect to each Zone specified in the Agent configuration file. // For each Publisher, register (provision) it with the Zone. // For each Subscriber, register (provision) it with the Zone. // Connect to the Zone. // Start event processing for each Publisher. // Start request processing for each Subscriber. // In the event of an error, disconnect from the Zones.
The Agent has not been initialised first.
The Agent has not been initialised first .
The Agent was unable to connect to a Zone, or there is an error with the event processing for a Subscriber.
The Agent was unable to connect to a Zone or there is an error with the event processing for a Subscriber .