/// <summary>
        /// Creates the output.
        /// </summary>
        /// <returns></returns>
        private PublisherConfigurator CreateOutput()
        {
            var uri = new Uri(_publisherConfig.Output.Uri);

            _output = AgentGatewayFactory.CreateOutputGateway(_identification, uri, _publisherConfig.Output.Transport);
            return(this);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorHandlingController"/> class.
 /// </summary>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="identification">The identification.</param>
 internal ErrorHandlingController(IOutputGateway<IMessage> outputGateway, Identification identification)
 {
     _outputGateway = outputGateway;
     _identification = identification;
     _agentErrorHandlings = new List<IAgentErrorHandling>();
     _routerErrorHandlings = new List<IRouterErrorHandling>();
 }
Exemple #3
0
        /// <summary>
        ///     Adds the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="service">The service.</param>
        /// <param name="outputGateway">The output gateway.</param>
        public void Add(SubscriptionKey key, Identification service, IOutputGateway <byte[]> outputGateway)
        {
            LoggerManager.Instance.Info(string.Format("Add Type {0}", key.Key));
            bool lockTaken = false;

            _lockKeys.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    if (!_keyDictionary.ContainsKey(key))
                    {
                        _keyDictionary.Add(key, new List <IOutputGateway <byte[]> >());
                    }
                    _keyDictionary[key].Add(outputGateway);

                    ReloadAssignableTypes(key, service, outputGateway);
                }
                catch (Exception exception)
                {
                    LoggerManager.Instance.Error(string.Format("Error al añadir suscriptor {0}", key.Key), exception);
                }
                finally
                {
                    LoggerManager.Instance.Info(string.Format("Se libera el lock {0}", key.Key));
                    _lockKeys.Exit();
                }
            }
        }
        /// <summary>
        ///     Unsubscribes the specified type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="service"></param>
        /// <param name="sender">The sender.</param>
        public void Unsubscribe(SubscriptionKey type, Identification service, IOutputGateway <byte[]> sender)
        {
            bool lockTaken = false;

            _lockSubcriptorsList.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    if (_subcriptorsList.ContainsKey(service))
                    {
                        _subcriptorsList.Remove(service);
                    }
                }
                catch (Exception exception)
                {
                    LoggerManager.Instance.Error(string.Format("Error al añadir suscriptor {0}", service.Id), exception);
                }
                finally
                {
                    LoggerManager.Instance.Info(string.Format("Se libera el lock {0}", service.Id));
                    _lockSubcriptorsList.Exit();
                }
            }

            _gatewaysRepository.RemoveSender(type, service, sender);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorHandlingController"/> class.
 /// </summary>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="identification">The identification.</param>
 internal ErrorHandlingController(IOutputGateway <IMessage> outputGateway, Identification identification)
 {
     _outputGateway        = outputGateway;
     _identification       = identification;
     _agentErrorHandlings  = new List <IAgentErrorHandling>();
     _routerErrorHandlings = new List <IRouterErrorHandling>();
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Monitor"/> class.
 /// </summary>
 /// <param name="controller">The controller.</param>
 /// <param name="outputGateway">The output gateway.</param>
 public Monitor(IController controller, IOutputGateway <IMessage> outputGateway)
 {
     _samplers      = new List <ISampler>();
     _controller    = controller;
     _outputGateway = outputGateway;
     ConfigureStateMachine();
 }
        /// <summary>
        /// Creates the output.
        /// </summary>
        /// <returns></returns>
        private ErrorHandlingControllerConfigurator CreateOutput()
        {
            var uri = new Uri(_errorHandlingControllerConfig.Output.Uri);

            _output = AgentGatewayFactory.CreateOutputGateway(_identification, uri, _errorHandlingControllerConfig.Output.Transport);
            return(this);
        }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Monitor"/> class.
 /// </summary>
 /// <param name="controller">The controller.</param>
 /// <param name="outputGateway">The output gateway.</param>
 public Monitor(IController controller, IOutputGateway<IMessage> outputGateway)
 {
     _samplers = new List<ISampler>();
     _controller = controller;
     _outputGateway = outputGateway;
     ConfigureStateMachine();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ControlProcessor"/> class.
 /// </summary>
 /// <param name="identification">The identification.</param>
 /// <param name="inputGateway">The input gateway.</param>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="handlerRepository">The handler repository.</param>
 /// <param name="messageBuilder">The message builder.</param>
 /// <param name="reinjectionEngine">The reinjection engine.</param>
 internal ControlProcessor(Identification identification,
                           IInputGateway <IControlMessage, MessageHeader> inputGateway,
                           IOutputGateway <IControlMessage> outputGateway,
                           IHandlerRepository handlerRepository, IMessageBuilder messageBuilder, IReinjectionEngine reinjectionEngine)
     : base(identification, inputGateway, handlerRepository, messageBuilder, reinjectionEngine)
 {
     OutputGateway = outputGateway;
 }
Exemple #10
0
        /// <summary>
        /// Creates the specified monitorable processor.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="outputGateway">The output gateway.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <returns></returns>
        public IMonitor Create(IController controller,
                               IOutputGateway<IMessage> outputGateway,
                               IEnumerable<string> assemblies)
        {
            var samplers = CreateSamplers(assemblies, controller.Processor);

            var monitor = new Monitor(controller, outputGateway);
            foreach (var sampler in samplers)
            {
                monitor.AddSampler(sampler);
            }

            return monitor;
        }
Exemple #11
0
        /// <summary>
        ///     Removes the specified output gateway.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="service"></param>
        /// <param name="outputGateway">The output gateway.</param>
        public void Remove(SubscriptionKey key, Identification service, IOutputGateway <byte[]> outputGateway)
        {
            LoggerManager.Instance.Info(string.Format("Remove Type {0}", key.Key));
            bool lockTaken = false;

            _lockKeys.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    if (_keyDictionary.ContainsKey(key))
                    {
                        _keyDictionary[key].Remove(outputGateway);
                        if (_keyDictionary[key].Count == 0)
                        {
                            _keyDictionary.Remove(key);
                        }
                    }
                }
                finally
                {
                    _lockKeys.Exit();
                }
            }

            lockTaken = false;
            _lockAsignableTypes.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    SpinWait.SpinUntil(() => _numThreadsRunning == 0);

                    foreach (var assignableType in _assignableTypesList)
                    {
                        assignableType.Value.Remove(service.Type, outputGateway);
                    }

                    foreach (var assignableType in _assignableTypesList.Where(pair => pair.Value.Count == 0).ToList())
                    {
                        _assignableTypesList.Remove(assignableType);
                    }
                }
                finally
                {
                    _lockAsignableTypes.Exit();
                }
            }
        }
 /// <summary>
 ///     Creates the control processor.
 /// </summary>
 /// <param name="identification">The identification.</param>
 /// <param name="inputGateway">The input gateway.</param>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="handlerRepository">The handler repository.</param>
 /// <returns></returns>
 public static IController CreateControlProcessor(Identification identification,
                                                  IInputGateway <IControlMessage, MessageHeader> inputGateway,
                                                  IOutputGateway <IControlMessage> outputGateway,
                                                  IHandlerRepository handlerRepository)
 {
     return(new ControlProcessor(identification,
                                 inputGateway,
                                 outputGateway,
                                 handlerRepository,
                                 MessageBuilderFactory.CreateDefaultBuilder(),
                                 ReinjectionEngineFactory.CreateDefaultEngine(inputGateway))
     {
         Logger = LoggerManager.Instance
     });
 }
