in src/main/java/com/amazonaws/services/sqs/AmazonSQSVirtualQueuesClient.java [155:190]
public CreateQueueResult createQueue(CreateQueueRequest request) {
String hostQueueUrl = request.getAttributes().get(Constants.VIRTUAL_QUEUE_HOST_QUEUE_ATTRIBUTE);
if (hostQueueUrl == null) {
return amazonSqsToBeExtended.createQueue(request);
}
Map<String, String> attributes = new HashMap<>(request.getAttributes());
attributes.remove(Constants.VIRTUAL_QUEUE_HOST_QUEUE_ATTRIBUTE);
Optional<Long> retentionPeriod = AmazonSQSIdleQueueDeletingClient.getRetentionPeriod(attributes);
if (!attributes.isEmpty()) {
throw new IllegalArgumentException("Virtual queues do not support setting these queue attributes independently of their host queues: "
+ attributes.keySet());
}
HostQueue host = hostQueues.computeIfAbsent(hostQueueUrl, HostQueue::new);
VirtualQueue virtualQueue = new VirtualQueue(host, request.getQueueName(), retentionPeriod);
// There is clearly a race condition here between checking the size and
// adding to the map, but that's fine since this is just a loose upper bound
// and it avoids synchronizing all calls on something like an AtomicInteger.
// The worse case scenario is that the map has X entries more than the maximum
// where X is the number of threads concurrently creating queues.
if (virtualQueues.size() > MAXIMUM_VIRTUAL_QUEUES_COUNT) {
throw new IllegalStateException("Cannot create virtual queue: the number of virtual queues would exceed the maximum of "
+ MAXIMUM_VIRTUAL_QUEUES_COUNT);
}
virtualQueues.put(virtualQueue.getID().getVirtualQueueName(), virtualQueue);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Total Virtual Queue Created is %s and Queue Name is %s", virtualQueues.size(), virtualQueue.getID().getVirtualQueueName()));
}
return new CreateQueueResult().withQueueUrl(virtualQueue.getID().getQueueUrl());
}