Beispiel #1
0
        public HostChannel(Uri address, string pipeName, Action <ConnectionConfigurator> configurator)
            : this(new ChannelAdapter(), address, pipeName)
        {
            _connections = new List <ChannelConnection>();

            _connections.Add(_output.Connect(configurator));
        }
Beispiel #2
0
        Inbox <T> GetInbox <T>()
        {
            return(_inboxCache.Retrieve(typeof(T), type =>
            {
                var inbox = new BufferedInbox <T>(_fiber, _scheduler);

                _adapter.Connect(x => x.AddChannel(inbox));

                return inbox;
            }) as Inbox <T>);
        }
Beispiel #3
0
        public HostChannel([NotNull] Uri address, [NotNull] string pipeName, [NotNull] Action <ConnectionConfigurator> configurator)
            : this(new ChannelAdapter(), address, pipeName)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException("configurator");
            }

            _connections = new List <ChannelConnection>();

            _connections.Add(_output.Connect(configurator));
        }
        public void OnFatal(Action <VoteBundle> action)
        {
            if (action == null)
            {
                return;
            }

            EventChannel.Connect(c => c.AddConsumerOf <VoteBundle>().UsingConsumer(vb =>
            {
                if (vb.Votes.Any(v => v.State == HealthState.Fatal))
                {
                    action(vb);
                }
            }).HandleOnFiber(_fiber));
        }
Beispiel #5
0
        void CreateCoordinatorChannel()
        {
            if (_channel != null)
            {
                return;
            }

            _channel           = new ChannelAdapter();
            _channelConnection = _channel.Connect(x =>
            {
                x.AddConsumerOf <ServiceEvent>()
                .UsingConsumer(OnServiceEvent)
                .HandleOnFiber(_fiber);

                x.AddConsumerOf <ServiceFault>()
                .UsingConsumer(OnServiceFault)
                .HandleOnFiber(_fiber);

                x.AddConsumerOf <ServiceStopped>()
                .UsingConsumer(OnServiceStopped)
                .HandleOnFiber(_fiber);

                x.AddConsumerOf <CreateShelfService>()
                .UsingConsumer(OnCreateShelfService)
                .HandleOnFiber(_fiber);

                x.AddConsumerOf <ServiceFolderChanged>()
                .UsingConsumer(OnServiceFolderChanged)
                .HandleOnFiber(_fiber);

                x.AddConsumerOf <Request <ServiceStatus> >()
                .UsingConsumer(Status)
                .HandleOnFiber(_fiber);
            });
        }
        void OnServiceFolderRemoved(ServiceFolderRemoved message)
        {
            _log.InfoFormat("[Topshelf] Folder Removed: {0}", message.ServiceName);

            if (_actorCache.Has(message.ServiceName))
            {
                var actor = _actorCache[message.ServiceName];

                _actorCache.Remove(message.ServiceName);
                _serviceCache.Remove(message.ServiceName);

                ChannelConnection connection = null;
                connection = _channel.Connect(x =>
                {
                    x.AddConsumerOf <ServiceStopped>()
                    .Where(m => m.ServiceName == message.ServiceName)
                    .UsingConsumer(_ =>
                    {
                        actor.Send(new UnloadService(message.ServiceName));
                    });

                    x.AddConsumerOf <ServiceUnloaded>()
                    .Where(m => m.ServiceName == message.ServiceName)
                    .UsingConsumer(_ =>
                    {
                        // actor.Exit(); why timeout?
                        connection.Dispose();
                    });
                });

                actor.Send(new StopService(message.ServiceName));
            }
        }
Beispiel #7
0
 public HostHost(UntypedChannel inputChannel, Uri address, string endpoint)
 {
     _input = inputChannel;
     _inputConnection = _input.Connect(x =>
         {
             x.ReceiveFromWcfChannel(address, endpoint)
                 .HandleOnCallingThread();
         });
 }
Beispiel #8
0
		public void Sending_a_message_to_a_channel()
		{
			_received = new Future<Simple>();

			_channel = new ChannelAdapter();
			_channel.Connect(x =>
				{
					x.AddConsumerOf<Simple>()
						.UsingConsumer(_received.Complete)
						.HandleOnCallingThread();
				});
		}
Beispiel #9
0
        public void Sending_a_message_to_a_channel()
        {
            _received = new Future <Simple>();

            _channel = new ChannelAdapter();
            _channel.Connect(x =>
            {
                x.AddConsumerOf <Simple>()
                .UsingConsumer(_received.Complete)
                .HandleOnCallingThread();
            });
        }