Exemple #13
0
        /// <summary>
        /// Creates the specified monitorable processor.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="outputGateway">The output gateway.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <returns></returns>
        public IMonitor Create(IController controller,
                               IOutputGateway <IMessage> outputGateway,
                               IEnumerable <string> assemblies)
        {
            var samplers = CreateSamplers(assemblies, controller.Processor);

            var monitor = new Monitor(controller, outputGateway);

            foreach (var sampler in samplers)
            {
                monitor.AddSampler(sampler);
            }

            return(monitor);
        }
Exemple #14
0
 /// <summary>
 ///     Creates the control processor.
 /// </summary>
 /// <param name="identification">The identification.</param>
 /// <param name="inputGateway">The input gateway.</param>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="handlerRepository">The handler repository.</param>
 /// <returns></returns>
 public static IController CreateControlProcessor(Identification identification,
                                                  IInputGateway<IControlMessage, MessageHeader> inputGateway,
                                                  IOutputGateway<IControlMessage> outputGateway,
                                                  IHandlerRepository handlerRepository)
 {
     return new ControlProcessor(identification,
                                 inputGateway,
                                 outputGateway,
                                 handlerRepository,
                                 MessageBuilderFactory.CreateDefaultBuilder(),
                                 ReinjectionEngineFactory.CreateDefaultEngine(inputGateway))
         {
             Logger = LoggerManager.Instance
         };
 }
