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.taverna.activities.interaction.InteractionRecorder.java
private Map<String, Set<String>> getInteractionMap(final String runId) { Map<String, Set<String>> interactionMap = InteractionRecorder.runToInteractionMap.get(runId); if (interactionMap == null) { interactionMap = Collections .synchronizedMap(Collections.synchronizedMap(new HashMap<String, Set<String>>())); InteractionRecorder.runToInteractionMap.put(runId, interactionMap); }//from w w w.j ava 2 s .c o m return interactionMap; }
From source file:org.kiji.mapreduce.KeyValueStoreReaderFactory.java
/** * Creates a KeyValueStoreReaderFactory. * * @param conf the Configuration from which a set of KeyValueStore bindings should * be deserialized and initialized./* www . ja va 2 s . co m*/ * @throws IOException if there is an error deserializing or initializing a * KeyValueStore instance. */ public KeyValueStoreReaderFactory(Configuration conf) throws IOException { Map<String, KeyValueStore<?, ?>> keyValueStores = new HashMap<String, KeyValueStore<?, ?>>(); int numKvStores = conf.getInt(KeyValueStore.CONF_KEY_VALUE_STORE_COUNT, KeyValueStore.DEFAULT_KEY_VALUE_STORE_COUNT); for (int i = 0; i < numKvStores; i++) { KeyValueStoreConfiguration kvStoreConf = new KeyValueStoreConfiguration(conf, i); Class<? extends KeyValueStore> kvStoreClass = kvStoreConf .<KeyValueStore>getClass(KeyValueStore.CONF_CLASS, null, KeyValueStore.class); String kvStoreName = kvStoreConf.get(KeyValueStore.CONF_NAME, ""); if (null != kvStoreClass) { KeyValueStore<?, ?> kvStore = ReflectionUtils.newInstance(kvStoreClass, conf); if (null != kvStore) { kvStore.initFromConf(kvStoreConf); if (kvStoreName.isEmpty()) { LOG.warn("Deserialized KeyValueStore not bound to a name; ignoring."); continue; } keyValueStores.put(kvStoreName, kvStore); } } } mKeyValueStores = Collections.unmodifiableMap(keyValueStores); mStoreReaders = Collections.synchronizedMap(new HashMap<String, KeyValueStoreReader<?, ?>>()); }
From source file:org.alfresco.filesys.repo.rules.ScenarioTempDeleteShuffle.java
@Override public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) { /**/*from w ww . j a va2s. c om*/ * This scenario is triggered by a delete of a file matching * the pattern */ if (operation instanceof CreateFileOperation) { CreateFileOperation c = (CreateFileOperation) operation; // check whether file is below .TemporaryItems String path = c.getPath(); // if path contains .TemporaryItems Matcher d = tempDirPattern.matcher(path); if (d.matches()) { logger.debug("pattern matches temp dir folder so this is a new create in a temp dir"); Matcher m = pattern.matcher(c.getName()); if (m.matches()) { // and how to lock - since we are already have one lock on the scenarios/folder here // this is a potential deadlock and synchronization bottleneck Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState() .get(SCENARIO_KEY); if (createdTempFiles == null) { synchronized (ctx.getSessionState()) { logger.debug("created new temp file map and added it to the session state"); createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY); if (createdTempFiles == null) { createdTempFiles = Collections .synchronizedMap(new MaxSizeMap<String, String>(5, false)); ctx.getSessionState().put(SCENARIO_KEY, createdTempFiles); } } } createdTempFiles.put(c.getName(), c.getName()); // TODO - Return a different scenario instance here ??? // So it can time out and have anti-patterns etc? } } } if (operation instanceof MoveFileOperation) { MoveFileOperation mf = (MoveFileOperation) operation; // check whether file is below .TemporaryItems String path = mf.getFromPath(); // if path contains .TemporaryItems Matcher d = tempDirPattern.matcher(path); if (d.matches()) { logger.debug("pattern matches temp dir folder so this is a new create in a temp dir"); Matcher m = pattern.matcher(mf.getFrom()); if (m.matches()) { // and how to lock - since we are already have one lock on the scenarios/folder here // this is a potential deadlock and synchronization bottleneck Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState() .get(SCENARIO_KEY); if (createdTempFiles == null) { synchronized (ctx.getSessionState()) { logger.debug("created new temp file map and added it to the session state"); createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY); if (createdTempFiles == null) { createdTempFiles = Collections .synchronizedMap(new MaxSizeMap<String, String>(5, false)); ctx.getSessionState().put(SCENARIO_KEY, createdTempFiles); } } } createdTempFiles.remove(mf.getFrom()); // TODO - Return a different scenario instance here ??? // So it can time out and have anti-patterns etc? } } } if (operation instanceof DeleteFileOperation) { DeleteFileOperation c = (DeleteFileOperation) operation; Matcher m = pattern.matcher(c.getName()); if (m.matches()) { Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState() .get(SCENARIO_KEY); if (createdTempFiles != null) { if (createdTempFiles.containsKey(c.getName())) { if (logger.isDebugEnabled()) { logger.debug("New Scenario Temp Delete Shuffle Instance:" + c.getName()); } ScenarioTempDeleteShuffleInstance instance = new ScenarioTempDeleteShuffleInstance(); instance.setTimeout(timeout); instance.setRanking(ranking); return instance; } } } } // No not interested. return null; }
From source file:org.apache.solr.handler.admin.CoreAdminHandler.java
public CoreAdminHandler() { super();//from w w w . j av a 2s . c om // Unlike most request handlers, CoreContainer initialization // should happen in the constructor... this.coreContainer = null; HashMap<String, Map<String, TaskObject>> map = new HashMap<>(3, 1.0f); map.put(RUNNING, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>())); map.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>())); map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>())); requestStatusMap = Collections.unmodifiableMap(map); coreAdminHandlerApi = new CoreAdminHandlerApi(this); }
From source file:me.xiaopan.android.spear.download.HttpClientImageDownloader.java
public HttpClientImageDownloader() { this.urlLocks = Collections.synchronizedMap(new WeakHashMap<String, ReentrantLock>()); BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, DEFAULT_WAIT_TIMEOUT); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_ROUTE_CONNECTIONS)); ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_READ_TIMEOUT); HttpConnectionParams.setConnectionTimeout(httpParams, DEFAULT_CONNECT_TIMEOUT); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, DEFAULT_USER_AGENT); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams); httpClient.addRequestInterceptor(new GzipProcessRequestInterceptor()); httpClient.addResponseInterceptor(new GzipProcessResponseInterceptor()); }
From source file:eu.smartfp7.EdgeNode.SocialNetworkFeed.java
/** * @see Servlet#init(ServletConfig)/* w w w . j a v a 2 s.c o m*/ */ public void init(ServletConfig config) throws ServletException { try { super.init(config); } catch (ServletException e) { System.err.println("Can not initialize servlet"); return; } // Read couchdb properties from file and initialise the client for feeds Properties dbProps = new Properties(); try { dbProps.load(getServletContext().getResourceAsStream("/WEB-INF/couchdb.properties")); } catch (IOException e1) { System.err.println("Can not open couchdb properties file"); return; } server = dbProps.getProperty("server"); port = Integer.parseInt(dbProps.getProperty("port")); user = dbProps.getProperty("user"); pass = dbProps.getProperty("pass"); // Test for incorrect user/pass or CouchDB server offline try { feedsClient = new CouchDbClient("feeds", true, "http", server, port, user, pass); } catch (Exception e) { System.err.println( "Could not connect to CouchDB, check that the server is running and that the correct username/pass is set"); System.err.println("Current configuration: server=" + server + ", port=" + port + ", user= " + user + ", pass= " + pass); return; } socialSearchList = Collections.synchronizedMap(new HashMap<String, SocialTaskData>()); }
From source file:org.csml.tommo.sugar.analysis.OpenedFileCache.java
protected OpenedFileCache() { cache = Collections.synchronizedMap(new HashMap<CachedFile, File>()); initProperties(); }
From source file:org.wallerlab.yoink.adaptive.smooth.SCMPWeightFactors.java
private void getWeightForAllPartitioningConfiguration(Job<JAXBElement> job) { Map<JobParameter, Object> parameters = job.getParameters(); Map<Molecule, Integer> bufferMoleculeMap = job.getRegions().get(Region.Name.BUFFER).getMolecularMap(); List<Molecule> bufferMolecules = new ArrayList<Molecule>(bufferMoleculeMap.keySet()); List<Integer> bufferIndices = new ArrayList<Integer>(bufferMoleculeMap.values()); double s_qm_out = (double) parameters.get(JobParameter.DISTANCE_S_QM_OUT); double t_qm_out = (double) parameters.get(JobParameter.DISTANCE_T_QM_OUT); double s_qm_in = (double) parameters.get(JobParameter.DISTANCE_S_QM_IN); double t_qm_in = (double) parameters.get(JobParameter.DISTANCE_T_QM_IN); double s_mm_out = (double) parameters.get(JobParameter.DISTANCE_S_MM_OUT); double t_mm_out = (double) parameters.get(JobParameter.DISTANCE_T_MM_OUT); double s_mm_in = (double) parameters.get(JobParameter.DISTANCE_S_MM_IN); double t_mm_in = (double) parameters.get(JobParameter.DISTANCE_T_MM_IN); sigmaIndexMap = new HashMap<List<Integer>, Double>(); sigmaIndexMap = Collections.synchronizedMap(sigmaIndexMap); int qmNumber = (int) parameters.get(JobParameter.NUMBER_QM); int number_qmInBuffer = qmNumber - qmNumber * 2 / 3; Map<Region.Name, Region> regions = job.getRegions(); Coord centerCoord = regions.get(Region.Name.QM_CORE).getCenterOfMass(); calculateWeightForEachConfiguration(bufferMolecules, bufferIndices, s_qm_out, t_qm_out, s_qm_in, t_qm_in, s_mm_out, t_mm_out, s_mm_in, t_mm_in, number_qmInBuffer, centerCoord); }
From source file:org.broad.igv.util.HttpUtils.java
private HttpUtils() { org.broad.tribble.util.ParsingUtils.registerHelperClass(IGVUrlHelper.class); disableCertificateValidation();//from w w w . j av a 2 s . c om CookieHandler.setDefault(new IGVCookieManager()); Authenticator.setDefault(new IGVAuthenticator()); try { System.setProperty("java.net.useSystemProxies", "true"); } catch (Exception e) { log.info("Couldn't set useSystemProxies=true"); } byteRangeTestMap = Collections.synchronizedMap(new HashMap()); }
From source file:org.apache.torque.engine.database.model.Table.java
/** * Constructs a table object with a name * * @param name table name//from www . java2 s . c o m */ public Table(String name) { this.name = name; columnList = new ArrayList(); foreignKeys = new ArrayList(5); indices = new ArrayList(5); unices = new ArrayList(5); columnsByName = new Hashtable(); columnsByJavaName = new Hashtable(); options = Collections.synchronizedMap(new ListOrderedMap()); }