예제 #1
0
        public void should_add_new_message_processor()
        {
            _messageProcessor = _mockRepository.StrictMock<IMessageProcessor>();
            _roomListener.AddProcessor(_messageProcessor);

            Assert.That(_roomListener.MessageProcessors.Contains (_messageProcessor), Is.True);
        }
예제 #2
0
파일: TCPListener.cs 프로젝트: krembf/ESRI
        public TCPListener(int _portNumber, IMessageProcessor _messageProcessor)
        {
            PortNumber = _portNumber;
            MessageProcessor = _messageProcessor;

            tcpListener = new TcpListener(IPAddress.Any, PortNumber);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandRunner"/> class. 
        /// </summary>
        /// <param name="processor">The <see cref="IMessageProcessor"/>.</param>
        /// <param name="receiver">The <see cref="ICommandReceiver"/>.</param>
        /// <param name="degreeOfParallelism">The maximum degree of parallelism.</param>
        public CommandRunner(IMessageProcessor processor, ICommandReceiver receiver, int degreeOfParallelism)
        {
            if (processor == null)
            {
                throw new ArgumentNullException("processor");
            }

            if (receiver == null)
            {
                throw new ArgumentNullException("receiver");
            }

            if (degreeOfParallelism <= 0)
            {
                throw new ArgumentOutOfRangeException("degreeOfParallelism");
            }

            this.runners = new CommandQueueRunner[degreeOfParallelism];
            this.receiver = receiver;
            for (int i = 0; i < this.runners.Length; i++)
            {
                var runner = new CommandQueueRunner(processor, receiver);
                this.runners[i] = runner;
            }
        }
예제 #4
0
 public Skype(IMessageProcessor messageProcessor )
 {
     _messageProcessor = messageProcessor;
     _skype = new SKYPE4COMLib.Skype();
     UseSkypeProtocolSeven();
     AttachMessageProcessorHandler();
 }
예제 #5
0
 public CommunicationParser(IMessageBuilder messageBuilder, IMessageProcessor messageProcessor, IEncodingAdapter encodingAdapter, ILogger logger, IMessageWriter messageWriter)
 {
     this._messageBuilder = messageBuilder;
     this._messageProcessor = messageProcessor;
     this._encodingAdapter = encodingAdapter;
     this._logger = logger;
     this._messageWriter = messageWriter;
 }
        private ISerialPort port; // serial port connection to the INSTEON controller

        public InsteonNetworkBridge(IMessageProcessor messageProcessor)
        {
            if (messageProcessor == null)
            {
                throw new ArgumentNullException(nameof(messageProcessor));
            }
            this.messageProcessor = messageProcessor;
        }
예제 #7
0
파일: Host.cs 프로젝트: kellyelton/chattr
 public Host(IListener listener, IMessageProcessor processor)
 {
     if (listener == null)
         throw new ArgumentNullException("listener");
     if(processor == null)
         throw new ArgumentNullException("processor");
     Listener = listener;
 }
예제 #8
0
 public PipelineConsumerWork(IMessageProcessor processor, IEndpoint endpoint, ISerializer serializer, MessageThreshold messageThreshold, IEndpointCircuitBreaker circuitBreaker)
 {
     this.endpoint = endpoint;
     this.processor = processor;
     this.circuitBreaker = circuitBreaker;
     this.serializer = serializer;
     this.messageThreshold = messageThreshold ?? new MessageThreshold();
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HealthWorker"/> class.
 /// </summary>
 /// <param name="processor">The parent processor.</param>
 /// <param name="name">The name of the worker.</param>
 public HealthWorker(IMessageProcessor processor, string name)
     : base(processor, name)
 {
     // create throttle lock to only allow one run per schedule
     var lockCollection = Configuration.LockCollection ?? "ServiceLock";
     var collection = Repository.Collection.Database.GetCollection<LockData>(lockCollection);
     _lockManager = new ThrottleLock(collection, Configuration.HealthCheck);
 }
예제 #10
0
        public GameStorage(IObjectContainer db, IMessageProcessor flash)
        {
            Database = db;
            Flash = flash;

            Reader = new MessageReader(Flash);
            Reader.ObjectRead += Reader_ObjectRead;
        }
예제 #11
0
 void IServiceConnector.Close()
 {
     try {
         Close();
     } finally {
         connected = false;
         processor = null;
     }
 }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EndpointConsumer{TContract}"/> class.
 /// </summary>
 /// <param name="transport">The transport.</param>
 /// <param name="messageProcessor">The message processor.</param>
 /// <param name="serializer">The serializer.</param>
 /// <param name="messageThreshold">The message threshold.</param>
 /// <param name="circuitBreakerFactory">The circuit breaker factory.</param>
 public EndpointConsumer(IPipelineTransport transport, IMessageProcessor messageProcessor, ISerializer serializer, MessageThreshold messageThreshold, IEndpontCircuitBreakerFactrory circuitBreakerFactory)
 {
     NumberOfWorkers = 1;
     this.messageProcessor = messageProcessor;
     this.transport = transport;
     pools = new List<WorkPool>();
     this.serializer = serializer;
     this.messageThreshold = messageThreshold;
     this.circuitBreakerFactory = circuitBreakerFactory;
 }
예제 #13
0
        public Messager(INetworkMessager networkMessager, IMessageProcessor messageProcessor, ILogger logger)
        {
            _networkMessager = networkMessager;
            _messageProcessor = messageProcessor;
            _logger = logger;

            _networkMessager.ClientConnected += NetworkClientConnected;
            _networkMessager.ClientMessageReceived += NetworkClientMessageReceived;
            _networkMessager.ClientDisconnected += NetworkClientDisconnected;
        }
예제 #14
0
 public ApplicationMessageConsumer(string groupName = null, ConsumerSetting setting = null)
 {
     _consumer = new Consumer(groupName ?? DefaultMessageConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential
     });
     _jsonSerializer = ObjectContainer.Resolve<IJsonSerializer>();
     _processor = ObjectContainer.Resolve<IMessageProcessor<ProcessingApplicationMessage, IApplicationMessage, bool>>();
     _typeNameProvider = ObjectContainer.Resolve<ITypeNameProvider>();
 }
예제 #15
0
 public PublishableExceptionConsumer(string id = null, string groupName = null, ConsumerSetting setting = null)
 {
     _consumer = new Consumer(groupName ?? DefaultExceptionConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential
     });
     _jsonSerializer = ObjectContainer.Resolve<IJsonSerializer>();
     _publishableExceptionProcessor = ObjectContainer.Resolve<IMessageProcessor<ProcessingPublishableExceptionMessage, IPublishableException, bool>>();
     _publishableExceptionTypeCodeProvider = ObjectContainer.Resolve<ITypeCodeProvider>();
 }
