Example usage for org.apache.commons.collections.map LRUMap LRUMap

List of usage examples for org.apache.commons.collections.map LRUMap LRUMap

Introduction

In this page you can find the example usage for org.apache.commons.collections.map LRUMap LRUMap.

Prototype

public LRUMap(Map map) 

Source Link

Document

Constructor copying elements from another map.

Usage

From source file:org.apache.accumulo.core.iterators.system.VisibilityFilter.java

public VisibilityFilter(SortedKeyValueIterator<Key, Value> iterator, Authorizations authorizations,
        byte[] defaultVisibility) {
    setSource(iterator);//  w  w  w .  ja  va  2 s. c  om
    this.ve = new VisibilityEvaluator(authorizations);
    this.authorizations = authorizations;
    this.defaultVisibility = new Text(defaultVisibility);
    this.cache = new LRUMap(1000);
    this.tmpVis = new Text();
}

From source file:org.apache.accumulo.core.iterators.user.TransformingIterator.java

@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options,
        IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    scanning = IteratorScope.scan.equals(env.getIteratorScope());
    if (scanning) {
        String auths = options.get(AUTH_OPT);
        if (auths != null && !auths.isEmpty()) {
            ve = new VisibilityEvaluator(new Authorizations(auths.getBytes(UTF_8)));
            visibleCache = new LRUMap(100);
        }// w  w w .  j av  a  2  s  .c o  m
    }

    if (options.containsKey(MAX_BUFFER_SIZE_OPT)) {
        maxBufferSize = AccumuloConfiguration.getMemoryInBytes(options.get(MAX_BUFFER_SIZE_OPT));
    } else {
        maxBufferSize = DEFAULT_MAX_BUFFER_SIZE;
    }

    parsedVisibilitiesCache = new LRUMap(100);
}

From source file:org.apache.accumulo.core.iterators.user.TransformingIterator.java

@Override
public SortedKeyValueIterator<Key, Value> deepCopy(IteratorEnvironment env) {
    TransformingIterator copy;//from   ww w . j a v a2  s.c o  m

    try {
        copy = getClass().newInstance();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    copy.setSource(getSource().deepCopy(env));

    copy.scanning = scanning;
    copy.keyPos = keyPos;
    copy.keys.addAll(keys);
    copy.seekRange = (seekRange == null) ? null : new Range(seekRange);
    copy.seekColumnFamilies = (seekColumnFamilies == null) ? null
            : new HashSet<ByteSequence>(seekColumnFamilies);
    copy.seekColumnFamiliesInclusive = seekColumnFamiliesInclusive;

    copy.ve = ve;
    if (visibleCache != null) {
        copy.visibleCache = new LRUMap(visibleCache.maxSize());
        copy.visibleCache.putAll(visibleCache);
    }

    if (parsedVisibilitiesCache != null) {
        copy.parsedVisibilitiesCache = new LRUMap(parsedVisibilitiesCache.maxSize());
        copy.parsedVisibilitiesCache.putAll(parsedVisibilitiesCache);
    }

    copy.maxBufferSize = maxBufferSize;

    return copy;
}

From source file:org.apache.accumulo.core.iterators.user.VisibilityFilter.java

@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options,
        IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    validateOptions(options);//from   ww  w  . j  av a 2s .co  m
    this.filterInvalid = Boolean.parseBoolean(options.get(FILTER_INVALID_ONLY));

    if (!filterInvalid) {
        String auths = options.get(AUTHS);
        Authorizations authObj = auths == null || auths.isEmpty() ? new Authorizations()
                : new Authorizations(auths.getBytes(UTF_8));
        this.ve = new VisibilityEvaluator(authObj);
        this.defaultVisibility = new Text();
    }
    this.cache = new LRUMap(1000);
    this.tmpVis = new Text();
}

From source file:org.apache.accumulo.server.util.RemoveEntriesForMissingFiles.java

