{@inheritDoc}

@throws QueueException.EphemeralIsFull
if the ephemeral storage is full
497678
@Override
    public IQueueMessage<ID, DATA> take() throws QueueException.EphemeralIsFull {
        if (!isEphemeralDisabled()) {
            int ephemeralMaxSize = getEphemeralMaxSize();
            if (ephemeralMaxSize > 0 && ephemeralSize() >= ephemeralMaxSize) {
                throw new QueueException.EphemeralIsFull(ephemeralMaxSize);
            }
        }
        try (Jedis jedis = getJedisConnector().getJedis()) {
            long now = System.currentTimeMillis();
            Object response = jedis.eval(getScriptTake(), 0, String.valueOf(now));
            if (response == null) {
                return null;
            }
            return deserialize(response instanceof byte[] ? (byte[]) response
                    : response.toString().getBytes(QueueUtils.UTF8));
        }
    }
1144732
@Override
  protected void reserveInternal(int newCapacity) {
    int oldCapacity = (nulls == 0L) ? 0 : capacity;
    if (isArray() || type instanceof MapType) {
      this.lengthData =
          Platform.reallocateMemory(lengthData, oldCapacity * 4L, newCapacity * 4L);
      this.offsetData =
          Platform.reallocateMemory(offsetData, oldCapacity * 4L, newCapacity * 4L);
    } else if (type instanceof ByteType || type instanceof BooleanType) {
      this.data = Platform.reallocateMemory(data, oldCapacity, newCapacity);
    } else if (type instanceof ShortType) {
      this.data = Platform.reallocateMemory(data, oldCapacity * 2L, newCapacity * 2L);
    } else if (type instanceof IntegerType || type instanceof FloatType ||
        type instanceof DateType || DecimalType.is32BitDecimalType(type)) {
      this.data = Platform.reallocateMemory(data, oldCapacity * 4L, newCapacity * 4L);
    } else if (type instanceof LongType || type instanceof DoubleType ||
        DecimalType.is64BitDecimalType(type) || type instanceof TimestampType) {
      this.data = Platform.reallocateMemory(data, oldCapacity * 8L, newCapacity * 8L);
    } else if (childColumns != null) {
      // Nothing to store.
    } else {
      throw new RuntimeException("Unhandled " + type);
    }
    this.nulls = Platform.reallocateMemory(nulls, oldCapacity, newCapacity);
    Platform.setMemory(nulls + oldCapacity, (byte)0, newCapacity - oldCapacity);
    capacity = newCapacity;
  }
541574
@Override
    protected void loadMorselQueueFromSource(Queue<StorageStatsMorsel> morselQueue) {
        // generate set of morsels based on duplication policy
        try {
            for (String account : getAccountsList()) {
                String accountPath = "/" + account;

                log.debug("loading {}", account);

                if (exclusionManager.isExcluded(accountPath)) {
                    continue;
                }

                AccountCredentials accountCreds = getCredentialsRepo().getAccountCredentials(account);
                for (StorageProviderCredentials cred : accountCreds.getProviderCredentials()) {
                    String storePath = accountPath + "/" + cred.getProviderId();
                    if (exclusionManager.isExcluded(storePath)) {
                        continue;
                    }

                    StorageProvider store = getStorageProvider(cred);

                    Iterator<String> spaces = store.getSpaces();
                    while (spaces.hasNext()) {
                        String spaceId = spaces.next();
                        String spacePath = storePath + "/" + spaceId;
                        if (!exclusionManager.isExcluded(spacePath)) {
                            morselQueue.add(new StorageStatsMorsel(account,
                                                                   cred.getProviderId(),
                                                                   cred.getProviderType().name(),
                                                                   spaceId));
                        }
                    }

                    log.info("loaded {} into morsel queue.", account);

                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new DuraCloudRuntimeException(e);
        }
    }
133819
function Queue(parameters) {
    parameters = parameters || new composites.Parameters(new Catalog());
    if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Queue/v1');
    abstractions.Collection.call(this, utilities.types.QUEUE, parameters);

    // the capacity and array are private attributes so methods that use it are
    // defined in the constructor
    var capacity = 1024;  // default capacity
    if (parameters) {
        const value = parameters.getParameter('$capacity', 2);
        if (value) capacity = value.toNumber();
    }
    const array = [];

    this.acceptVisitor = function(visitor) {
        visitor.visitQueue(this);
    };

    this.toArray = function() {
        return array.slice();  // copy the array
    };

    this.getSize = function() {
        return array.length;
    };

    this.addItem = function(item) {
        if (array.length < capacity) {
            item = this.convert(item);
            array.push(item);
            return true;
        }
        throw new utilities.Exception({
            $module: '/bali/collections/Queue',
            $procedure: '$addItem',
            $exception: '$resourceLimit',
            $capacity: capacity,
            $text: '"The queue has reached its maximum capacity."'
        });
    };

    this.removeItem = function() {
        if (array.length > 0) return array.splice(0, 1)[0];  // remove the first item in the array
    };

    this.getHead = function() {
        return array[0];
    };

    this.deleteAll = function() {
        array.splice(0);
    };

    return this;
}
177887
@Override
    public IQueueMessage<ID, DATA> take() throws QueueException.EphemeralIsFull {
        try {
            GetResponse msg = getConsumerChannel().basicGet(queueName, true);
            return msg != null ? deserialize(msg.getBody()) : null;
        } catch (Exception e) {
            throw e instanceof QueueException ? (QueueException) e : new QueueException(e);
        }
    }
743688
@Override
    public Queue getQueue() throws JMSException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "getQueue");
        Queue q = (Queue) theDestination;
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "getQueue", q);
        return q;
    }