예제 #16
0
        public static async Task <HandlerResponse <TResult> > ProcessAsync <TResult>(this IMessageProcessor processor, ICommand command, CancellationToken cancellationToken)
        {
            if (processor == null)
            {
                throw Error.ArgumentNull("processor");
            }

            var response = await processor.ProcessAsync(command, cancellationToken);

            return(new HandlerResponse <TResult>(response));
        }
예제 #17
0
 public CommandConsumer(string groupName = null, ConsumerSetting setting = null)
 {
     _consumer             = new Consumer(groupName ?? DefaultCommandConsumerGroup, setting);
     _sendReplyService     = new SendReplyService();
     _jsonSerializer       = ObjectContainer.Resolve <IJsonSerializer>();
     _typeNameProvider     = ObjectContainer.Resolve <ITypeNameProvider>();
     _processor            = ObjectContainer.Resolve <IMessageProcessor <ProcessingCommand, ICommand, CommandResult> >();
     _repository           = ObjectContainer.Resolve <IRepository>();
     _aggregateRootStorage = ObjectContainer.Resolve <IAggregateStorage>();
     _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
 }
 public ServiceBusTopicChannelReceiver(IProcessingSettings settings, IEventSubscription <TTopic> subscription, IServiceBusConfiguration configuration, IHostConfiguration hostConfiguration, IMessageProcessor processor)
 {
     Settings          = settings;
     _managementClient = new ManagementClient(configuration.ConnectionString);
     _subscription     = subscription;
     _log           = hostConfiguration.Log;
     _configuration = configuration;
     _processor     = processor;
     //new client factory per ServiceBusTopicChannelReceiver means a separate communication channel per reader instead of a shared
     _clientFactory = new ClientFactory(configuration.ConnectionString);
 }
예제 #19
0
        public IMessageProcessor GetMessageProcessor(string address)
        {
            IMessageProcessor rv = null;

            if (_messageProcessors.ContainsKey(address))
            {
                rv = _messageProcessors[address];
            }

            return(rv);
        }
예제 #20
0
 /// <summary>
 /// Registers a <see cref="IMessageProcessor"/> to the available <see cref="Processors"/>.
 /// </summary>
 /// <param name="proc">The <see cref="IMessageProcessor"/> to register.</param>
 public static void Register(IMessageProcessor proc)
 {
     lock (SyncLock)
     {
         if (Processors.Contains(proc))
         {
             return;
         }
         Processors.Add(proc);
     }
 }
예제 #21
0
        public MessageConsumer(IOptions <RabbitMqClientOptions> options, ISettingsProvider settingsProvider, IMessageProcessor messageProcessor, ILogger <MessageConsumer> logger)
            : base(options, logger)
        {
            _SettingsProvider = settingsProvider
                                ?? throw new ArgumentException($"Argument {nameof(settingsProvider)} is null.", nameof(settingsProvider));
            _MessageProcessor = messageProcessor;
            _Logger           = logger;

            _Queues = new List <Queue>();
            _Logger.LogInformation("MessageConsumer created");
        }
 public KafkaMessageHandler(IMessageParser messageParser,
                            IMessageProcessor messageProcessor,
                            IKafkaPublisherExecutor publisher,
                            ILogger <KafkaMessageHandler> logger,
                            SystemInfo systemInfo)
 {
     _messageParser    = messageParser ?? throw new ArgumentNullException(nameof(messageParser));
     _messageProcessor = messageProcessor ?? throw new ArgumentNullException(nameof(messageProcessor));
     _publisher        = publisher ?? throw new ArgumentNullException(nameof(publisher));
     _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
     _systemInfo       = systemInfo ?? throw new ArgumentNullException(nameof(systemInfo));
 }
 public PublishableExceptionConsumer(string groupName = null, ConsumerSetting setting = null)
 {
     _consumer = new Consumer(groupName ?? DefaultExceptionConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential,
         ConsumeFromWhere  = ConsumeFromWhere.FirstOffset
     });
     _jsonSerializer = ObjectContainer.Resolve <IJsonSerializer>();
     _publishableExceptionProcessor = ObjectContainer.Resolve <IMessageProcessor <ProcessingPublishableExceptionMessage, IPublishableException> >();
     _typeNameProvider = ObjectContainer.Resolve <ITypeNameProvider>();
     _logger           = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
 }