Beispiel #10
0
        /// <summary>
        /// <para>Start the receiving thread pool.</para>
        ///
        /// <para>This method implements a message-based receive loop;
        /// so instead of having a while-loop that receives non-stop, the event channel
        /// ensures that receives are enqueued whenever <see cref="ReceiveCompleted"/> is published
        /// in the event channel passed to this pool instance at construction time.</para>
        /// </summary>
        public void Start()
        {
            _eventConnection = _eventChannel.Connect(x =>
            {
                x.AddConsumerOf <ReceiveCompleted>()
                .UsingConsumer(Handle)
                .HandleOnCallingThread();

                x.AddConsumerOf <ConsumeCompleted>()
                .UsingConsumer(Handle)
                .HandleOnCallingThread();
            });

            _enabled = true;

            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting Consumer Pool for {0}", _bus.Endpoint.Address.Uri);
            }

            QueueReceiver();
        }
Beispiel #11
0
        void InitializePerformanceCounters()
        {
            try
            {
                string instanceName = string.Format("{0}_{1}{2}",
                                                    Endpoint.Address.Uri.Scheme, Endpoint.Address.Uri.Host, Endpoint.Address.Uri.AbsolutePath.Replace("/", "_"));

                _counters = new ServiceBusInstancePerformanceCounters(instanceName);

                _performanceCounterConnection = _eventChannel.Connect(x =>
                {
                    x.AddConsumerOf <MessageReceived>()
                    .UsingConsumer(message =>
                    {
                        _counters.ReceiveCount.Increment();
                        _counters.ReceiveRate.Increment();
                        _counters.ReceiveDuration.IncrementBy(
                            (long)message.ReceiveDuration.TotalMilliseconds);
                        _counters.ReceiveDurationBase.Increment();
                        _counters.ConsumerDuration.IncrementBy(
                            (long)message.ConsumeDuration.TotalMilliseconds);
                        _counters.ConsumerDurationBase.Increment();
                    });

                    x.AddConsumerOf <MessagePublished>()
                    .UsingConsumer(message =>
                    {
                        _counters.PublishCount.Increment();
                        _counters.PublishRate.Increment();
                        _counters.PublishDuration.IncrementBy((long)message.Duration.TotalMilliseconds);
                        _counters.PublishDurationBase.Increment();

                        _counters.SentCount.IncrementBy(message.ConsumerCount);
                        _counters.SendRate.IncrementBy(message.ConsumerCount);
                    });

                    x.AddConsumerOf <ThreadPoolEvent>()
                    .UsingConsumer(message =>
                    {
                        _counters.ReceiveThreadCount.Set(message.ReceiverCount);
                        _counters.ConsumerThreadCount.Set(message.ConsumerCount);
                    });
                });
            }
            catch (Exception ex)
            {
                _log.Warn(
                    "The performance counters could not be created, try running the program in the Administrator role. Just once.",
                    ex);
            }
        }
        public MessageTraceBusService(UntypedChannel eventChannel)
        {
            _eventChannel = eventChannel;
            _fiber        = new PoolFiber();
            _messages     = new Deque <IReceivedMessageTraceDetail>();
            _detailLimit  = 100;

            _connection = _eventChannel.Connect(x =>
            {
                x.AddConsumerOf <MessageReceived>()
                .UsingConsumer(Handle)
                .HandleOnFiber(_fiber);
            });
        }
Beispiel #13
0
        public ActorInbox(Fiber fiber, Scheduler scheduler)
        {
            _fiber     = fiber;
            _scheduler = scheduler;

            _adapter            = new ChannelAdapter();
            _internalConnection = _adapter.Connect(x =>
            {
                x.AddConsumerOf <Exit>()
                .UsingConsumer(HandleExit)
                .HandleOnFiber(_fiber);
                x.AddConsumerOf <Kill>()
                .UsingConsumer(HandleKill)
                .HandleOnCallingThread();
            });

            _inboxCache = new Cache <Type, object>();
        }
Beispiel #14
0
 public void Connect(Action <ConnectionConfigurator> configurator)
 {
     _connections.Add(_channel.Connect(configurator));
 }
Beispiel #15
0
 protected ServiceChannel(Action <ConnectionConfigurator> configurator)
 {
     _channel     = new ChannelAdapter();
     _connections = new List <ChannelConnection>();
     _connections.Add(_channel.Connect(configurator));
 }
Beispiel #16
0
 public ChannelConnection Subscribe(Action <ConnectionConfigurator> subscriberActions)
 {
     return(_events.Connect(subscriberActions));
 }