Purge the contents and hand them to the calling pool that
owns this threadlocal version.

@return Object[]
544665
protected Object[] purge() {
        Object[] data = new Object[getCurrentNumElements()];
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "LocalPool is purging " + data.length + " items.  firstEntry: " + firstEntry + " lastEntry: " + lastEntry + " poolSize: " + poolSize);
        }

        if (0 < data.length) {
            int out = 0;
            if (lastEntry >= firstEntry) {
                for (int i = firstEntry; i <= lastEntry; i++) {
                    data[out] = free[i];
                    free[i] = null;
                    out++;
                }
            } else {
                for (int i = firstEntry; i < poolSize; i++) {
                    data[out] = free[i];
                    free[i] = null;
                    out++;
                }
                for (int i = 0; i <= lastEntry; i++) {
                    data[out] = free[i];
                    free[i] = null;
                    out++;
                }
            }

            lastEntry = -1;
            firstEntry = -1;
        }

        return data;
    }
68734
private function cleanUp()
    {
        if ($this->quiet) {
            $errors = explode(PHP_EOL, ob_get_clean());
            $shown = [];

            foreach ($errors as $error) {
                if ($error && !in_array($error, $shown)) {
                    out($error, 'error');
                    $shown[] = $error;
                }
            }
        }

        if (file_exists($this->tmpPharPath)) {
            @unlink($this->tmpPharPath);
        }
        if (file_exists($this->tmpPubkeyPath)) {
            @unlink($this->tmpPharPath);
        }
    }
65010
public function convertAll()
    {
        $apiObjects = $this->apiObjects;
        if (empty($apiObjects)) {
            return [];
        }

        return $this->getLegacyKernel()->runCallback(
            static function () use ($apiObjects) {
                $convertedObjects = [];
                foreach ($apiObjects as $alias => $apiObject) {
                    if ($apiObject instanceof Content) {
                        $convertedObjects[$alias] = eZContentObject::fetch($apiObject->getVersionInfo()->getContentInfo()->id);
                    } elseif ($apiObject instanceof Location) {
                        $convertedObjects[$alias] = eZContentObjectTreeNode::fetch($apiObject->id);
                    } elseif ($apiObject instanceof VersionInfo) {
                        $convertedObjects[$alias] = eZContentObjectVersion::fetchVersion($apiObject->versionNo, $apiObject->getContentInfo()->id);
                    }
                }

                return $convertedObjects;
            },
            false,
            false
        );
    }
526859
public function rebuild(): array
    {
        $redirects = [];
        $this->flush();
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_redirect');
        $queryBuilder->getRestrictions()->removeAll()
            ->add(GeneralUtility::makeInstance(HiddenRestriction::class))
            ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
        $statement = $queryBuilder
            ->select('*')
            ->from('sys_redirect')
            ->execute();
        while ($row = $statement->fetch()) {
            $host = $row['source_host'] ?: '*';
            if ($row['is_regexp']) {
                $redirects[$host]['regexp'][$row['source_path']][$row['uid']] = $row;
            } elseif ($row['respect_query_parameters']) {
                $redirects[$host]['respect_query_parameters'][$row['source_path']][$row['uid']] = $row;
            } else {
                $redirects[$host]['flat'][rtrim($row['source_path'], '/') . '/'][$row['uid']] = $row;
            }
        }
        $this->cache->set('redirects', $redirects, ['redirects']);
        return $redirects;
    }
347237
protected function cleanupOldChunks()
    {
        if ($this->useChunks === false) {
            // We have no write access. Do nothing.
            return;
        }

        static $beenHere = false;

        // We only do this once.
        if ($beenHere === true) {
            return;
        }

        $beenHere = true;
        // Clean up leftover files.
        $chunkList = glob($this->chunkDir . '*.Krexx.tmp');
        if (empty($chunkList) === false) {
            $now = time();
            foreach ($chunkList as $file) {
                // We delete everything that is older than 15 minutes.
                if (($this->pool->fileService->filetime($file) + 900) < $now) {
                    $this->pool->fileService->deleteFile($file);
                }
            }
        }
    }
28102
private LocalThreadObjectPool getThreadLocalObjectPool() {
        if (threadPoolSize <= 0) {
            // no local thread pool needed.
            return null;
        }
        LocalThreadObjectPool localPool = null;
        if (threadLocals != null) {
            localPool = threadLocals.get();
            if (localPool == null) {
                localPool = new LocalThreadObjectPool(threadPoolSize, null, destroyer); // @PK36998C
                threadLocals.set(localPool);

                localPool.setCleanUpOld(cleanUpOld);
            }
        }

        return localPool;
    }
594386
public function getReplacements(): array
    {
        $replacements = [
            'blank' => '',
            'class' => $this->getClassName(),
            'message' => $this->getValue(),
        ];

        $traceReplacements = $this->getTraceReplacements();

        return array_merge($replacements, $traceReplacements);
    }