예제 #24
0
        /// <summary>
        /// Invokes the <see cref="IMessageProcessor"/> for handle processing a message block.
        /// </summary>
        /// <param name="socket">The <see cref="IIPSocket"/> that the data came from.</param>
        /// <param name="processor">The <see cref="IMessageProcessor"/> to invoke.</param>
        /// <param name="reader">The <see cref="BitStream"/> containing the data to process.</param>
        protected override void InvokeProcessor(IIPSocket socket, IMessageProcessor processor, BitStream reader)
        {
            // Invoke the processor as normal, but keeping track of the bit position before and after invoking
            var startBits = reader.PositionBits;

            base.InvokeProcessor(socket, processor, reader);

            var endBits = reader.PositionBits;

            // Update the stats
            _stats.HandleProcessorInvoked(processor.MsgID, endBits - startBits);
        }
예제 #25
0
        // string localIpAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString()
        public LocalNode(int port) : base(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString(), port)
        {
            localResources  = new Dictionary <string, Tuple <string, string> >();
            msgProccessor   = new LocalMessageProcessor(this);
            serverComponent = new AsynchronousServer(port, msgProccessor);
            clientComponent = new AsynchronousClient();

            predNode = this;
            succNode = this;

            var serverTask = Task.Run(() => serverComponent.StartServer());
        }
예제 #26
0
        public MessageProcessorTests()
        {
            var expectedMappedModel = GetSegmentModel();

            mappingService = A.Fake <IMappingService>();
            A.CallTo(() => mappingService.MapToSegmentModel(A <string> .Ignored, A <long> .Ignored)).Returns(expectedMappedModel);

            httpClientService = A.Fake <IHttpClientService>();
            A.CallTo(() => httpClientService.DeleteAsync(A <Guid> .Ignored)).Returns(HttpStatusCode.OK);

            processor = new MessageProcessor(httpClientService, mappingService);
        }
예제 #27
0
        public Listener(IConnectionFactory connectionFactory, IConsumerFactory consumerFactory, MessageType type, string queueName,
                        string exchangeName, IEnumerable <IMessageProcessor> messageProcessors, ILogger <Listener> logger)
        {
            _consumerFactory   = consumerFactory;
            _type              = type;
            _queueName         = queueName;
            _exchangeName      = exchangeName;
            _connectionFactory = connectionFactory;
            _logger            = logger;

            _messageProcessor = messageProcessors.FirstOrDefault(t => t.Type == type);
        }
예제 #28
0
        public TCPServer(IMessageProcessor processor, string ipAddress, int port)
        {
            this.processor = processor;
            socket         = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(ipAddress), port);

            processor?.Process($"TCP Server listening on {endPoint.ToString()}");
            socket.Bind(endPoint);      //  bind socketu na poslouchani tohoto endPointu

            socket.Listen(ListenerCount);
        }
예제 #29
0
 protected override void Dispose(bool disposing)
 {
     if(disposing)
     {
         if(processor != null) processor.Dispose();
         if(server != null) ((IDisposable) server).Dispose();
     }
     processor = null;
     factory = null;
     server = null;
     base.Dispose(disposing);
 }
        /// <summary>
        /// Invokes the <see cref="IMessageProcessor"/> for handle processing a message block.
        /// </summary>
        /// <param name="socket">The <see cref="IIPSocket"/> that the data came from.</param>
        /// <param name="processor">The <see cref="IMessageProcessor"/> to invoke.</param>
        /// <param name="reader">The <see cref="BitStream"/> containing the data to process.</param>
        protected override void InvokeProcessor(IIPSocket socket, IMessageProcessor processor, BitStream reader)
        {
            // Invoke the processor as normal, but keeping track of the bit position before and after invoking
            var startBits = reader.PositionBits;

            base.InvokeProcessor(socket, processor, reader);

            var endBits = reader.PositionBits;

            // Update the stats
            _stats.HandleProcessorInvoked(processor.MsgID, endBits - startBits);
        }
예제 #31
0
        private Message Command(IServiceAddress machine, ServiceType serviceType, MessageStream message)
        {
            IMessageProcessor     proc  = Connector.Connect(machine, serviceType);
            IEnumerable <Message> msgIn = proc.Process(message);
            Message lastM = null;

            foreach (Message m in msgIn)
            {
                lastM = m;
            }
            return(lastM);
        }
예제 #32
0
        public bool ProcessMessage(IMessageProcessor processor, IBuildVisitor buildVisitor, IServiceMessage message)
        {
            var processed = false;

            switch (message.Name?.ToLowerInvariant())
            {
            case "message":
                var text = message.GetValue("text");
                if (text != null)
                {
                    var status = message.GetValue("status")?.ToUpperInvariant();
                    switch (status)
                    {
                    case "ERROR":
                        _log.Trace(() => new[] { new Text($"Add error {text}") });
                        buildVisitor.Visit(new BuildError(text));
                        break;

                    case "WARNING":
                        _log.Trace(() => new[] { new Text($"Add warning {text}") });
                        buildVisitor.Visit(new BuildWarning(text));
                        break;
                    }
                }

                var parseInternal = message.GetValue("tc:tags")?.ToLowerInvariant() == "tc:parseservicemessagesinside";
                if (!parseInternal || !processor.ProcessServiceMessages(text, buildVisitor))
                {
                    WriteLine(text);
                }

                processed = true;
                break;

            case "blockopened":
                var blockName = message.GetValue("name");
                _log.Trace(() => new [] { new Text($"Open block {blockName}") });
                WriteLine(blockName);
                _tabs++;
                _tabsString = new string(' ', _tabs *Text.Tab.Value.Length);
                processed   = true;
                break;

            case "blockclosed":
                _log.Trace(() => new[] { new Text("Close block") });
                _tabs--;
                _tabsString = new string(' ', _tabs *Text.Tab.Value.Length);
                processed   = true;
                break;
            }

            return(processed);
        }