Exemple #15
0
        /// <summary>
        ///     Reloads the assignable types.
        /// </summary>
        /// <param name="subscriptionKey">The subscription key.</param>
        /// <param name="service">The service.</param>
        /// <param name="outputGateway">The output gateway.</param>
        private void ReloadAssignableTypes(SubscriptionKey subscriptionKey, Identification service,
                                           IOutputGateway <byte[]> outputGateway)
        {
            //Recargamos la lista de tipos asignables
            bool lockTaken = false;

            _lockAsignableTypes.Enter(ref lockTaken);
            if (lockTaken)
            {
                SpinWait.SpinUntil(() => _numThreadsRunning == 0);

                foreach (var assignableType in _assignableTypesList)
                {
                    KeyValuePair <SubscriptionKey, List <IOutputGateway <byte[]> > > key =
                        _keyDictionary.FirstOrDefault(pair => pair.Key.Key == assignableType.Key);

                    if (key.Key != null && key.Key.IsAssignableKey(subscriptionKey.Key))
                    {
                        if (!assignableType.Value.Exists(outputGateway))
                        {
                            assignableType.Value.Add(service.Type, outputGateway);
                        }
                    }
                }

                if (!_assignableTypesList.ContainsKey(subscriptionKey.Key))
                {
                    var loadBalancerController = new LoadBalancerController <string, IOutputGateway <byte[]> >();
                    _assignableTypesList.Add(subscriptionKey.Key, loadBalancerController);

                    loadBalancerController.Add(service.Type, outputGateway);
                }

                _lockAsignableTypes.Exit();
            }
        }
Exemple #16
0
 /// <summary>
 ///     Unsubscribes the specified message type.
 /// </summary>
 /// <param name="messageType">Type of the message.</param>
 /// <param name="service"></param>
 /// <param name="outputGateway">The message sender.</param>
 public void Unsubscribe(SubscriptionKey messageType, Identification service,
                         IOutputGateway<byte[]> outputGateway)
 {
     _routerOutputHelper.Unsubscribe(messageType, service, outputGateway);
 }
Exemple #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusPublisher"/> class.
 /// </summary>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="messageBuilder">The message builder.</param>
 public BusPublisher(IOutputGateway<IMessage> outputGateway, IMessageBuilder messageBuilder)
 {
     _outputGateway = outputGateway;
     _messageBuilder = messageBuilder;
 }
Exemple #18
0
 /// <summary>
 /// Configures the output gateway.
 /// </summary>
 /// <param name="outputGateway">The output gateway.</param>
 public void ConfigureOutputGateway(IOutputGateway <IMessage> outputGateway)
 {
     OutputGateway = outputGateway;
 }
 /// <summary>
 /// Creates the output.
 /// </summary>
 /// <returns></returns>
 private ErrorHandlingControllerConfigurator CreateOutput()
 {
     var uri = new Uri(_errorHandlingControllerConfig.Output.Uri);
     _output = AgentGatewayFactory.CreateOutputGateway(_identification, uri, _errorHandlingControllerConfig.Output.Transport);
     return this;
 }
 /// <summary>
 /// Creates the output.
 /// </summary>
 /// <returns></returns>
 private PublisherConfigurator CreateOutput()
 {
     var uri = new Uri(_publisherConfig.Output.Uri);
     _output = AgentGatewayFactory.CreateOutputGateway(_identification, uri, _publisherConfig.Output.Transport);
     return this;
 }
