def buffer_initialize(options={})
      if ! self.class.method_defined?(:flush)
        raise ArgumentError, "Any class including Stud::Buffer must define a flush() method."
      end

      @buffer_config = {
        :max_items => options[:max_items] || 50,
        :max_interval => options[:max_interval] || 5,
        :logger => options[:logger] || nil,
        :autoflush => options.fetch(:autoflush, true),
        :has_on_flush_error => self.class.method_defined?(:on_flush_error),
        :has_on_full_buffer_receive => self.class.method_defined?(:on_full_buffer_receive),
        :drop_messages_on_flush_error => options.fetch(:drop_messages_on_flush_error, false),
        :drop_messages_on_full_buffer => options.fetch(:drop_messages_on_full_buffer, false),
        :flush_at_exit => options.fetch(:flush_at_exit, false)
      }

      if @buffer_config[:flush_at_exit]
        at_exit { buffer_flush(final: true) }
      end

      reset_buffer
    end
def buffer_initialize(options={})
      if ! self.class.method_defined?(:flush)
        raise ArgumentError, "Any class including Stud::Buffer must define a flush() method."
      end

      @buffer_config = {
        :max_items => options[:max_items] || 50,
        :max_interval => options[:max_interval] || 5,
        :logger => options[:logger] || nil,
        :autoflush => options.fetch(:autoflush, true),
        :has_on_flush_error => self.class.method_defined?(:on_flush_error),
        :has_on_full_buffer_receive => self.class.method_defined?(:on_full_buffer_receive),
        :drop_messages_on_flush_error => options.fetch(:drop_messages_on_flush_error, false),
        :drop_messages_on_full_buffer => options.fetch(:drop_messages_on_full_buffer, false),
        :flush_at_exit => options.fetch(:flush_at_exit, false)
      }

      if @buffer_config[:flush_at_exit]
        at_exit { buffer_flush(final: true) }
      end

      reset_buffer
    end
Initialize the buffer.

 Call directly from your constructor if you wish to set some non-default
 options. Otherwise buffer_initialize will be called automatically during the
 first buffer_receive call.

 Options:
 * :max_items, Max number of items to buffer before flushing. Default 50.
 * :max_interval, Max number of seconds to wait between flushes. Default 5.
 * :logger, A logger to write log messages to. No default. Optional.
 * :autoflush, Whether to immediately flush all inbound messages. Default true.
 * :drop_messages_on_flush_error, Whether to drop messages when there is a flush error. Default false.
 * :drop_messages_on_full_buffer, Whether to drop messages when the buffer is full. Default false.

 @param [Hash] options