Modified the producer class to implement the Countable and
IteratorAggregate interfaces.
Added checks to make sure the consumer or producer hasn't been closed.