Exemple #21
0
        /// <summary>
        ///     Unsubscribes the specified type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="service"></param>
        /// <param name="sender">The sender.</param>
        public void Unsubscribe(SubscriptionKey type, Identification service, IOutputGateway<byte[]> sender)
        {
            bool lockTaken = false;
            _lockSubcriptorsList.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    if (_subcriptorsList.ContainsKey(service))
                    {
                        _subcriptorsList.Remove(service);
                    }
                }
                catch (Exception exception)
                {
                    LoggerManager.Instance.Error(string.Format("Error al añadir suscriptor {0}", service.Id), exception);
                }
                finally
                {
                    LoggerManager.Instance.Info(string.Format("Se libera el lock {0}", service.Id));
                    _lockSubcriptorsList.Exit();
                }
            }

            _gatewaysRepository.RemoveSender(type, service, sender);
        }
 /// <summary>
 /// Removes the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public abstract void RemoveSender(SubscriptionKey type, Identification service, IOutputGateway<byte[]> sender);
 /// <summary>
 ///     Unsubscribes the specified message type.
 /// </summary>
 /// <param name="messageType">Type of the message.</param>
 /// <param name="service"></param>
 /// <param name="outputGateway">The message sender.</param>
 public void Unsubscribe(SubscriptionKey messageType, Identification service,
                         IOutputGateway <byte[]> outputGateway)
 {
     _routerOutputHelper.Unsubscribe(messageType, service, outputGateway);
 }
 /// <summary>
 /// Creates the specified output gateway.
 /// </summary>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="identification">The identification.</param>
 /// <returns></returns>
 public static IErrorHandlingController Create(IOutputGateway<IMessage> outputGateway, Identification identification)
 {
     return new ErrorHandlingController(outputGateway, identification);
 }
Exemple #25
0
 /// <summary>
 ///     Adds the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public override void AddSender(SubscriptionKey type, Identification service, IOutputGateway <byte[]> sender)
 {
     LoggerManager.Instance.Debug(string.Format("Add Sender: {0}", type.Key));
     HierarchicalKeyEngine.Add(type, service, sender);
 }
Exemple #26
0
 /// <summary>
 ///     Removes the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public override void RemoveSender(SubscriptionKey type, Identification service, IOutputGateway <byte[]> sender)
 {
     HierarchicalKeyEngine.Remove(type, service, sender);
 }
Exemple #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusPublisher"/> class.
 /// </summary>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="messageBuilder">The message builder.</param>
 public BusPublisher(IOutputGateway <IMessage> outputGateway, IMessageBuilder messageBuilder)
 {
     _outputGateway  = outputGateway;
     _messageBuilder = messageBuilder;
 }
Exemple #28
0
 /// <summary>
 /// Creates the bus publisher.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="messageBuilder">The message builder.</param>
 /// <returns></returns>
 public static BusPublisher CreateBusPublisher(IOutputGateway<IMessage> output, IMessageBuilder messageBuilder)
 {
     return new BusPublisher(output, messageBuilder);
 }
 /// <summary>
 /// Removes the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public abstract void RemoveSender(SubscriptionKey type, Identification service, IOutputGateway <byte[]> sender);
 /// <summary>
 /// Creates the specified output gateway.
 /// </summary>
 /// <param name="outputGateway">The output gateway.</param>
 /// <param name="identification">The identification.</param>
 /// <returns></returns>
 public static IErrorHandlingController Create(IOutputGateway <IMessage> outputGateway, Identification identification)
 {
     return(new ErrorHandlingController(outputGateway, identification));
 }
 /// <summary>
 ///     Adds the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public override void AddSender(SubscriptionKey type, Identification service, IOutputGateway<byte[]> sender)
 {
     LoggerManager.Instance.Debug(string.Format("Add Sender: {0}", type.Key));
     HierarchicalKeyEngine.Add(type, service, sender);
 }
Exemple #32
0
 /// <summary>
 /// Creates the bus publisher.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="messageBuilder">The message builder.</param>
 /// <returns></returns>
 public static BusPublisher CreateBusPublisher(IOutputGateway <IMessage> output, IMessageBuilder messageBuilder)
 {
     return(new BusPublisher(output, messageBuilder));
 }
 /// <summary>
 ///     Removes the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public override void RemoveSender(SubscriptionKey type, Identification service, IOutputGateway<byte[]> sender)
 {
     HierarchicalKeyEngine.Remove(type, service, sender);
 }