class TaskMailboxImpl implements TaskMailbox {

	@Override
	public @Nonnull Mail take(int priority) throws InterruptedException, IllegalStateException {
		checkIsMailboxThread();
		checkTakeStateConditions();
		Mail head = takeOrNull(batch, priority);
		if (head != null) {
			return head;
		}
		final ReentrantLock lock = this.lock;
		lock.lockInterruptibly();
		try {
			Mail headMail;
			while ((headMail = takeOrNull(queue, priority)) == null) {
				notEmpty.await();
			}
			hasNewMail = !queue.isEmpty();
			return headMail;
		} finally {
			lock.unlock();
		}
	}

	public  TaskMailboxImpl(@Nonnull final Thread taskMailboxThread);
	@VisibleForTesting public  TaskMailboxImpl();

}