class ClearMailQueueTask implements Task {

    @Override
    public Result run() {
        try (ManageableMailQueue queue = factory.create(queueName)) {
            this.initialCount = Optional.of(getRemainingSize(queue));
            this.queue = Optional.of(queue);
            queue.clear();
            this.lastAdditionalInformation = details();
        } catch (MailQueue.MailQueueException | IOException e) {
            LOGGER.error("Clear MailQueue got an exception", e);
            return Result.PARTIAL;
        } finally {
            this.queue = Optional.empty();
        }

        return Result.COMPLETED;
    }

    public  ClearMailQueueTask(MailQueueName queueName, ClearMailQueueTask.MailQueueFactory factory);

}