예제 #33
0
        public IMessageProcessor GetPipeline(IMessageProcessor baseProcessor)
        {
            var processors = new IMessageProcessor[_middlewares.Count + 1];

            processors[processors.Length - 1] = baseProcessor;
            for (var i = processors.Length - 2; i >= 0; i--)
            {
                processors[i] = new MiddlewareWrapper(_middlewares[i], processors[i + 1]);
            }

            return(processors[0]);
        }
예제 #34
0
        public ApplicationMessageConsumer(string id = null, string groupName = null, ConsumerSetting setting = null)
        {
            var consumerId = id ?? DefaultMessageConsumerId;

            _consumer = new Consumer(consumerId, groupName ?? DefaultMessageConsumerGroup, setting ?? new ConsumerSetting
            {
                MessageHandleMode = MessageHandleMode.Sequential
            });
            _jsonSerializer   = ObjectContainer.Resolve <IJsonSerializer>();
            _processor        = ObjectContainer.Resolve <IMessageProcessor <ProcessingApplicationMessage, IApplicationMessage, bool> >();
            _typeCodeProvider = ObjectContainer.Resolve <ITypeCodeProvider>();
        }
 public ServiceBusQueueChannelReceiver(IProcessingSettings settings, IMessageSerializer serializer, IServiceBusConfiguration configuration, IHostConfiguration hostConfiguration, IMessageProcessor processor)
 {
     _serializer        = serializer;
     _configuration     = configuration;
     _hostConfiguration = hostConfiguration;
     _processor         = processor;
     Settings           = settings;
     _log = hostConfiguration.Log;
     //new client factory per ServiceBusQueueChannelReceiver means a separate communication channel per reader instead of a shared
     _clientFactory    = new ClientFactory(configuration.ConnectionString);
     _managementClient = new ServiceBusAdministrationClient(configuration.ConnectionString);
 }
예제 #36
0
        public ConnectionClient(IClientConnector connector, DeveelDbConnectionStringBuilder settings)
        {
            if (connector == null)
            {
                throw new ArgumentNullException("connector");
            }

            Settings      = settings;
            Connector     = connector;
            Processor     = connector.CreateProcessor();
            OwnsConnector = false;
        }
예제 #37
0
        public MainViewModel(ICommunicator communicator, IMessageBuilder messageBuilder, IMessageProcessor messageProcessor)
        {
            _messageBuilder   = messageBuilder;
            _messageProcessor = messageProcessor;
            _communicator     = communicator;

            _communicator.DataReceived += CommunicatorOnDataReceived;

            BuildControllers();
            GetPossibleConnectionSettings();
            RegisterCommands();
        }
        /// <summary>
        /// Creates instance of <see cref="MessageProcessor"/>
        /// </summary>
        /// <param name="logger">Provides logging</param>
        /// <param name="telegramBotClient">A client interface to use the Telegram Bot API</param>
        /// <param name="messageProcessorFactory">Provides the necessary message processor</param>
        /// <param name="adminIdsProvider">Provides the list of admins</param>
        /// <param name="messageTypeIdentifier">Identifies the type of message</param>
        public MessageProcessor(ILogger logger, ITelegramBotClient telegramBotClient,
                                IMessageProcessorFactory messageProcessorFactory, IAdminIdsProvider adminIdsProvider,
                                IMessageTypeIdentifier messageTypeIdentifier)
        {
            _adminIdsProvider      = adminIdsProvider;
            _messageTypeIdentifier = messageTypeIdentifier;
            _adminMessageProcessor = messageProcessorFactory.GetMessageProcessor <AdminMessageProcessor>();
            _userMessageProcessor  = messageProcessorFactory.GetMessageProcessor <UserMessageProcessor>();
            _adminIds = adminIdsProvider.AdminIds;

            adminIdsProvider.AdminListUpdatedAction += UpdateAdminIds;
        }
 public SubscriptionClientHostedService(ILogger <SubscriptionClientHostedService> logger,
                                        IAzureKeyVaultService azureKeyVaultService,
                                        IConfiguration configuration,
                                        IMessageProcessor messageProcessor)
 {
     _logger = logger;
     _azureKeyVaultService = azureKeyVaultService;
     _messageProcessor     = messageProcessor;
     _topicName            = configuration["ExtractTopicName"];
     _subscriptionName     = configuration["ExtractSubscriptionName"];
     _serviceBusConnectionStringSecretName = configuration["ServiceBusConnectionStringSecretName"];
 }
