protected synchronized void startSweeper()

in src/main/java/com/amazonaws/services/sqs/AmazonSQSIdleQueueDeletingClient.java [126:156]


    protected synchronized void startSweeper(AmazonSQSRequester requester, AmazonSQSResponder responder,
                                             long period, TimeUnit unit,
                                             Consumer<Exception> exceptionHandler) {
        if (this.idleQueueSweeper != null) {
            throw new IllegalStateException("Idle queue sweeper is already started!");
        }

        // Create the DLQ first so the primary queue can reference it
        // Note that SSE doesn't have to be enabled on this queue since the messages
        // will already be encrypted in the primary queue, and dead-lettering doesn't affect that.
        // The messages will still be receivable from the DLQ regardless.
        Map<String, String> dlqAttributes = new HashMap<>();
        dlqAttributes.put(QueueAttributeName.MessageRetentionPeriod.name(), Long.toString(DLQ_MESSAGE_RETENTION_PERIOD));
        deadLetterQueueUrl = createOrUpdateQueue(queueNamePrefix + SWEEPING_QUEUE_DLQ_SUFFIX, dlqAttributes);
        String deadLetterQueueArn = super.getQueueAttributes(deadLetterQueueUrl,
                Collections.singletonList(QueueAttributeName.QueueArn.name()))
                        .getAttributes().get(QueueAttributeName.QueueArn.name());

        Map<String, String> queueAttributes = new HashMap<>();
        // Server-side encryption is important here because we're putting
        // queue URLs into this queue.
        queueAttributes.put(QueueAttributeName.KmsMasterKeyId.toString(), "alias/aws/sqs");
        queueAttributes.put(QueueAttributeName.RedrivePolicy.toString(),
                "{\"maxReceiveCount\":\"5\", \"deadLetterTargetArn\":\"" + deadLetterQueueArn + "\"}");
        // TODO-RS: Configure a tight MessageRetentionPeriod! Put explicit thought
        // into other configuration as well.
        String sweepingQueueUrl = createOrUpdateQueue(queueNamePrefix, queueAttributes);

        this.idleQueueSweeper = new IdleQueueSweeper(requester, responder, sweepingQueueUrl, queueNamePrefix,
                period, unit, exceptionHandler);
    }