public void dispose()

in commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java [1191:1280]


    public void dispose(final boolean fromRemote)
    {
         // If already disposed, return immediately
        if (!alive.compareAndSet(true, false))
        {
            return;
        }

        log.info("In DISPOSE, [{0}] fromRemote [{1}]",
                this.cacheAttr::getCacheName, () -> fromRemote);

        // Remove us from the cache managers list
        // This will call us back but exit immediately
        if (cacheManager != null)
        {
            cacheManager.freeCache(getCacheName(), fromRemote);
        }

        // Try to stop shrinker thread
        if (future != null)
        {
            future.cancel(true);
        }

        // Now, shut down the event queue
        if (elementEventQ != null)
        {
            elementEventQ.dispose();
            elementEventQ = null;
        }

        // Dispose of each auxiliary cache, Remote auxiliaries will be
        // skipped if 'fromRemote' is true.
        for (final ICache<K, V> aux : auxCaches)
        {
            try
            {
                // Skip this auxiliary if:
                // - The auxiliary is null
                // - The auxiliary is not alive
                // - The auxiliary is remote and the invocation was remote
                if (aux == null || aux.getStatus() != CacheStatus.ALIVE
                    || fromRemote && aux.getCacheType() == CacheType.REMOTE_CACHE)
                {
                    log.info("In DISPOSE, [{0}] SKIPPING auxiliary [{1}] fromRemote [{2}]",
                            this.cacheAttr::getCacheName,
                            () -> aux == null ? "null" : aux.getCacheName(),
                            () -> fromRemote);
                    continue;
                }

                log.info("In DISPOSE, [{0}] auxiliary [{1}]",
                        this.cacheAttr::getCacheName, aux::getCacheName);

                // IT USED TO BE THE CASE THAT (If the auxiliary is not a lateral, or the cache
                // attributes
                // have 'getUseLateral' set, all the elements currently in
                // memory are written to the lateral before disposing)
                // I changed this. It was excessive. Only the disk cache needs the items, since only
                // the disk cache is in a situation to not get items on a put.
                if (aux.getCacheType() == CacheType.DISK_CACHE)
                {
                    final int numToFree = memCache.getSize();
                    memCache.freeElements(numToFree);

                    log.info("In DISPOSE, [{0}] put {1} into auxiliary [{2}]",
                            this.cacheAttr::getCacheName, () -> numToFree,
                            aux::getCacheName);
                }

                // Dispose of the auxiliary
                aux.dispose();
            }
            catch (final IOException ex)
            {
                log.error("Failure disposing of aux.", ex);
            }
        }

        log.info("In DISPOSE, [{0}] disposing of memory cache.",
                this.cacheAttr::getCacheName);
        try
        {
            memCache.dispose();
        }
        catch (final IOException ex)
        {
            log.error("Failure disposing of memCache", ex);
        }
    }