Example usage for java.util Collections synchronizedMap

List of usage examples for java.util Collections synchronizedMap

Introduction

In this page you can find the example usage for java.util Collections synchronizedMap.

Prototype

public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m) 

Source Link

Document

Returns a synchronized (thread-safe) map backed by the specified map.

Usage

From source file:org.ops4j.pax.web.extender.war.internal.WebAppPublisher.java

/**
 * Creates a new web app publisher.
 */
WebAppPublisher() {
    m_webApps = Collections.synchronizedMap(new HashMap<WebApp, ReplaceableService<HttpService>>());
}

From source file:org.apache.xmlgraphics.image.loader.util.SoftMapCache.java

/**
 * Creates a new soft cache.//w  w  w .  j a va 2 s  .  co m
 * @param synched true if the Map containing the values should by synchronized
 */
public SoftMapCache(boolean synched) {
    this.map = new java.util.HashMap();
    if (synched) {
        this.map = Collections.synchronizedMap(this.map);
    }
}

From source file:org.jboss.dashboard.commons.events.Publisher.java

public Publisher() {
    subscribers = Collections.synchronizedMap(new HashMap());
}

From source file:org.springmodules.cache.interceptor.MetadataCacheAttributeSource.java

public MetadataCacheAttributeSource(MetadataFinder f) {
    Assert.notNull(f, "property 'finder' is required");
    attributeMap = Collections.synchronizedMap(new HashMap());
    finder = f;/*  www . java 2s  .co m*/
}

From source file:cc.kune.core.server.persist.CachedCollection.java

/**
 * Instantiates a new cached collection.
 * // w  w  w .ja  va 2  s  .  c  o m
 * @param size
 *          the size of the cache
 */
public CachedCollection(final int size) {
    cache = Collections.synchronizedMap(new LRUMap(size));
}

From source file:au.com.jwatmuff.genericdb.cache.CachingDatabase.java

private void clearQueryCaches() {
    findAllCache = Collections.synchronizedMap(new HashMap<QueryInfo, List>());
    findCache = Collections.synchronizedMap(new HashMap<QueryInfo, Object>());
}

From source file:gov.nih.nci.cacis.xds.client.TestXDSConfigImpl.java

/**
 * {@inheritDoc}/*from   w w w . jav  a 2s . c  o m*/
 */
@Override
@Bean
//@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)    
public DocumentHandler documentHandler() {
    final DocumentHandler<HashMap<String, String>, HashMap<String, String>> docH = new DocumentHandler<HashMap<String, String>, HashMap<String, String>>() {

        private final Map<String, String> contHash = Collections.synchronizedMap(new HashMap<String, String>());

        @Override
        public String handleDocument(HashMap<String, String> documentMetadata)
                throws ApplicationRuntimeException {
            final String docId = UUID.randomUUID().toString();
            contHash.put(docId, documentMetadata.get("content"));
            return docId;
        }

        @Override
        public void initialize(HashMap<String, String> setupInfo) throws ApplicationRuntimeException {
            // dummyImpl do not do anything                    
        }

        @Override
        public InputStream retrieveDocument(String docUniqueID) throws ApplicationRuntimeException {
            final String cont = contHash.get(docUniqueID);
            if (StringUtils.isEmpty(cont)) {
                return null;
            } else {
                return new ByteArrayInputStream(cont.getBytes());
            }

        }
    };
    return docH;
}

From source file:org.apache.torque.templates.platform.PlatformDefaultImpl.java

private void initialize() {
    schemaTypeToSqlTypeMap = Collections.synchronizedMap(new HashMap<SchemaType, SqlType>());
    for (SchemaType schemaType : SchemaType.values()) {
        setSchemaTypeToSqlTypeMapping(schemaType, new SqlType(schemaType.name()));
    }//  ww  w  .j av  a2s  .  c o m
    setSchemaTypeToSqlTypeMapping(SchemaType.BOOLEANCHAR, new SqlType("CHAR"));
    setSchemaTypeToSqlTypeMapping(SchemaType.BOOLEANINT, new SqlType("INTEGER"));
}

From source file:org.apache.oodt.cas.resource.jobrepo.XStreamJobRepository.java

public XStreamJobRepository(File workingDir, int maxHistory) {
    this.workingDir = workingDir;
    this.maxHistory = Math.max(maxHistory == -1 ? Integer.MAX_VALUE : maxHistory, 1);
    this.jobMap = Collections.synchronizedMap(new ConcurrentHashMap<String, String>());
    this.jobPrecedence = new Vector<String>();
}

From source file:org.ajax4jsf.util.ServicesUtils.java

/**
 * Get per-context instance for service.
 * @param name - name ( default classname ) for service.
 * @return current instance for this service.
 * @throws ClassNotFoundException//from w  ww .ja  v  a 2  s .  c om
 */
public static Object getServiceInstance(String name) {
    Map<ClassLoader, Object> contextInstances = (Map<ClassLoader, Object>) _instances.get(name);
    if (null == contextInstances) {
        contextInstances = Collections.synchronizedMap(new HashMap<ClassLoader, Object>());
        _instances.put(name, contextInstances);
    }
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    Object serviceInstance = contextInstances.get(loader);
    if (null == serviceInstance) {
        try {
            Class<?> serviceClass = loadServiceClass(loader, name);
            serviceInstance = serviceClass.newInstance();
        } catch (Exception e) {
            throw new FacesException("Error create instance for service " + name, e);
        }
        contextInstances.put(loader, serviceInstance);
    }
    return serviceInstance;
}