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.codehaus.cargo.website.WebsiteGenerator.java
private static void download() throws Exception { long start = System.currentTimeMillis(); File attachmentsDirectory = new File("target", "attachments"); if (!attachmentsDirectory.isDirectory()) { attachmentsDirectory.mkdirs();// w w w . ja v a2 s.c o m } File sourceDirectory = new File("target", "source"); if (!sourceDirectory.isDirectory()) { sourceDirectory.mkdirs(); } File tempDirectory = new File("target", "temp"); if (!tempDirectory.isDirectory()) { tempDirectory.mkdirs(); } URL url = new URL("https://codehaus-cargo.atlassian.net/wiki/rest/api/space/CARGO/content?limit=2048"); URLConnection connection = url.openConnection(); StringBuilder sb = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { for (String line = reader.readLine(); line != null; line = reader.readLine()) { sb.append(line); } } JSONArray pages = new JSONObject(sb.toString()).getJSONObject("page").getJSONArray("results"); System.out.println("Found " + pages.length() + " pages to handle"); files = Collections.synchronizedSet(new HashSet<File>(pages.length())); exceptions = Collections.synchronizedMap(new HashMap<URL, Exception>()); attachments = Collections.synchronizedSet(new HashSet<URL>(pages.length())); for (int i = 0; i < pages.length(); i++) { JSONObject links = pages.getJSONObject(i).getJSONObject("_links"); WebsiteGenerator runnable = new WebsiteGenerator(); runnable.url = new URL(links.getString("self") + "?expand=body.view"); Thread thread = new Thread(runnable); executor.submit(thread); } JSONArray blogposts = new JSONObject(sb.toString()).getJSONObject("blogpost").getJSONArray("results"); System.out.println("Found " + blogposts.length() + " blog posts to handle"); files = Collections.synchronizedSet(new HashSet<File>(blogposts.length())); exceptions = Collections.synchronizedMap(new HashMap<URL, Exception>()); attachments = Collections.synchronizedSet(new HashSet<URL>(blogposts.length())); for (int i = 0; i < blogposts.length(); i++) { JSONObject links = blogposts.getJSONObject(i).getJSONObject("_links"); WebsiteGenerator runnable = new WebsiteGenerator(); runnable.url = new URL(links.getString("self") + "?expand=body.view"); Thread thread = new Thread(runnable); executor.submit(thread); } while (executor.getCompletedTaskCount() < pages.length() + blogposts.length() + attachments.size()) { Thread.sleep(5000); System.out.println(" - Completed " + executor.getCompletedTaskCount() + "/" + (pages.length() + blogposts.length() + attachments.size()) + " tasks - " + ((System.currentTimeMillis() - start) / 1000) + " seconds spent so far"); } if (executor.getCompletedTaskCount() < pages.length() + blogposts.length() + attachments.size()) { throw new Exception("WARNING: Only completed " + executor.getCompletedTaskCount() + " tasks out of " + (pages.length() + blogposts.length() + attachments.size())); } System.out.println("All tasks complete"); for (File file : files) { System.out.println(" - Wrote file " + file.getAbsolutePath()); } if (exceptions.size() > 0) { for (HashMap.Entry<URL, Exception> exception : exceptions.entrySet()) { System.out.println(" - Pending exception for URL " + exception.getKey() + ": " + exception); } throw new Exception("Some files have failed download"); } System.out.println( "Export completed, total time taken " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); }
From source file:com.musenkishi.atelier.Atelier.java
public static AtelierBuilder with(String id) { if (paletteCache == null) { paletteCache = Collections.synchronizedMap(new LRUMap<String, Palette>(MAX_ITEMS_IN_CACHE)); }//from w w w . j a v a 2 s.c o m return new AtelierBuilder(id); }
From source file:mitm.application.djigzo.ws.impl.JamesRepositoryManagerWSImpl.java
public JamesRepositoryManagerWSImpl(ServiceManager serviceManager, Map<JamesRepository, String> repositoryURLMap) { Check.notNull(serviceManager, "serviceManager"); Check.notNull(repositoryURLMap, "repositoryURLMap"); this.serviceManager = serviceManager; this.repositoryURLMap = Collections.synchronizedMap(new HashMap<JamesRepository, String>(repositoryURLMap)); }
From source file:com.evolveum.midpoint.prism.marshaller.PrismBeanInspector.java
private <V, P1, P2> V find2(final Map<P1, Map<P2, V>> cache, final P1 param1, final P2 param2, final Getter2<V, P1, P2> getter) { Map<P2, V> cache2 = cache.computeIfAbsent(param1, k -> Collections.synchronizedMap(new HashMap<>())); return find1(cache2, param2, p -> getter.get(param1, p)); }
From source file:com.icesoft.util.pooling.StringInternMapLRU.java
private void createMap() { int maxSize = defaultSize; if (contextParam != null) { String maxSizeParam = FacesContext.getCurrentInstance().getExternalContext() .getInitParameter(contextParam); if (maxSizeParam != null && maxSizeParam.length() > 0) { int configuredMaxSize = 0; try { configuredMaxSize = Integer.parseInt(maxSizeParam); } catch (Exception e) { log.error("Couldn't parse context-param: " + contextParam + ".", e); }/*ww w .j av a 2s. co m*/ if (configuredMaxSize > 0) { maxSize = configuredMaxSize; } else { disabled = true; return; } } } int capacity = ((maxSize * 4) / 3) + 10; final int finalSize = maxSize; map = Collections.synchronizedMap(new LinkedHashMap(capacity, 0.75f, true) { protected boolean removeEldestEntry(Map.Entry eldest) { return size() > finalSize; } }); }
From source file:com.taobao.weex.devtools.inspector.protocol.module.DOM.java
public DOM(Document document) { mObjectMapper = new ObjectMapper(); mDocument = Util.throwIfNull(document); mSearchResults = Collections.synchronizedMap(new HashMap<String, List<Integer>>()); mResultCounter = new AtomicInteger(0); mPeerManager = new ChromePeerManager(); mPeerManager.setListener(new PeerManagerListener()); mListener = new DocumentUpdateListener(); }
From source file:gov.nih.nci.integration.invoker.CaTissueRegistrationServiceInvocationStrategy.java
/** * Constructor// w ww .j av a 2 s. c o m * * @param retryCount - retryCount * @param caTissueParticipantClient - caTissueParticipantClient * @param xsltTransformer - xsltTransformer */ public CaTissueRegistrationServiceInvocationStrategy(int retryCount, CaTissueParticipantClient caTissueParticipantClient, XSLTTransformer xsltTransformer) { super(); this.retryCount = retryCount; this.caTissueParticipantClient = caTissueParticipantClient; this.xsltTransformer = xsltTransformer; final HashMap<String, IntegrationError> msgToErrMapBase = new LinkedHashMap<String, IntegrationError>(); msgToErrMapBase.put("Error authenticating user", IntegrationError._1019); msgToErrMapBase.put("Exception occurred while performing XSL transformation on Date field.", IntegrationError._1028); // CHECKSTYLE:OFF msgToErrMapBase.put( "Submission failed since a Participant with the same Participant Protocol ID within this Collection Protocol already exists.", IntegrationError._1031); // CHECKSTYLE:ON msgToErrMapBase.put( "Submission failed since a Participant with the same SOCIAL_SECURITY_NUMBER already exists.", IntegrationError._1032); msgToErrMapBase.put("Participant does not contain the unique identifier SSN", IntegrationError._1034); msgToErrMapBase.put("Participant does not contain the unique medical identifier", IntegrationError._1035); msgToErrMapBase.put( "Either Title is not selected or Date format is not correct in Collection Protocol Registration", IntegrationError._1098); msgToErrMapBase.put("Exception occurred while XSL transformation.", IntegrationError._1099); msgToErrMapBase.put("Collection Protocol's consent tier statements list is empty.", IntegrationError._1107); msgToErrMap = Collections.synchronizedMap(msgToErrMapBase); }
From source file:gov.nih.nci.integration.invoker.CaTissueSpecimenServiceInvocationStrategy.java
/** * Constructor/*from w w w. j a v a 2 s . c o m*/ * * @param retryCount - retryCount * @param caTissueSpecimenClient - caTissueSpecimenClient * @param xsltTransformer - xsltTransformer */ public CaTissueSpecimenServiceInvocationStrategy(int retryCount, CaTissueSpecimenClient caTissueSpecimenClient, XSLTTransformer xsltTransformer) { super(); this.retryCount = retryCount; this.caTissueSpecimenClient = caTissueSpecimenClient; this.xsltTransformer = xsltTransformer; final HashMap<String, IntegrationError> msgToErrMapBase = new LinkedHashMap<String, IntegrationError>(); msgToErrMapBase.put("Type is required", IntegrationError._1079); msgToErrMapBase.put("Specimen with the same LABEL already exists", IntegrationError._1080); msgToErrMapBase.put("Specimen Type is invalid", IntegrationError._1081); msgToErrMapBase.put("Tissue Side is invalid", IntegrationError._1082); msgToErrMapBase.put("Tissue Site is invalid", IntegrationError._1083); msgToErrMapBase.put("Specimen Collection Group not found in caTissue", IntegrationError._1084); msgToErrMapBase.put("Available Quantity cannot be greater than the Initial Quantity", IntegrationError._1085); msgToErrMapBase.put("Pathological Status is invalid", IntegrationError._1086); msgToErrMapBase.put("Error occurred : Unable to rollback. Please check the logs.", IntegrationError._1093); msgToErrMapBase.put("Guidance for breast core biopsy is required.", IntegrationError._1094); msgToErrMapBase.put("\'Other Text\' should be provided only when a guidance of \'OTHER\' is selected.", IntegrationError._1095); msgToErrMapBase.put("The value for \'Guidance for breast core biopsy\' is invalid.", IntegrationError._1097); msgToErrMapBase.put("Exception occurred while XSL transformation.", IntegrationError._1099); msgToErrMap = Collections.synchronizedMap(msgToErrMapBase); }
From source file:org.ejbca.config.ExtendedKeyUsageConfiguration.java
/** * Fill the map and list with OIDs from the configuration file *//*from w w w .j av a 2 s.c o m*/ private static synchronized void fillExtendedKeyUsageOidsAndTexts() { final ListOrderedMap map = new ListOrderedMap(); final Configuration conf = ConfigurationHolder.instance(); final String ekuname = "extendedkeyusage.name."; final String ekuoid = "extendedkeyusage.oid."; for (int i = 0; i < 255; i++) { final String oid = conf.getString(ekuoid + i); if (oid != null) { String name = conf.getString(ekuname + i); if (name != null) { // A null value in the properties file means that we should not use this value, so set it to null for real if (name.equalsIgnoreCase("null")) { name = null; } map.put(oid, name); } else { log.error("Found extended key usage oid " + oid + ", but no name defined. Not adding to list of extended key usages."); } } else { // No eku with that number = no more ekus so break, log.debug("Read " + i + " extended key usages."); break; } } extendedKeyUsageOids = map.asList(); if (extendedKeyUsageOids == null) { log.error("Extended key usage OIDs is null, there is a serious error with extendedkeyusage.properties"); extendedKeyUsageOids = new ArrayList<String>(); } extendedKeyUsageOidsAndNames = Collections.synchronizedMap(map); }