All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gs.fw.common.mithra.cacheloader.DependentTupleKeyIndex Maven / Gradle / Ivy

There is a newer version: 18.1.0
Show newest version
/*
 Copyright 2016 Goldman Sachs.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */

package com.gs.fw.common.mithra.cacheloader;


import com.gs.collections.impl.list.mutable.FastList;
import com.gs.fw.common.mithra.cache.NonUniqueIdentityIndex;
import com.gs.fw.common.mithra.extractor.Extractor;
import com.gs.fw.common.mithra.util.DoUntilProcedure;

import java.util.List;

public final class DependentTupleKeyIndex extends DependentKeyIndex
{
    private NonUniqueIdentityIndex bestSingleKeyIndex = null;
    private List sampleForBestSingleKeyIndex = FastList.newList();
    private long size = 0L;

    public DependentTupleKeyIndex(CacheLoaderEngine cacheLoaderEngine, DependentLoadingTaskSpawner dependentObjectLoader, Extractor keyExtractors[])
    {
        super (cacheLoaderEngine, dependentObjectLoader, keyExtractors);
    }

    protected synchronized void addKeyHoldersToBeLoaded(List keyHolders)
    {
        if (this.bestSingleKeyIndex == null)
        {
            this.sampleForBestSingleKeyIndex.addAll(keyHolders);

            if (this.sampleForBestSingleKeyIndex.size() >= DependentLoadingTaskSpawner.TASK_SIZE)
            {
                this.bestSingleKeyIndex = this.createLeastMutatingIndex(this.sampleForBestSingleKeyIndex, this.getKeyExtractors());
                this.sampleForBestSingleKeyIndex = null;
            }
        }
        if (this.bestSingleKeyIndex != null)
        {
            for(int i=0;i= DependentLoadingTaskSpawner.TASK_SIZE)
                    {
                        resultListHolder[0] = list;
                        return true;
                    }
                    else
                    {
                        if (resultListHolder[0].size() < DependentLoadingTaskSpawner.TASK_SIZE)
                        {
                            resultListHolder[0].addAll (list);
                        }
                    }
                }
                else
                {
                    if (resultListHolder[0].size() < DependentLoadingTaskSpawner.TASK_SIZE)
                    {
                        resultListHolder[0].add (each);
                    }
                }
                return false;
            }
        });

        List list = resultListHolder[0];
        for (Object aList : list)
        {
            bestSingleKeyIndex.remove(aList);
        }
        return list;
    }
    private NonUniqueIdentityIndex createLeastMutatingIndex(final List sampleKeyHolders, final Extractor[] keyExtractors)
    {
        NonUniqueIdentityIndex[] indexes = new NonUniqueIdentityIndex[keyExtractors.length];
        for (int n = 0; n < keyExtractors.length; n++)
        {
            Extractor[] nsExtractor = {keyExtractors[n]};
            indexes[n] = new NonUniqueIdentityIndex(nsExtractor);
        }

        int sampleLimit = Math.min(sampleKeyHolders.size(), DependentLoadingTaskSpawner.TASK_SIZE);
        for (int i=0; i bestKeyIndex.getAverageReturnSize())
            {
                bestKeyIndex = indexes[n];
            }
        }

        for (int i=sampleLimit; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy