Adapters::createItemPool

Create Item Pool

@param string                $poolOffset
@param DataStructures\Config $poolConfig
322303
public function createItemPool($poolOffset, DataStructures\Config $poolConfig)
    {
        $adapterClassName = '\O2System\Cache\Adapters\\' . ucfirst($poolConfig->adapter) . '\ItemPool';

        if (class_exists($adapterClassName)) {
            $adapter = new $adapterClassName($poolConfig);

            if ($adapter instanceof AbstractAdapter) {
                if ($adapter->isSupported()) {
                    $this->register($adapter, $poolOffset);
                }
            }
        }
    }
1100141
private void createContextPool(Integer poolSize, String providerURL) throws NamingException {
        final String METHODNAME = "createContextPool";

        /*
         * Validate provider URL
         */
        if (providerURL == null) {
            providerURL = getPrimaryURL();
        }

        /*
         * Default the pool size if one was not provided.
         */
        if (poolSize == null) {
            poolSize = DEFAULT_INIT_POOL_SIZE;
        }

        /*
         * Enable the context pool
         */
        if (iContextPoolEnabled) {
            long currentTimeMillisec = System.currentTimeMillis();
            long currentTimeSeconds = roundToSeconds(currentTimeMillisec);

            // Don't purge the pool more than once per second
            // This prevents multiple threads from purging the pool
            if (currentTimeMillisec - iPoolCreateTimestampMillisec > 1000) {
                List<TimedDirContext> contexts = new Vector<TimedDirContext>(poolSize);
                Hashtable<String, Object> env = getEnvironment(URLTYPE_SEQUENCE, providerURL);

                String currentURL = null;
                try {
                    for (int i = 0; i < poolSize; i++) {
                        TimedDirContext ctx = createDirContext(env, currentTimeSeconds);
                        currentURL = getProviderURL(ctx);
                        if (!providerURL.equalsIgnoreCase(currentURL)) {
                            env = getEnvironment(URLTYPE_SEQUENCE, currentURL);
                            providerURL = currentURL;
                        }
                        contexts.add(ctx);
                        //iLiveContexts++;
                    }
                } catch (NamingException e) {
                    if (tc.isDebugEnabled()) {
                        Tr.debug(tc, METHODNAME + " Context Pool creation FAILED for " + Thread.currentThread() + ", iLiveContext=" + iLiveContexts, e);
                    }
                    if (tc.isDebugEnabled()) {
                        Tr.debug(tc, METHODNAME + " Cleanup contexts in temp pool: " + contexts.size());
                    }
                    for (int j = 0; j < contexts.size(); j++) {
                        try {
                            TimedDirContext ctx = contexts.get(j);
                            ctx.close();
                        } catch (Exception ee) {
                        }
                    }
                    throw e;
                }
                iLiveContexts += poolSize;

                // set active URL
                setActiveURL(providerURL);

                List<TimedDirContext> oldCtxs = iContexts;
                iContexts = contexts;
                iPoolCreateTimestampSeconds = currentTimeSeconds;
                iPoolCreateTimestampMillisec = currentTimeMillisec;
                closeContextPool(oldCtxs);

                if (tc.isDebugEnabled()) {
                    Tr.debug(tc, METHODNAME + " Active Provider URL: " + getActiveURL());
                    Tr.debug(tc, METHODNAME + " ContextPool: total=" + iLiveContexts + ", poolSize=" + iContexts.size(),
                             ", iPoolCreateTimestampSeconds=" + iPoolCreateTimestampSeconds);
                }
            } else if (tc.isDebugEnabled()) {
                Tr.debug(tc, METHODNAME + " Pool has already been purged within past second... skipping purge");
            }
        } else {
            setActiveURL(providerURL);
        }
    }
1149875
function setOffsetToNodeList(nodeList, leftToken, offset, baseToken) {
            for (const t of genCollectNodeList(nodeList, leftToken, null)) {
                setOffsetToToken(t, offset, baseToken)
            }
        }
1167889
protected final function poolSave(CacheItemInterface $item): bool
    {
        try {
            $stream = new Stream(
                $this->includePath . $this->getTarget($item->getKey()),
                Stream::MODE_W_MORE);
            $stream->write(serialize($item));
            $stream->detach();
            return true;
        } catch (InvalidArgumentException $e) {
            return false;
        }
    }
13223
protected function createAdapter(string $adapter, array $config): Adapter
    {
        if ($adapter === 'Local') {
            if (! isset($config['config']['path'])) {
                throw new RuntimeException('Filesystem local adapter must set `path`');
            }

            $config = [$config['config']['path']];
        }

        return Reflection::newInstance(
            'One\\FileSystem\\Adapters\\' . $adapter,
            $config
        );
    }