769504
@Override
    public final boolean retainAll(Collection<?> c) {
        this.writeLock.lock();
        try {
            int newSize = 0;
            for (final Queue<T> queue : this.keyedQueues.values()) {
                queue.retainAll(c);
                newSize += queue.size();
            }

            // Update the queue size
            final int oldSize = this.size;
            this.size = newSize;

            // If the updated size and old size differ things changed
            return this.size != oldSize;
        } finally {
            this.writeLock.unlock();
        }
    }
969091
@Trivial
    public synchronized boolean isFull() {
        // final String methodName = "isFull()";
        boolean isFull = false;
        int size = this.explicitBuffer.size() + this.scanBuffer.size() + this.garbageCollectorBuffer.size();
        if (size > this.maxInvalidationBufferSize || (System.currentTimeMillis() - this.lastRemoveTime) >= this.maxInvalidationBufferLife) {
            isFull = true;
            setlastRemoveTime();
        }
        // if (isFull) {
        // traceDebug(methodName, "cacheName=" + this.cod.cacheName + " isFull=" + isFull + " explicitBuffer=" +
        // explicitBuffer.size() + " scanBuffer=" + this.scanBuffer.size());
        // }
        return isFull;
    }
925663
public synchronized void enqueue(final byte[] array) throws IOException {
		assert array != null;
		byteDiskQueue.enqueueInt(array.length);
		byteDiskQueue.enqueue(array);
		size++;
	}
147634
protected function getQueue()
        {
            if (null === $this->queue) {
                $this->queue = new $this->queueClass();

                if (!$this->queue instanceof SplPriorityQueue) {
                    throw new Exception(sprintf(
                        'Queue expects an internal queue of type SplPriorityQueue; received "%s"',
                        get_class($this->queue)
                    ));
                }
            }

            return $this->queue;
        }
918193
private void checkStorageState(StorageException e) {
        if (e.getCause() instanceof AmazonS3Exception) {
            String errorCode =
                ((AmazonS3Exception) e.getCause()).getErrorCode();
            if (INVALID_OBJECT_STATE.equals(errorCode)) {
                String message = "The storage state of this content item " +
                                 "does not allow for this action to be taken. To resolve " +
                                 "this issue: 1. Request that this content item be " +
                                 "retrieved from offline storage 2. Wait (retrieval may " +
                                 "take up to 5 hours) 3. Retry this request";
                throw new StorageStateException(message, e);
            }
        }
    }
