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

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

Introduction

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

Prototype

public ReferenceMap(int keyType, int valueType) 

Source Link

Document

Constructs a new ReferenceMap that will use the specified types of references.

Usage

From source file:com.google.gwt.dev.shell.designtime.WrappersCache.java

/**
 * Weakly caches a given JSO by unique id. A cached JSO can be looked up by unique id until it is garbage
 * collected.// w  w w  .j a  va2  s  .  c om
 * 
 * Instantiations: changed to long.
 * 
 * @param uniqueId
 *            a unique id associated with the JSO
 * @param jso
 *            the value to cache
 */
@SuppressWarnings("unchecked")
public static void putCachedJso(ClassLoader cl, long uniqueId, Object jso) {
    Map<Long, Object> cache = m_jsoCache.get(cl);
    if (cache == null) {
        cache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
        m_jsoCache.put(cl, cache);
    }
    cache.put(uniqueId, jso);
}

From source file:com.googlecode.actorom.impl.remote.RemoteActorProxy.java

public RemoteActorProxy(Address address, RemoteChannelConnector connector) {
    this.address = address;
    this.connector = connector;
    this.futures = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
    // Connect the connector to the remote server topology:
    this.connector.connect();
}

From source file:desmoj.core.simulator.Model.java

/**
 * Constructs a model, with the given name and parameters for report and
 * trace files./*from   www .jav  a  2  s .co  m*/
 * 
 * @param name
 *            java.lang.String : The name of this model
 * @param owner
 *            Model : The main model this model is associated to
 * @param showInTrace
 *            boolean : Flag for showing this model in trace-files. Set it
 *            to <code>true</code> if model should show up in trace,
 *            <code>false</code> if model should not be shown in trace.
 */
public Model(Model owner, String name, boolean showInReport, boolean showInTrace) {

    super(owner, name, showInReport, showInTrace); // create a reportable

    // init data structures
    _subModels = new ArrayList<Model>(); // create empty Vector for subModels
    _reportables = new ArrayList<Reportable>(); // create empty Vector for reportables

    if (owner != null) { // check if this is a submodel
        this.isMainModel = false;
        owner.registerSubModel(this);
        // register as submodel at owner model
    } else {
        this.isMainModel = true;
    }

    _paramManager = new ParameterManager(); // create ParameterManager

    _numberOfEntitiesCreated = 0L;

    _entityMap = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
}

From source file:com.google.gwt.dev.cfg.ModuleDefLoader.java

@SuppressWarnings("unchecked")
private static Map<String, ModuleDef> getModulesCache() {
    ClassLoader keyClassLoader = Thread.currentThread().getContextClassLoader();
    Map<String, ModuleDef> cache = loadedModulesCaches.get(keyClassLoader);
    if (cache == null) {
        cache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
        loadedModulesCaches.put(keyClassLoader, cache);
    }//from www . j a  v a2  s.c om
    return cache;
}

From source file:net.darkmist.clf.LogParser.java

@SuppressWarnings("unchecked")
private static <N, V> Map<N, V> newWeakCache() {
    return new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.WEAK);
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.java

public EngineServiceImpl() {
    jarsClassLoaderCache = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.SOFT);
    resourcesClassLoaderCache = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.SOFT);
    cacheableCompiledReports = new CacheableCompiledReports(this);
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.java

protected ClassLoader getJarsClassLoader(ClassLoader origClassLoader, List jarFiles) {
    boolean caching = true;
    for (Iterator it = jarFiles.iterator(); caching && it.hasNext();) {
        CacheObject cacheJarFile = (CacheObject) it.next();
        caching &= cacheJarFile.isCached();
    }//w  w  w.j a  v a 2 s  .c o  m

    ClassLoader classLoader;
    if (caching) {
        Map childrenClassLoaders;
        synchronized (jarsClassLoaderCache) {
            childrenClassLoaders = (Map) jarsClassLoaderCache.get(origClassLoader);
            if (childrenClassLoaders == null) {
                childrenClassLoaders = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
                jarsClassLoaderCache.put(origClassLoader, childrenClassLoaders);
            }
        }
        Object classLoaderKey = getJarFileNames(jarFiles);
        synchronized (childrenClassLoaders) {
            classLoader = (ClassLoader) childrenClassLoaders.get(classLoaderKey);
            if (classLoader == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Creating class loader for parent " + origClassLoader + " and jars "
                            + classLoaderKey);
                }
                classLoader = createJarsClassLoader(origClassLoader, jarFiles);
                childrenClassLoaders.put(classLoaderKey, classLoader);
            }
        }
    } else {
        classLoader = createJarsClassLoader(origClassLoader, jarFiles);
    }
    return classLoader;
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.java

protected ClassLoader getResourcesClassLoader(ClassLoader parent, Map resourceBundleKeys, boolean inMemoryUnit,
        RepositoryContext repositoryContext) {
    ClassLoader repositoryResourceClassLoader;
    if (inMemoryUnit) {
        repositoryResourceClassLoader = new RepositoryResourceClassLoader(parent, resourceBundleKeys, true,
                repositoryContext);//from w w  w  .  j  a v a2s  .  co m
    } else {
        Map childrenClassLoaders;
        synchronized (resourcesClassLoaderCache) {
            childrenClassLoaders = (Map) resourcesClassLoaderCache.get(parent);
            if (childrenClassLoaders == null) {
                childrenClassLoaders = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
                resourcesClassLoaderCache.put(parent, childrenClassLoaders);
            }
        }
        synchronized (childrenClassLoaders) {
            //put something from the repository context in the key?
            repositoryResourceClassLoader = (ClassLoader) childrenClassLoaders.get(resourceBundleKeys);
            if (repositoryResourceClassLoader == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Creating class loader for parent " + parent + " and resources "
                            + resourceBundleKeys);
                }
                repositoryResourceClassLoader = new RepositoryResourceClassLoader(parent, resourceBundleKeys,
                        false, repositoryContext);
                childrenClassLoaders.put(resourceBundleKeys, repositoryResourceClassLoader);
            }
        }
    }
    return repositoryResourceClassLoader;
}

From source file:org.apache.cayenne.access.DefaultObjectMapRetainStrategy.java

@SuppressWarnings("unchecked")
public Map<Object, Persistent> createObjectMap() {
    String strategy = runtimeProperties.get(Constants.SERVER_OBJECT_RETAIN_STRATEGY_PROPERTY);

    if (strategy == null || WEAK_RETAIN_STRATEGY.equals(strategy)) {
        return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
    } else if (SOFT_RETAIN_STRATEGY.equals(strategy)) {
        return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
    } else if (HARD_RETAIN_STRATEGY.equals(strategy)) {
        return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.HARD);
    } else {//from w ww.  j  a  va2 s  .co m
        throw new CayenneRuntimeException("Unsupported retain strategy %s", strategy);
    }
}

From source file:org.apache.cayenne.access.ObjectStore.java

/**
 * Factory method to create default Map for storing registered objects.
 * //  www .  ja v a2  s. com
 * @since 3.0
 * @return a map with hard referenced keys and weak referenced values.
 */
static Map<Object, Persistent> createObjectMap() {
    return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
}