예제 #40
0
        protected void AddConsumer(AbstractConsumerSettings consumerSettings, IMessageProcessor <Message> messageProcessor)
        {
            if (consumerSettings is null)
            {
                throw new ArgumentNullException(nameof(consumerSettings));
            }

            var consumer = consumerSettings.GetKind() == PathKind.Topic
                ? new TopicSubscriptionConsumer(this, consumerSettings, messageProcessor) as BaseConsumer
                : new QueueConsumer(this, consumerSettings, messageProcessor);

            _consumers.Add(consumer);
        }
예제 #41
0
 public ApplicationMessageConsumer Initialize(string groupName = null, ConsumerSetting setting = null)
 {
     _consumer = new Consumer(groupName ?? DefaultMessageConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential,
         ConsumeFromWhere  = ConsumeFromWhere.FirstOffset
     });
     _jsonSerializer   = ObjectContainer.Resolve <IJsonSerializer>();
     _processor        = ObjectContainer.Resolve <IMessageProcessor <ProcessingApplicationMessage, IApplicationMessage> >();
     _typeNameProvider = ObjectContainer.Resolve <ITypeNameProvider>();
     _logger           = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
     return(this);
 }
        public StorageQueueChannelReceiver(IProcessingSettings settings, IMessageProcessor processor, IHostConfiguration hostConfiguration, IStorageBusConfiguration storageOptions)
        {
            if (settings.PrefetchCount > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(settings),
                                                      "PrefetchCount is set too high. The maximum number of messages that may be retrieved at a time is 32.");
            }

            Settings           = settings;
            _storageOptions    = storageOptions;
            _processor         = processor;
            _hostConfiguration = hostConfiguration;
        }
예제 #43
0
 public DomainEventConsumer(string groupName = null, ConsumerSetting setting = null, bool sendEventHandledMessage = true)
 {
     _consumer = new Consumer(groupName ?? DefaultEventConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential
     });
     _sendReplyService = new SendReplyService();
     _jsonSerializer = ObjectContainer.Resolve<IJsonSerializer>();
     _eventSerializer = ObjectContainer.Resolve<IEventSerializer>();
     _processor = ObjectContainer.Resolve<IMessageProcessor<ProcessingDomainEventStreamMessage, DomainEventStreamMessage, bool>>();
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
     _sendEventHandledMessage = sendEventHandledMessage;
 }
예제 #44
0
 /// <summary>
 /// Initializes an instance of the <see cref="TcpNetworkConnector"/> class as client.
 /// </summary>
 /// <param name="messageTypeCache">The message type cache.</param>
 /// <param name="messageSerializer">The message serializer.</param>
 /// <param name="messageProcessor">The message processor.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="host">The host string.</param>
 /// <param name="port">The port.</param>
 public TcpNetworkConnector(
     IMessageTypeCache messageTypeCache,
     IMessageSerializer messageSerializer,
     IMessageProcessor messageProcessor,
     ILogger <TcpNetworkConnector> logger,
     string host, int port) : base(messageTypeCache, messageSerializer, messageProcessor, logger)
 {
     Host      = host;
     Port      = port;
     TcpClient = new TcpClient {
         Client = { NoDelay = true }
     };
 }
예제 #45
0
 public DomainEventConsumer(string groupName = null, ConsumerSetting setting = null, bool sendEventHandledMessage = true)
 {
     _consumer = new Consumer(groupName ?? DefaultEventConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential
     });
     _sendReplyService        = new SendReplyService();
     _jsonSerializer          = ObjectContainer.Resolve <IJsonSerializer>();
     _eventSerializer         = ObjectContainer.Resolve <IEventSerializer>();
     _processor               = ObjectContainer.Resolve <IMessageProcessor <ProcessingDomainEventStreamMessage, DomainEventStreamMessage, bool> >();
     _logger                  = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
     _sendEventHandledMessage = sendEventHandledMessage;
 }
