List of usage examples for java.util Collections synchronizedMap
public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m)
From source file:org.apache.hadoop.yarn.server.timeline.RollingLevelDBTimelineStore.java
@Override @SuppressWarnings("unchecked") protected void serviceInit(Configuration conf) throws Exception { Preconditions.checkArgument(conf.getLong(TIMELINE_SERVICE_TTL_MS, DEFAULT_TIMELINE_SERVICE_TTL_MS) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_TTL_MS); Preconditions.checkArgument(//w w w . j a v a 2 s . c o m conf.getLong(TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS, DEFAULT_TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS); Preconditions.checkArgument( conf.getLong(TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE) >= 0, "%s property value should be greater than or equal to zero", TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE); Preconditions.checkArgument( conf.getLong(TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE) > 0, " %s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE); Preconditions.checkArgument( conf.getLong(TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE); Preconditions.checkArgument( conf.getLong(TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES, DEFAULT_TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES); Preconditions.checkArgument( conf.getLong(TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE); Options options = new Options(); options.createIfMissing(true); options.cacheSize(conf.getLong(TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE)); JniDBFactory factory = new JniDBFactory(); Path dbPath = new Path(conf.get(TIMELINE_SERVICE_LEVELDB_PATH), FILENAME); Path domainDBPath = new Path(dbPath, DOMAIN); Path starttimeDBPath = new Path(dbPath, STARTTIME); Path ownerDBPath = new Path(dbPath, OWNER); try (FileSystem localFS = FileSystem.getLocal(conf)) { if (!localFS.exists(dbPath)) { if (!localFS.mkdirs(dbPath)) { throw new IOException("Couldn't create directory for leveldb " + "timeline store " + dbPath); } localFS.setPermission(dbPath, LEVELDB_DIR_UMASK); } if (!localFS.exists(domainDBPath)) { if (!localFS.mkdirs(domainDBPath)) { throw new IOException( "Couldn't create directory for leveldb " + "timeline store " + domainDBPath); } localFS.setPermission(domainDBPath, LEVELDB_DIR_UMASK); } if (!localFS.exists(starttimeDBPath)) { if (!localFS.mkdirs(starttimeDBPath)) { throw new IOException( "Couldn't create directory for leveldb " + "timeline store " + starttimeDBPath); } localFS.setPermission(starttimeDBPath, LEVELDB_DIR_UMASK); } if (!localFS.exists(ownerDBPath)) { if (!localFS.mkdirs(ownerDBPath)) { throw new IOException( "Couldn't create directory for leveldb " + "timeline store " + ownerDBPath); } localFS.setPermission(ownerDBPath, LEVELDB_DIR_UMASK); } } options.maxOpenFiles(conf.getInt(TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES, DEFAULT_TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES)); options.writeBufferSize(conf.getInt(TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE)); LOG.info("Using leveldb path " + dbPath); domaindb = factory.open(new File(domainDBPath.toString()), options); entitydb = new RollingLevelDB(ENTITY); entitydb.init(conf); indexdb = new RollingLevelDB(INDEX); indexdb.init(conf); starttimedb = factory.open(new File(starttimeDBPath.toString()), options); ownerdb = factory.open(new File(ownerDBPath.toString()), options); checkVersion(); startTimeWriteCache = Collections.synchronizedMap(new LRUMap(getStartTimeWriteCacheSize(conf))); startTimeReadCache = Collections.synchronizedMap(new LRUMap(getStartTimeReadCacheSize(conf))); writeBatchSize = conf.getInt(TIMELINE_SERVICE_LEVELDB_WRITE_BATCH_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_WRITE_BATCH_SIZE); super.serviceInit(conf); }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
private static Map<String, Bitmap> getICache() { if (invalidCache == null) { invalidCache = Collections.synchronizedMap(new BitmapCache(100, BIG_PIXELS, 250000)); }/*www . ja v a 2s . c om*/ return invalidCache; }
From source file:uk.ac.ucl.excites.sapelli.transmission.db.TransmissionStore.java
/** * @param client//from ww w.j a v a2s .c om * @throws DBException */ public TransmissionStore(TransmissionClient client) throws DBException { super(client); this.outCache = Collections.synchronizedMap(new LRUMap<Integer, Transmission<?>>(MAX_CACHE_SIZE)); this.inCache = Collections.synchronizedMap(new LRUMap<Integer, Transmission<?>>(MAX_CACHE_SIZE)); }
From source file:org.structr.core.app.StructrApp.java
private synchronized Long getNodeFromCache(final String uuid) { if (nodeUuidMap == null) { final int cacheSize = Services .parseInt(StructrApp.getConfigurationValue(Services.APPLICATION_UUID_CACHE_SIZE), 10000); nodeUuidMap = Collections.synchronizedMap(new LruMap<String, Long>(cacheSize)); }//ww w . ja v a 2s .co m return nodeUuidMap.get(uuid); }
From source file:org.apache.hadoop.hbase.crosssite.coprocessor.TestCrossSiteCoprocessor.java
private Map<byte[], SumResponse> sumInBatch(final CrossSiteHTable table, final String[] clusterNames, final byte[] family, final byte[] qualifier, final byte[] start, final byte[] end) throws ServiceException, Throwable { ColumnAggregationProtos.SumRequest.Builder builder = ColumnAggregationProtos.SumRequest.newBuilder(); builder.setFamily(HBaseZeroCopyByteString.wrap(family)); if (qualifier != null && qualifier.length > 0) { builder.setQualifier(HBaseZeroCopyByteString.wrap(qualifier)); }//w w w . j a va 2 s. c o m final Map<byte[], ColumnAggregationProtos.SumResponse> results = Collections .synchronizedMap(new TreeMap<byte[], ColumnAggregationProtos.SumResponse>(Bytes.BYTES_COMPARATOR)); table.batchCoprocessorService( ColumnAggregationProtos.ColumnAggregationService.getDescriptor().findMethodByName("sum"), builder.build(), start, end, clusterNames, ColumnAggregationProtos.SumResponse.getDefaultInstance(), new Callback<ColumnAggregationProtos.SumResponse>() { @Override public void update(byte[] region, byte[] row, ColumnAggregationProtos.SumResponse result) { if (region != null) { results.put(region, result); } } }); return results; }
From source file:org.structr.core.app.StructrApp.java
private synchronized Long getRelFromCache(final String uuid) { if (relUuidMap == null) { final int cacheSize = Services .parseInt(StructrApp.getConfigurationValue(Services.APPLICATION_UUID_CACHE_SIZE), 10000); relUuidMap = Collections.synchronizedMap(new LruMap<String, Long>(cacheSize)); }/* www. j a v a 2s.co m*/ return relUuidMap.get(uuid); }
From source file:com.silverpeas.classifieds.control.ClassifiedsSessionController.java
/** * create a map of fields corresponding to listName * @param listName : String// w w w . java 2 s. c o m * @return a Hashtable of <String, String> */ private Map<String, String> createListField(String listName) { Map<String, String> fields = Collections.synchronizedMap(new HashMap<String, String>()); if (StringUtil.isDefined(listName)) { // cration de la hashtable (key,value) try { PublicationTemplate pubTemplate = getPublicationTemplate(); GenericFieldTemplate field = (GenericFieldTemplate) pubTemplate.getRecordTemplate() .getFieldTemplate(listName); return field.getKeyValuePairs(getLanguage()); } catch (Exception e) { // ERREUR : le champ de recherche renseign n'est pas une liste droulante throw new ClassifiedsRuntimeException("ClassifedsSessionController.createListField()", SilverpeasRuntimeException.ERROR, "root.EX_CANT_GET_REMOTE_OBJECT", e); } } else { // ERREUR : le champs de recherche n'est pas renseign } return fields; }
From source file:org.apache.cocoon.components.modules.input.XMLFileModule.java
private Map getExpressionCache(Map cache, Object key) { synchronized (cache) { Map map = (Map) cache.get(key); if (map == null) { map = Collections.synchronizedMap(new HashMap()); cache.put(key, map);//from w w w. j a v a 2 s . c o m } return map; } }
From source file:net.sf.ehcache.store.DiskStore.java
/** * Remove all of the elements from the store. * <p/>// w ww . j a v a2 s. c o m * If there are registered <code>CacheEventListener</code>s they are notified of the expiry or removal * of the <code>Element</code> as each is removed. */ public final synchronized void removeAll() { if (persistent == false) { return; } try { checkActive(); // Ditch all the elements, and truncate the file spool = Collections.synchronizedMap(new HashMap()); diskElements = Collections.synchronizedMap(new HashMap()); freeSpace = Collections.synchronizedList(new ArrayList()); totalSize = 0; randomAccessFile.setLength(0); if (persistent) { indexFile.delete(); indexFile.createNewFile(); } } catch (Exception e) { // Clean up LOG.error(name + " Cache: Could not rebuild disk store. Initial cause was " + e.getMessage(), e); dispose(); } }
From source file:org.silverpeas.components.classifieds.control.ClassifiedsSessionController.java
/** * create a map of fields corresponding to listName * @param listName : String//from ww w . java2s . co m * @return a Hashtable of <String, String> */ private Map<String, String> createListField(String listName) { Map<String, String> fields = Collections.synchronizedMap(new HashMap<>()); if (StringUtil.isDefined(listName)) { // cration de la hashtable (key,value) try { PublicationTemplate pubTemplate = getPublicationTemplate(); if (pubTemplate != null) { GenericFieldTemplate field = (GenericFieldTemplate) pubTemplate.getRecordTemplate() .getFieldTemplate(listName); return field.getKeyValuePairs(getLanguage()); } } catch (Exception e) { // ERREUR : le champ de recherche renseign n'est pas une liste droulante throw new SilverpeasRuntimeException("Field is not a list", e); } } else { // ERREUR : le champs de recherche n'est pas renseign } return fields; }