Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*-
  * See the file LICENSE for redistribution information.
  *
  * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
  *
  */
 
 package com.sleepycat.je.evictor;
 
Create an evictor for a shared cache. [#21330]
public class SharedEvictor extends Evictor {
    public SharedEvictor(EnvironmentImpl envImpl) {
        super(envImpl);
    }
    @Override
        return new SharedSelector();
    }

    
SharedEvictor, unlike PrivateEvictor, must maintain a cache map for each EnvironmentImpl, since each cache map is logically associated with a single DbTree instance.
    @Override
    DbCache createDbCache() {
        return new DbCache() {
            final Map<EnvironmentImplMap<DatabaseIdDatabaseImpl>> envMap =
                new HashMap<EnvironmentImplMap<DatabaseIdDatabaseImpl>>();
            int nOperations = 0;
            public DatabaseImpl getDb(EnvironmentImpl envImpl,
                                      DatabaseId dbId) {
                Map<DatabaseIdDatabaseImplmap = .get(envImpl);
                if (map == null) {
                    map = new HashMap<DatabaseIdDatabaseImpl>();
                    .put(envImplmap);
                }
                /*
                 * Clear DB cache after dbCacheClearCount operations, to
                 * prevent starving other threads that need exclusive access to
                 * the MapLN (for example, DbTree.deleteMapLN).  [#21015]
                 *
                 * Note that we clear the caches for all environments after
                 * dbCacheClearCount total operations, rather than after
                 * dbCacheClearCount operations for a single environment,
                 * because the total is a more accurate representation of
                 * elapsed time, during which other threads may be waiting for
                 * exclusive access to the MapLN.
                 */
                 += 1;
                if (( % ) == 0) {
                    releaseDbs();
                }
                return envImpl.getDbTree().getDb(dbId, -1, map);
            }
            public void releaseDbs() {
                for (Map.Entry<EnvironmentImplMap<DatabaseIdDatabaseImpl>>
                     entry : .entrySet()) {
                    final EnvironmentImpl envImpl = entry.getKey();
                    final Map<DatabaseIdDatabaseImplmap = entry.getValue();
                    envImpl.getDbTree().releaseDbs(map);
                    map.clear();
                }
            }
        };
    }
New to GrepCode? Check out our FAQ X