private static int checkTable(ClientContext context, String table, Range range, boolean fix) throws Exception {

    @SuppressWarnings({ "rawtypes" })
    Map cache = new LRUMap(100000);
    Set<Path> processing = new HashSet<Path>();
    ExecutorService threadPool = Executors.newFixedThreadPool(16);

    System.out.printf("Scanning : %s %s\n", table, range);

    VolumeManager fs = VolumeManagerImpl.get();
    Connector connector = context.getConnector();
    Scanner metadata = connector.createScanner(table, Authorizations.EMPTY);
    metadata.setRange(range);//  www. ja v  a 2s  .  c  om
    metadata.fetchColumnFamily(DataFileColumnFamily.NAME);
    int count = 0;
    AtomicInteger missing = new AtomicInteger(0);
    AtomicReference<Exception> exceptionRef = new AtomicReference<Exception>(null);
    BatchWriter writer = null;

    if (fix)
        writer = connector.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());

    for (Entry<Key, Value> entry : metadata) {
        if (exceptionRef.get() != null)
            break;

        count++;
        Key key = entry.getKey();
        Path map = fs.getFullPath(key);

        synchronized (processing) {
            while (processing.size() >= 64 || processing.contains(map))
                processing.wait();

            if (cache.get(map) != null) {
                continue;
            }

            processing.add(map);
        }

        threadPool.submit(new CheckFileTask(cache, fs, missing, writer, key, map, processing, exceptionRef));
    }

    threadPool.shutdown();

    synchronized (processing) {
        while (processing.size() > 0)
            processing.wait();
    }

    if (exceptionRef.get() != null)
        throw new AccumuloException(exceptionRef.get());

    if (writer != null && missing.get() > 0)
        writer.close();

    System.out.printf("Scan finished, %d files of %d missing\n\n", missing.get(), count);

    return missing.get();
}

From source file:org.apache.cassandra.jmeter.AbstractCassandaTestElement.java

private BoundStatement getPreparedStatement(Session conn, boolean callable) {
    Map<String, PreparedStatement> preparedStatementMap = perConnCache.get(conn);
    if (null == preparedStatementMap) {
        @SuppressWarnings("unchecked") // LRUMap is not generic
        Map<String, PreparedStatement> lruMap = new LRUMap(MAX_OPEN_PREPARED_STATEMENTS) {
            private static final long serialVersionUID = 1L;

            @Override/* w w  w  .  ja  v  a2  s  .com*/
            protected boolean removeLRU(LinkEntry entry) {
                PreparedStatement preparedStatement = (PreparedStatement) entry.getValue();
                return true;
            }
        };

        // TODO - This is wrong, but is synchronized
        preparedStatementMap = Collections.<String, PreparedStatement>synchronizedMap(lruMap);
        // As a connection is held by only one thread, we cannot already have a 
        // preparedStatementMap put by another thread
        perConnCache.put(conn, preparedStatementMap);
    }
    PreparedStatement pstmt = preparedStatementMap.get(getQuery());
    if (null == pstmt) {
        pstmt = conn.prepare(getQuery());

        // PreparedStatementMap is associated to one connection so
        //  2 threads cannot use the same PreparedStatement map at the same time
        preparedStatementMap.put(getQuery(), pstmt);
    }

    return pstmt.bind();
}

From source file:org.apache.cayenne.access.jdbc.SQLTemplateResourceManager.java

public void initialize(RuntimeServices rs) throws Exception {
    super.rsvc = rs;
    this.templateCache = new LRUMap(100);
}

From source file:org.apache.cayenne.cache.MapQueryCache.java

@SuppressWarnings("unchecked")
protected synchronized Map<String, List<?>> createCache(String cacheName) {
    Map<String, List<?>> map = getCache(cacheName);
    if (map != null) {
        return map;
    }/*from w  ww  . ja v  a 2s. c  o  m*/
    map = new LRUMap(maxSize);
    cacheGroups.put(cacheName, map);
    return map;
}

From source file:org.apache.directory.server.core.authn.SimpleAuthenticator.java

/**
 * Creates a new instance.
 */
public SimpleAuthenticator() {
    super(AuthenticationLevel.SIMPLE);
    credentialCache = new LRUMap(DEFAULT_CACHE_SIZE);
}

From source file:org.apache.directory.server.core.authn.SimpleAuthenticator.java

/**
 * Creates a new instance./*from w  w w  .  j  a v a 2s.  co m*/
 * @see AbstractAuthenticator
 * 
 * @param baseDn The base Dn
 */
public SimpleAuthenticator(Dn baseDn) {
    super(AuthenticationLevel.SIMPLE, baseDn);
    credentialCache = new LRUMap(DEFAULT_CACHE_SIZE);
}