예제 #46
0
        static void Main(string[] args)
        {
            InitializeENodeFramework();

            _commandCount     = int.Parse(ConfigurationManager.AppSettings["count"]);
            _logger           = ObjectContainer.Resolve <ILoggerFactory>().Create("main");
            _repository       = ObjectContainer.Resolve <IRepository>();
            _commandProcessor = ObjectContainer.Resolve <IMessageProcessor <ProcessingCommand, ICommand, CommandResult> >();

            var createCommands = new List <ProcessingCommand>();
            var updateCommands = new List <ProcessingCommand>();

            for (var i = 0; i < _commandCount; i++)
            {
                var noteId = ObjectId.GenerateNewStringId();
                createCommands.Add(new ProcessingCommand(new CreateNoteCommand
                {
                    AggregateRootId = noteId,
                    Title           = "Sample Note"
                }, new CommandExecuteContext(_commandCount), new Dictionary <string, string>()));
                updateCommands.Add(new ProcessingCommand(new ChangeNoteTitleCommand
                {
                    AggregateRootId = noteId,
                    Title           = "Changed Note Title"
                }, new CommandExecuteContext(_commandCount), new Dictionary <string, string>()));
            }

            _waitHandle = new ManualResetEvent(false);
            _watch      = Stopwatch.StartNew();
            Console.WriteLine("--Start to process create aggregate commands, total count: {0}.", _commandCount);
            foreach (var command in createCommands)
            {
                _commandProcessor.Process(command);
            }
            _waitHandle.WaitOne();
            Console.WriteLine("--Commands process completed, throughput: {0}/s", _commandCount * 1000 / _watch.ElapsedMilliseconds);

            _executedCount = 0;
            _waitHandle    = new ManualResetEvent(false);
            _watch         = Stopwatch.StartNew();
            Console.WriteLine("");
            Console.WriteLine("--Start to process update aggregate commands, total count: {0}.", _commandCount);
            foreach (var command in updateCommands)
            {
                _commandProcessor.Process(command);
            }
            _waitHandle.WaitOne();
            Console.WriteLine("--Commands process completed, throughput: {0}/s", _commandCount * 1000 / _watch.ElapsedMilliseconds);

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            IMessageProcessor processor = MessageFactory.GetInstance();

            processor.Init(10000, 5000);
            processor.Register(new MessageContext()
            {
                Key = "IES", Address = new string[] { "10.130.36.225:9015" }, QueueSize = 16
            });
            processor.AddMessage("IES", new IESMessage()
            {
                ID = "IES001", DeviceID = "Device001"
            });
            Thread.Sleep(5000);
            processor.Register(new MessageContext()
            {
                Key = "LIVE", Address = new string[] { "10.130.36.225:9017" }, QueueSize = 16
            });
            processor.AddMessage("LIVE", new LIVEMessage()
            {
                MsgBody = "LIVE001&Device002"
            });
            Thread.Sleep(5000);
            processor.AddMessage("IES", new IESMessage()
            {
                ID = "IES002", DeviceID = "Device001"
            });
            processor.AddMessage("LIVE", new LIVEMessage()
            {
                MsgBody = "LIVE002&Device002"
            });
            //Thread t = new Thread(new ParameterizedThreadStart(SetStatus1));
            //t.Start(processor);
            //Thread.Sleep(5000);
            //Console.WriteLine(DateTime.Now + " Main SetTargetStatus");
            //processor.SetTargetStatus("key1", true);
            //Console.WriteLine(DateTime.Now + " AddMessage");
            //processor.AddMessage("key2", new MyMessage());
            //processor.AddMessage("key1", new MyMessage());
            //Thread.Sleep(5000);
            //processor.SetTargetAddress("key2", new string[] { "10.130.36.100:1111" });
            //processor.SetTargetStatus("key2", true);
            //Thread.Sleep(5000);
            //Thread t2 = new Thread(new ParameterizedThreadStart(SetStatus2));
            //t2.Start(processor);
            //Thread.Sleep(5000);
            //Console.WriteLine(DateTime.Now + " Main SetTargetStatus");
            //processor.SetTargetStatus("key2", true);
            //processor.AddMessage("key2", new MyMessage());
            Console.ReadKey();
        }
예제 #48
0
        public BusPoller(ITransport transport, IMessageProcessor processor, uint countOfWorkers, string address)
        {
            this.transport = transport;
            this.processor = processor;
            this.address = address;
            if (countOfWorkers == 0)
            {
                throw new ArgumentException("Count of workers must be greater than zero", "countOfWorkers");
            }

            workers = new Thread[countOfWorkers];
            waitHandles = new AutoResetEvent[countOfWorkers];
            cancellationTokenSource = new CancellationTokenSource();
        }
예제 #49
0
        private static void registerManager(IMessageProcessor p, String source)
        {
            MethodInfo[] minfos = typeof(IMessageProcessor).GetMethods();
            foreach (MethodInfo minfo in minfos)
            {
                Console.WriteLine(minfo.Name);
                String methodName = minfo.Name;
                String[] fields = methodName.Split('_');
                String type = fields[1];

                processors[source + type] = Delegate.CreateDelegate(typeof(process_message), p, minfo.Name) as process_message;// p.GetType().GetMethod(minfo.Name).DeclaringType;

            }
        }
