protected virtual void Dispose(bool disposing)
        {
            this.disposing = disposing;

            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    if (consumer != null)
                    {
                        Logger.Debug("Disposing " + consumer.Name);

                        consumer.Stop().Wait();
                        consumer.OnPartitionsAssigned -= Consumer_OnPartitionsAssigned;
                        consumer.OnPartitionsRevoked  -= Consumer_OnPartitionsRevoked;
                        consumer.OnEndReached         -= Consumer_OnEndReached;
                        consumer.Dispose();
                    }

                    consumer = null;
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called by <see cref="SwitchApp" /> at th very end of the application
        /// shut down process to give this class the chance to release any resources
        /// it holds.
        /// </summary>
        internal static void Shutdown()
        {
            if (eventBinding != null)
            {
                eventBinding.Dispose();
                eventBinding = null;
            }

            if (eventConsumer != null)
            {
                eventConsumer.Dispose();
                eventConsumer = null;
            }
        }
Beispiel #3
0
        public static void EventMainLoop()
        {
            EventConsumer ec = null;

            try
            {
                ec = new EventConsumer("CUSTOM", "sofia::register_attempt", 100);
                ec.bind("SHUTDOWN", String.Empty);
                ec.bind("HEARTBEAT", String.Empty);
                while (Running)
                {
                    var evt = ec.pop(0, 0);
                    if (evt == null)
                    {
                        continue;
                    }

                    var en = evt.InternalEvent.GetValueOfHeader("Event-Name");
                    if (en == "CUSTOM")
                    {
                        en = evt.InternalEvent.GetValueOfHeader("Event-SubClass");
                    }
                    switch (en)
                    {
                    case @"sofia::register_attempt":
                    {
                        var iev = evt.InternalEvent;
                        var ar  = iev.GetValueOfHeader("auth-result");        // get the value of the result to see if it's the case we want
                        var ip  = iev.GetValueOfHeader("network-ip");         // and the ip address the register came from

                        if (ar == "FORBIDDEN")
                        {
                            BanTracker.TrackFailure(ip);
                        }
                    }
                    break;

                    case "SHUTDOWN":
                        Log.WriteLine(LogLevel.Critical, "FTB: Processing Shutdown event");
                        Running = false;
                        break;

                    case "HEARTBEAT":
                        BanTracker.CleanUp();
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception exx)
            {
                Log.WriteLine(LogLevel.Critical, "FailToBan -- Exception in event loop {0}", exx.Message);
            }
            finally
            {
                if (ec != null)
                {
                    ec.Dispose();
                }
                _eventThread = null;
            }
        }
 public void Dispose()
 {
     _consumer.Dispose();
 }
 public void Disconnect()
 {
     _eventBus.Dispose();
 }