347704
public void purgePoolContents() throws ResourceException {
        if (tc.isEntryEnabled()) {
            Tr.entry(this, tc, "purgePoolContents", gConfigProps.cfName);
        }
        ArrayList<MCWrapper> destroyMCWrappeList = new ArrayList<MCWrapper>();
        synchronized (destroyMCWrapperListLock) {
            for (int j = 0; j < gConfigProps.getMaxFreePoolHashSize(); ++j) {
                synchronized (freePool[j].freeConnectionLockObject) {
                    /*
                     * If a connection gets away, by setting fatalErrorNotificationTime will
                     * guaranty when the connection is returned to the free pool, it will be
                     */
                    freePool[j].incrementFatalErrorValue(j);
                    /*
                     * Move as many connections as we can in the free pool to the destroy list
                     */
                    if (freePool[j].mcWrapperList.size() > 0) {
                        //freePool[j][i].removeCleanupAndDestroyAllFreeConnections();
                        int mcWrapperListIndex = freePool[j].mcWrapperList.size() - 1;
                        for (int k = mcWrapperListIndex; k >= 0; --k) {
                            MCWrapper mcw = (MCWrapper) freePool[j].mcWrapperList.remove(k);
                            if (!mcw.isMarkedForPurgeDestruction()) {
                                mcw.setPoolState(0);
                                mcw.markForPurgeDestruction();
                                destroyMCWrappeList.add(mcw);
                                --freePool[j].numberOfConnectionsAssignedToThisFreePool;
                            }
                        }
                    }
                } // end free lock
            } //end for j
        } //end syc for destroyMCWrapperListLock
        if (localConnection_ != null) {
            boolean purgeTLS = false;
            /*
             * We can purge connections in the connection pool if we are not in thread sensitive code.
             */
            updateToTLSPoolInProgress.set(true); // set to true for pausing pool.
            synchronized (updateToTLSPoolInProgressLockObject) {
                try {
                    sleep(20);
                } catch (InterruptedException e) {
                }
                if (activeTLSRequest.get() > 0) {
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                    }
                    if (activeTLSRequest.get() > 0) {
                        // We can not purge tls
                        if (tc.isDebugEnabled()) {
                            Tr.debug(this, tc, "To many active requests to search tls, active request value is " + activeRequest.get());
                        }
                    } else {
                        purgeTLS = true;
                    }
                } else {
                    purgeTLS = true;
                }
                if (purgeTLS) {
                    if (tc.isDebugEnabled()) {
                        Tr.debug(this, tc, "Searching tls for a connections to purge.");
                    }
                    Iterator<Entry<MCWrapper, ArrayList<MCWrapper>>> it = tlsArrayLists.entrySet().iterator();
                    while (it.hasNext()) {
                        Entry<MCWrapper, ArrayList<MCWrapper>> e = it.next();
                        MCWrapper mcw = e.getKey();
                        if (mcw.getPoolState() == MCWrapper.ConnectionState_freeTLSPool) {
                            ArrayList<MCWrapper> mh = e.getValue();
                            mh.remove(mcw);
                            tlsArrayLists.remove(mcw);
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                ((com.ibm.ejs.j2c.MCWrapper) mcw).setThreadID(((com.ibm.ejs.j2c.MCWrapper) mcw).getThreadID() + "-purge-removed");
                                Tr.debug(this, tc, "removed mcWrapper from thread local " + mcw);
                            }
                            if (!mcw.isMarkedForPurgeDestruction()) {
                                mcw.setPoolState(0);
                                mcw.markForPurgeDestruction();
                                destroyMCWrappeList.add(mcw);
                            }
                        }
                    }
                }
                updateToTLSPoolInProgress.set(false); // set to false for releasing pool.
                updateToTLSPoolInProgressLockObject.notifyAll();
            }
        }
        /*
         * we need to cleanup and destroy connections in the local destroy list.
         */
        for (int i = 0; i < destroyMCWrappeList.size(); ++i) {
            MCWrapper mcw = destroyMCWrappeList.get(i);
            freePool[0].cleanupAndDestroyMCWrapper(mcw);
            this.totalConnectionCount.decrementAndGet();
        }
        if (tc.isEntryEnabled()) {
            Tr.exit(this, tc, "purgePoolContents");
        }
    }
1156078
public function deleteRepository(): array
    {
        return $this->getApi()->request($this->getApi()
                                             ->sprintf('/repos/:owner/:repo', $this->getOwner(), $this->getRepo()),
            Request::METHOD_DELETE);
    }
317652
public function toQueryParts(): array
    {
        if (empty($this->startIndex) && empty($this->endIndex)) {
            return [];
        }

        // @todo PHP appears to leak memory in both json_decode() and unserialize() with large result sets. Our best
        // guess is that some amount of data causes PHP to allocate larger chunks, and perhaps that class of memory
        // isn't ever a candidate for garbage collection. In general, paging over result sets (like in
        // \Lullabot\Mpx\Tests\Functional\DataService\Media\MediaQueryTest) should use a constant amount of memory per
        // page. 250 comes from tests on macOS with PHP 7.2 - going to 300 results causes an obvious memory leak.
        if ($this->endIndex - $this->startIndex > 250) {
            @trigger_error('PHP may leak memory with large result pages. Consider reducing the number of results per page.', E_USER_DEPRECATED);
        }

        return ['range' => $this->startIndex.'-'.$this->endIndex];
    }