예제 #50
0
        public CommandQueueRunner(IMessageProcessor processor, ICommandReceiver receiver)
        {
            if (processor == null)
            {
                throw new ArgumentNullException("processor");
            }

            if (receiver == null)
            {
                throw new ArgumentNullException("receiver");
            }

            this.receiver = receiver;
            this.processor = processor;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageWorkerBase"/> class.
        /// </summary>
        /// <param name="processor">The parent processor.</param>
        /// <param name="name">The name of the worker.</param>
        /// <exception cref="ArgumentNullException"><paramref name="processor"/> is <see langword="null" />.</exception>
        protected MessageWorkerBase(IMessageProcessor processor, string name)
        {
            if (processor == null)
                throw new ArgumentNullException("processor");

            if (name == null)
                throw new ArgumentNullException("name");

            _name = name;

            _processor = processor;
            _container = _processor.Container;
            _configuration = _container.Configuration;
            _repository = _container.Repository;

            _random = new Random();
            _pollTimer = new Timer(PollQueue);
        }
예제 #52
0
파일: Program.cs 프로젝트: Marceli/MSTest
        static void Main(string[] args)
        {
            int threadsCount;
            int messagesCount;
            //			if(args.Count()!=2 || !int.TryParse(args[0],out threadsCount)|| ! int.TryParse(args[1],out messagesCount))
            //			{
            //				Console.WriteLine("Please provide number of threads and number of messages");
            //				Console.WriteLine("Usage : messageprocessor.exe 64 256");
            //				return;
            //			}
            //			Console.WriteLine("It's O(T^2*M) (where T number of threads, M number of messages) algorithm so it can take some time to compute results for big T");

            threadsCount = 64;
            messagesCount = 256;
            //nice but doesn't handle no more than 63 threads how nice is that?
            //			messageProcessor = new MessageProcessorWithParallel(threadsCount, messagesCount);
            //            Start();
            //	messageProcessor = new MessageProcessorWithMsBlockingQueue(threadsCount, messagesCount);
             //   Start();
            messageProcessor = new MessageProcessorFastest(threadsCount, messagesCount);
            Start();
            Console.ReadKey();
        }
예제 #53
0
 public bool RemoveProcessor(IMessageProcessor processorToRemove)
 {
     throw new System.NotImplementedException();
 }
예제 #54
0
 public void AddProcessor(IMessageProcessor processor)
 {
     MessageProcessors.Add(processor);
 }
예제 #55
0
 private void ProcessMessages(IList<RoomMessage> messages, IMessageProcessor processor)
 {
     foreach (var message in messages)
     {
         if (processor.IsRegisteredMessageType(message.MessageType))
         {
             processor.ProcessMessage(message, new RepsonseClient(_roomId, _proxy));
         }
     }
 }
예제 #56
0
        private List<long> DoPersist(TreeWrite sequence, int tryCount)
        {
            // NOTE: nodes are written in order of branches and then leaf nodes. All
            //   branch nodes and leafs are grouped together.

            // The list of nodes to be allocated,
            IList<ITreeNode> allBranches = sequence.BranchNodes;
            IList<ITreeNode> allLeafs = sequence.LeafNodes;
            List<ITreeNode> nodes = new List<ITreeNode>(allBranches.Count + allLeafs.Count);
            nodes.AddRange(allBranches);
            nodes.AddRange(allLeafs);
            int sz = nodes.Count;
            // The list of allocated referenced for the nodes,
            DataAddress[] refs = new DataAddress[sz];
            long[] outRefs = new long[sz];

            MessageStream allocateMessage = new MessageStream(MessageType.Request);

            // Make a connection with the manager server,
            IMessageProcessor manager = connector.Connect(managerAddress, ServiceType.Manager);

            // Allocate the space first,
            for (int i = 0; i < sz; ++i) {
                ITreeNode node = nodes[i];
                RequestMessage request = new RequestMessage("allocateNode");
                // Is it a branch node?
                if (node is TreeBranch) {
                    // Branch nodes are 1K in size,
                    request.Arguments.Add(1024);
                } else {
                    // Leaf nodes are 4k in size,
                    request.Arguments.Add(4096);
                }

                allocateMessage.AddMessage(request);
            }

            // The result of the set of allocations,
            MessageStream resultStream = (MessageStream) manager.Process(allocateMessage);
            //DEBUG: ++network_comm_count;

            // The unique list of blocks,
            List<long> uniqueBlocks = new List<long>();

            // Parse the result stream one message at a time, the order will be the
            // order of the allocation messages,
            int n = 0;
            foreach (ResponseMessage m in resultStream) {
                if (m.HasError)
                    throw m.Error.AsException();

                DataAddress addr = (DataAddress) m.Arguments[0].Value;
                refs[n] = addr;
                // Make a list of unique block identifiers,
                if (!uniqueBlocks.Contains(addr.BlockId)) {
                    uniqueBlocks.Add(addr.BlockId);
                }
                ++n;
            }

            // Get the block to server map for each of the blocks,

            IDictionary<long, IList<BlockServerElement>> blockToServerMap = GetServersForBlock(uniqueBlocks);

            // Make message streams for each unique block
            int ubid_count = uniqueBlocks.Count;
            MessageStream[] ubidStream = new MessageStream[ubid_count];
            for (int i = 0; i < ubidStream.Length; ++i) {
                ubidStream[i] = new MessageStream(MessageType.Request);
            }

            // Scan all the blocks and create the message streams,
            for (int i = 0; i < sz; ++i) {
                byte[] nodeBuf;

                ITreeNode node = nodes[i];
                // Is it a branch node?
                if (node is TreeBranch) {
                    TreeBranch branch = (TreeBranch)node;
                    // Make a copy of the branch (NOTE; we Clone() the array here).
                    long[] curNodeData = (long[])branch.ChildPointers.Clone();
                    int curNdsz = branch.DataSize;
                    branch = new TreeBranch(refs[i].Value, curNodeData, curNdsz);

                    // The number of children
                    int chsz = branch.ChildCount;
                    // For each child, if it's a heap node, look up the child id and
                    // reference map in the sequence and set the reference accordingly,
                    for (int o = 0; o < chsz; ++o) {
                        long childRef = branch.GetChild(o);
                        if (childRef < 0) {
                            // The ref is currently on the heap, so adjust accordingly
                            int ref_id = sequence.LookupRef(i, o);
                            branch.SetChildOverride(o, refs[ref_id].Value);
                        }
                    }

                    // Turn the branch into a 'node_buf' byte[] array object for
                    // serialization.
                    long[] nodeData = branch.ChildPointers;
                    int ndsz = branch.DataSize;
                    MemoryStream bout = new MemoryStream(1024);
                    BinaryWriter dout = new BinaryWriter(bout, Encoding.Unicode);
                    dout.Write(BranchType);
                    dout.Write(ndsz);
                    for (int o = 0; o < ndsz; ++o) {
                        dout.Write(nodeData[o]);
                    }
                    dout.Flush();

                    // Turn it into a byte array,
                    nodeBuf = bout.ToArray();

                    // Put this branch into the local cache,
                    networkCache.SetNode(refs[i], branch);

                } else {
                    // If it's a leaf node,

                    TreeLeaf leaf = (TreeLeaf)node;
                    int lfsz = leaf.Length;

                    nodeBuf = new byte[lfsz + 6];
                    // Technically, we could comment these next two lines out.
                    ByteBuffer.WriteInt2(LeafType, nodeBuf, 0);
                    ByteBuffer.WriteInt4(lfsz, nodeBuf, 2);
                    leaf.Read(0, nodeBuf, 6, lfsz);

                    // Put this leaf into the local cache,
                    leaf = new ByteArrayTreeLeaf(refs[i].Value, nodeBuf);
                    networkCache.SetNode(refs[i], leaf);

                }

                // The DataAddress this node is being written to,
                DataAddress address = refs[i];
                // Get the block id,
                long blockId = address.BlockId;
                int bid = uniqueBlocks.IndexOf(blockId);
                RequestMessage request = new RequestMessage("writeToBlock");
                request.Arguments.Add(address);
                request.Arguments.Add(nodeBuf);
                request.Arguments.Add(0);
                request.Arguments.Add(nodeBuf.Length);
                ubidStream[bid].AddMessage(request);

                // Update 'outRefs' array,
                outRefs[i] = refs[i].Value;
            }

            // A log of successfully processed operations,
            List<object> successProcess = new List<object>(64);

            // Now process the streams on the servers,
            for (int i = 0; i < ubidStream.Length; ++i) {
                // The output message,
                MessageStream requestMessageStream = ubidStream[i];

                // Get the servers this message needs to be sent to,
                long block_id = uniqueBlocks[i];
                IList<BlockServerElement> blockServers = blockToServerMap[block_id];

                // Format a message for writing this node out,
                int bssz = blockServers.Count;
                IMessageProcessor[] blockServerProcs = new IMessageProcessor[bssz];

                // Make the block server connections,
                for (int o = 0; o < bssz; ++o) {
                    IServiceAddress address = blockServers[o].Address;
                    blockServerProcs[o] = connector.Connect(address, ServiceType.Block);
                    MessageStream responseMessageStream = (MessageStream) blockServerProcs[o].Process(requestMessageStream);
                    //DEBUG: ++network_comm_count;

                    if (responseMessageStream.HasError) {
                        // If this is an error, we need to report the failure to the
                        // manager server,
                        ReportBlockServerFailure(address);
                        // Remove the block id from the server list cache,
                        networkCache.RemoveServers(block_id);

                        // Rollback any server writes already successfully made,
                        for (int p = 0; p < successProcess.Count; p += 2) {
                            IServiceAddress blockAddress = (IServiceAddress) successProcess[p];
                            MessageStream toRollback = (MessageStream) successProcess[p + 1];

                            List<DataAddress> rollbackNodes = new List<DataAddress>(128);
                            foreach(Message rm in toRollback) {
                                DataAddress raddr = (DataAddress) rm.Arguments[0].Value;
                                rollbackNodes.Add(raddr);
                            }

                            // Create the rollback message,
                            RequestMessage rollbackRequest = new RequestMessage("rollbackNodes");
                            rollbackRequest.Arguments.Add(rollbackNodes.ToArray());

                            // Send it to the block server,
                            Message responseMessage = connector.Connect(blockAddress, ServiceType.Block).Process(rollbackRequest);
                            //DEBUG: ++network_comm_count;

                            // If rollback generated an error we throw the error now
                            // because this likely is a serious network error.
                            if (responseMessage.HasError)
                                throw new NetworkException("Rollback wrote failed: " + responseMessage.ErrorMessage);
                        }

                        // Retry,
                        if (tryCount > 0)
                            return DoPersist(sequence, tryCount - 1);

                        // Otherwise we fail the write
                        throw new NetworkException(responseMessageStream.ErrorMessage);
                    }

                    // If we succeeded without an error, add to the log
                    successProcess.Add(address);
                    successProcess.Add(requestMessageStream);

                }
            }

            // Return the references,
            return new List<long>(outRefs);
        }
예제 #57
0
        public void RunPersistentPipeConnection(string pipeName, IMessageProcessor messageProcessor)
        {
            _persistentPipeServerStream = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

            AsyncCallback ac = null;
            ac = o =>
            {
                NamedPipeServerStream server = (NamedPipeServerStream)o.AsyncState;
                server.EndWaitForConnection(o);

                while (true)
                {
                    if (!messageProcessor.ProcessMessages(server)) break;
                }

                server.Dispose();
                server = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
                server.BeginWaitForConnection(ac, server);
            };
            _persistentPipeServerStream.BeginWaitForConnection(ac, _persistentPipeServerStream);
        }
예제 #58
0
 public MessageSender(IEnvelopeSender envelopeSender, IMessageProcessor messageProcessor)
     : this(envelopeSender)
 {
     _messageProcessor = messageProcessor;
 }
예제 #59
0
 /// <summary>
 /// Invokes the <see cref="IMessageProcessor"/> for handle processing a message block.
 /// </summary>
 /// <param name="socket">The <see cref="IIPSocket"/> that the data came from.</param>
 /// <param name="processor">The <see cref="IMessageProcessor"/> to invoke.</param>
 /// <param name="reader">The <see cref="BitStream"/> containing the data to process.</param>
 protected virtual void InvokeProcessor(IIPSocket socket, IMessageProcessor processor, BitStream reader)
 {
     processor.Call(socket, reader);
 }
 public void Release(IMessageProcessor messageProcessor)
 {
 }