794057
@Override
  public Page allocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner) {
      while (true) {
          processQueue();
          long now = max.get();
          if (now < size) {
            return null;
          } else if (max.compareAndSet(now, now - size)) {
            ByteBuffer buffer;
            try {
              buffer = ByteBuffer.allocateDirect(size);
            } catch (OutOfMemoryError e) {
              return null;
            }
            bufferSizes.put(new PhantomReference<>(buffer, allocatedBuffers), size);
            return new Page(buffer, owner);
          }
      }
  }
967949
protected function queueAllForDeletion()
    {
        // If no file is currently stored, don't delete anything.
        if ( ! $this->originalFilename()) {
            return;
        }

        $this->deleteTarget    = $this->makeTargetInstanceWithCurrentData();
        $this->queuedForDelete = array_unique(array_merge($this->queuedForDelete, $this->variants(true)));
    }
803991
private void internalSchedule(CapacityRequest cr)
   {
      if (this.threadStarted.compareAndSet(false, true))         
      {
         this.fillerThread.start();
      }
      
      // Multiple instances of the same ManagedConnectionPool is allowed
      synchronized (crs)
      {
         crs.addLast(cr);
         crs.notifyAll();
      }
   }
838399
protected function queueAllForDeletion()
    {
        if (empty($this->getAttribute('filename'))) {
            return;
        }

        // Remove old files
        if ($this->config('preserve_files', false) === false) {
            foreach ($this->styles as $name => $style) {
                $this->setQueue('deletion', $this->path($name));
            }
        }

        // Set model attributes
        $this->instanceWrite('file_name', null);
        $this->instanceWrite('file_size', null);
        $this->instanceWrite('content_type', null);
        $this->instanceWrite('updated_at', null);
        $this->instanceWrite('queue_state', self::QUEUE_DONE);
        $this->instanceWrite('queued_file', null);
    }
311091
@Override
    protected void initQueue(T queue, QueueSpec spec) throws Exception {
        queue.setJdbcHelper(defaultJdbcHelper).setDataSource(defaultDataSource);

        queue.setEphemeralDisabled(getDefaultEphemeralDisabled())
                .setEphemeralMaxSize(getDefaultEphemeralMaxSize());
        Boolean ephemeralDisabled = spec.getField(QueueSpec.FIELD_EPHEMERAL_DISABLED,
                Boolean.class);
        if (ephemeralDisabled != null) {
            queue.setEphemeralDisabled(ephemeralDisabled.booleanValue());
        }
        Integer maxEphemeralSize = spec.getField(QueueSpec.FIELD_EPHEMERAL_MAX_SIZE, Integer.class);
        if (maxEphemeralSize != null) {
            queue.setEphemeralMaxSize(maxEphemeralSize.intValue());
        }

        queue.setTableName(defaultTableName).setTableNameEphemeral(defaultTableNameEphemeral)
                .setMaxRetries(defaultMaxRetries)
                .setTransactionIsolationLevel(defaultTransactionIsolationLevel);
        String tableName = spec.getField(SPEC_FIELD_TABLE_NAME);
        if (!StringUtils.isBlank(tableName)) {
            queue.setTableName(tableName);
        }
        String tableNameEphemeral = spec.getField(SPEC_FIELD_TABLE_NAME_EPHEMERAL);
        if (!StringUtils.isBlank(tableNameEphemeral)) {
            queue.setTableNameEphemeral(tableNameEphemeral);
        }
        Integer maxRetries = spec.getField(SPEC_FIELD_MAX_RETRIES, Integer.class);
        if (maxRetries != null) {
            queue.setMaxRetries(maxRetries.intValue());
        }
        Integer txIsolationLevel = spec.getField(SPEC_FIELD_TRANSACTION_ISOLATION_LEVEL,
                Integer.class);
        if (txIsolationLevel != null) {
            queue.setTransactionIsolationLevel(txIsolationLevel.intValue());
        }

        super.initQueue(queue, spec);
    }
1259503
@Override
	public int remainingCapacity() {
		if (sizeLimit > 0){
			int remaining = sizeLimit - size();
			return remaining < 0 ? 0 : remaining;
		}else{
			return queue.remainingCapacity();
		}
	}