301285
public function removeOldIndices(): array
    {
        $aliasName = $this->searchClient->getIndexName(); // The alias name is the unprefixed index name

        $currentlyLiveIndices = $this->indexDriver->indexesByAlias($aliasName);

        $indexStatus = $this->systemDriver->status();
        $allIndices = array_keys($indexStatus['indices']);

        $indicesToBeRemoved = [];

        foreach ($allIndices as $indexName) {
            if (strpos($indexName, $aliasName . '-') !== 0) {
                // filter out all indices not starting with the alias-name, as they are unrelated to our application
                continue;
            }

            if (in_array($indexName, $currentlyLiveIndices, true)) {
                // skip the currently live index names from deletion
                continue;
            }

            $indicesToBeRemoved[] = $indexName;
        }

        array_map(function ($index) {
            $this->indexDriver->deleteIndex($index);
        }, $indicesToBeRemoved);

        return $indicesToBeRemoved;
    }
583240
protected function getSanitizedCalls()
    {
        $calls = $this->getCalls();

        foreach ($calls as $i => $call) {
            foreach ($call['arguments'] as $j => $argument) {
                if (is_a($argument, 'Closure')) {
                    $calls[$i]['arguments'][$j] = $this->buildSerializableClosure($argument);
                }
            }
        }

        return $calls;
    }
163573
public function handleExpiration() : array
    {
        $deleted   = [];
        $cacheKeys = $this->cache->keys();

        foreach ($cacheKeys as $key) {
            $fileMeta = $this->cache->get($key, true);

            if ( ! $this->isExpired($fileMeta)) {
                continue;
            }

            if ( ! $this->cache->delete($key)) {
                continue;
            }

            if (is_writable($fileMeta['file_path'])) {
                unlink($fileMeta['file_path']);
            }

            $deleted[] = $fileMeta;
        }

        return $deleted;
    }
193767
public function purge() {

		foreach(
			new \RecursiveIteratorIterator(
				new \RecursiveDirectoryIterator(
					$this->path,
					\FilesystemIterator::SKIP_DOTS
				),
				\RecursiveIteratorIterator::CHILD_FIRST) as $f) {

			if ($f->isDir()) {
				if(!@rmdir($f->getRealPath())) {
					throw new FilesystemFolderException(sprintf('Filesystem folder %s could not be deleted!', $f->getRealPath()));
				}

				self::unsetInstance($f->getRealPath());
			}
		    else {
		    	if(!@unlink($f->getRealPath())) {
		    		throw new FilesystemFolderException(sprintf('Filesystem file %s could not be deleted!', $f->getRealPath()));
		    	}

		    	FilesystemFile::unsetInstance($f->getRealPath());
			}
		}

	}
915203
public function queueForDeletion()
    {
        $pages = [];
        $includeThisPage = true;
        if ($this->getCollectionPath() == Config::get('concrete.paths.trash')) {
            // we're in the trash. we can't delete the trash. we're skipping over the trash node.
            $includeThisPage = false;
        }
        $pages = $this->populateRecursivePages($pages, ['cID' => $this->getCollectionID()], $this->getCollectionParentID(), 0, $includeThisPage);
        // now, since this is deletion, we want to order the pages by level, which
        // should get us no funny business if the queue dies.
        usort($pages, ['Page', 'queueForDeletionSort']);
        $q = Queue::get('delete_page');
        foreach ($pages as $page) {
            $q->send(serialize($page));
        }
    }
209569
public function actionClear()
    {
        $cachesInput = func_get_args();

        if (empty($cachesInput)) {
            throw new Exception('You should specify cache components names');
        }

        $caches = $this->findCaches($cachesInput);
        $cachesInfo = [];

        $foundCaches = array_keys($caches);
        $notFoundCaches = array_diff($cachesInput, array_keys($caches));

        if ($notFoundCaches) {
            $this->notifyNotFoundCaches($notFoundCaches);
        }

        if (!$foundCaches) {
            $this->notifyNoCachesFound();
            return ExitCode::OK;
        }

        if (!$this->confirmClear($foundCaches)) {
            return ExitCode::OK;
        }

        foreach ($caches as $name => $class) {
            $cachesInfo[] = [
                'name' => $name,
                'class' => $class,
                'is_flushed' => $this->canBeCleared($class) ? $this->app->get($name)->clear() : false,
            ];
        }

        $this->notifyCleared($cachesInfo);
    }
307814
public function collect() : array
    {
        $this->readEnv = [];

        $this
            ->fillTravisCi()
            ->fillCircleCi()
            ->fillAppVeyor()
            ->fillJenkins()
            ->fillScrutinizer();

        return $this->readEnv;
    }