示例#1
0
 public EventDispatcher( IGrandOutputDispatcherStrategy strategy, Action<TimeSpan> onIdle = null )
 {
     Debug.Assert( strategy != null );
     _queue = new ConcurrentQueue<EventItem>();
     _dispatchLock = new object();
     _strat = strategy;
     _onIdle = onIdle;
     _overloadLock = new object();
     _thread = new Thread( Run );
     _thread.IsBackground = true;
     _strat.Initialize( () => _nonBlockingCount, _thread, out _idleManager );
     _thread.Start();
 }
示例#2
0
 public EventDispatcher(IGrandOutputDispatcherStrategy strategy, Action <TimeSpan> onIdle = null)
 {
     Debug.Assert(strategy != null);
     _queue               = new ConcurrentQueue <EventItem>();
     _dispatchLock        = new object();
     _strat               = strategy;
     _onIdle              = onIdle;
     _overloadLock        = new object();
     _thread              = new Thread(Run);
     _thread.IsBackground = true;
     _strat.Initialize(() => _nonBlockingCount, _thread, out _idleManager);
     _thread.Start();
 }
示例#3
0
        public void Dispose()
        {
            Interlocked.MemoryBarrier();
            var strat = _strat;

            if (strat != null)
            {
                _strat = null;
                Interlocked.MemoryBarrier();
                DoAdd(new GrandOutputEventInfo(), null);
                GC.SuppressFinalize(this);
                _thread.Join();
            }
        }
示例#4
0
        /// <summary>
        /// Initializes a new <see cref="GrandOutput"/>. 
        /// </summary>
        /// <param name="dispatcherStrategy">Strategy to use to handle the throughput.</param>
        public GrandOutput( IGrandOutputDispatcherStrategy dispatcherStrategy = null )
        {
            _clients = new List<WeakReference<GrandOutputClient>>();
            _dispatcher = new EventDispatcher( dispatcherStrategy ?? new EventDispatcherBasicStrategy(), null );
            CommonSink = new GrandOutputCompositeSink();
            var factory = new ChannelFactory( this, _dispatcher );
            _channelHost = new ChannelHost( factory, OnConfigurationReady );
            _channelHost.ConfigurationClosing += OnConfigurationClosing;
            _bufferingChannel = new BufferingChannel( _dispatcher, factory.CommonSinkOnlyReceiver );
            _nextDeadClientGarbage = DateTime.UtcNow.AddMinutes( 5 );

            // TODO: Adapt this termination handling to dotnet.
            var h = new EventHandler( OnDomainTermination );
            AppDomain.CurrentDomain.DomainUnload += h;
            AppDomain.CurrentDomain.ProcessExit += h;
        }
示例#5
0
        /// <summary>
        /// Initializes a new <see cref="GrandOutput"/>.
        /// </summary>
        /// <param name="dispatcherStrategy">Strategy to use to handle the throughput.</param>
        public GrandOutput(IGrandOutputDispatcherStrategy dispatcherStrategy = null)
        {
            _clients    = new List <WeakReference <GrandOutputClient> >();
            _dispatcher = new EventDispatcher(dispatcherStrategy ?? new EventDispatcherBasicStrategy(), null);
            CommonSink  = new GrandOutputCompositeSink();
            var factory = new ChannelFactory(this, _dispatcher);

            _channelHost = new ChannelHost(factory, OnConfigurationReady);
            _channelHost.ConfigurationClosing += OnConfigurationClosing;
            _bufferingChannel      = new BufferingChannel(_dispatcher, factory.CommonSinkOnlyReceiver);
            _nextDeadClientGarbage = DateTime.UtcNow.AddMinutes(5);

            // TODO: Adapt this termination handling to dotnet.
            var h = new EventHandler(OnDomainTermination);

            AppDomain.CurrentDomain.DomainUnload += h;
            AppDomain.CurrentDomain.ProcessExit  += h;
        }
示例#6
0
 public void Dispose()
 {
     Interlocked.MemoryBarrier();
     var strat = _strat;
     if( strat != null )
     {
         _strat = null;
         Interlocked.MemoryBarrier();
         DoAdd( new GrandOutputEventInfo(), null );
         GC.SuppressFinalize( this );
         _thread.Join();
     }
 }