584900
function BroadcastItem(pool, msg) {
  if (!(this instanceof BroadcastItem))
    return new BroadcastItem(pool, msg);

  assert(!msg.mutable, 'Cannot broadcast mutable item.');

  const item = msg.toInv();

  this.pool = pool;
  this.hash = item.hash;
  this.type = item.type;
  this.msg = msg;
  this.jobs = [];
}
1012439
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
    {
        if (!isset($config['cache_key_generator'])) {
            $config['cache_key_generator'] = new HeaderCacheKeyGenerator(['Authorization', 'Cookie', 'Accept', 'Content-type']);
        }
        $this->cachePlugin = Plugin\CachePlugin::clientCache($cachePool, $this->streamFactory, $config);
        $this->httpClientModified = true;
    }
243326
public static function get(CacheItemPoolInterface $pool, array $config, array $tags)
    {
        if ($config['use_tagging']) {
            $pool = new FixedTaggingCachePool(TaggablePSR6PoolAdapter::makeTaggable($pool), $tags);
        }

        if (!empty($config['prefix'])) {
            $pool = new PrefixedCachePool($pool, $config['prefix']);
        }

        return new DoctrineCacheBridge($pool);
    }
458727
public static function get(CacheItemPoolInterface $pool, RouterInterface $router, array $config)
    {
        if ($config['use_tagging']) {
            $pool = TaggablePSR6PoolAdapter::makeTaggable($pool);
        }

        if (!empty($config['prefix'])) {
            $pool = new PrefixedCachePool($pool, $config['prefix']);
        }

        return new CachingRouter($pool, $router, $config);
    }
66963
public static PoolInfoStrings createPoolInfoStrings(PoolInfo poolInfo) {
    if (poolInfo == null) {
      return null;
    }

    return new PoolInfoStrings(poolInfo.getPoolGroupName(),
                               poolInfo.getPoolName());
  }
316377
private function applyPoolOptions(PoolInterface $pool, array $options)
    {
        if (isset($options['logger'])) {
            $pool->setLogger($options['logger']);
        }

        if (isset($options['item_class'])) {
            $pool->setItemClass($options['item_class']);
        }

        if (isset($options['namespace'])) {
            $pool->setNamespace($options['namespace']);
        }
    }
5812
public function offsetSet($offset, $data)
    {
        if ($this->items === null) {
            $this->fillItems();
        }

        return $this->items[$offset] = $data;
    }
30770
public function load($widgetOffset)
    {
        $widgetDirectory = modules()->top()->getRealPath() . 'Widgets' . DIRECTORY_SEPARATOR . studlycase($widgetOffset) . DIRECTORY_SEPARATOR;

        if (is_dir($widgetDirectory)) {
            $widget = new DataStructures\Module\Widget($widgetDirectory);
            $this->store(camelcase($widgetOffset), $widget);
        }

        return $this->exists($widgetOffset);
    }
832465
public static function makeTaggable(CacheItemPoolInterface $cachePool, CacheItemPoolInterface $tagStorePool = null)
    {
        if ($cachePool instanceof TaggableCacheItemPoolInterface && $tagStorePool === null) {
            return $cachePool;
        }

        return new self($cachePool, $tagStorePool);
    }
175393
protected final function poolGetItem(string $key): CacheItemInterface
    {
        try {
            $stream = new Stream(
                $this->includePath . $this->getTarget($key),
                Stream::MODE_C_MORE);
            $serialized = $stream->__toString();
            $stream->detach();
            if ($serialized) {
                $item = unserialize($serialized);
                if (is_object($item) && $item instanceof CacheItem) {
                    return $item;
                }
            }
            throw new InvalidArgumentException("Item must implement psr-6");
        } catch (InvalidArgumentException $e) {
            return $this->createItem($key);
        }
    }
812783
ClassPool createClassPool(final List<String> classpathElements) throws MojoExecutionException {
        final ClassPool classPool = new ClassPool(ClassPool.getDefault());
        for (final String classPathElement : classpathElements) {
            try {
                classPool.appendClassPath(classPathElement);
            } catch (final NotFoundException e) {
                throw new MojoExecutionException("Unable to add class path to pool: " + classPathElement, e);
            }
        }
        return classPool;
    }
753587
protected ItemImpl readItem(ItemData itemData, boolean pool) throws RepositoryException
   {
      return readItem(itemData, null, pool, true);
   }