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.openhab.binding.modbus.internal.ModbusConfiguration.java
public static Collection<ModbusSlave> getAllSlaves() { return Collections.synchronizedMap(modbusSlaves).values(); }
From source file:cat.albirar.framework.dynabean.impl.DynaBeanDescriptor.java
/** * Default constructor.//from ww w . ja va 2 s . c om */ DynaBeanDescriptor(IDynaBeanImplementationFactory factory) { this.factory = factory; validDescriptor = false; properties = Collections.synchronizedMap(new TreeMap<String, DynaBeanPropertyDescriptor>()); }
From source file:org.cesecore.config.ExtendedKeyUsageConfiguration.java
/** * Fill the map and list with OIDs from the configuration file *//* w w w.j a v a 2s .c o m*/ @SuppressWarnings("unchecked") 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; } else { 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."); } } // No eku with a certain number == continue trying next, we will try 0-255. } log.debug("Read " + map.size() + " extended key usages."); extendedKeyUsageOids = map.asList(); if ((extendedKeyUsageOids == null) || (extendedKeyUsageOids.size() == 0)) { log.error( "Extended key usage OIDs is null or zero length, there is a serious error with extendedkeyusage.properties"); extendedKeyUsageOids = new ArrayList<String>(); } extendedKeyUsageOidsAndNames = Collections.synchronizedMap(map); }
From source file:strat.mining.multipool.stats.service.impl.RequestStatsLoggingServiceImpl.java
@Scheduled(cron = "0 0 * * * *") private void logStats() { Map<String, Map<String, AtomicInteger>> currencyTickersOldMap = currencyTickerRequest; currencyTickerRequest = Collections.synchronizedMap(new HashMap<String, Map<String, AtomicInteger>>()); Map<String, AtomicInteger> donatorsRequestOld = donatorsRequests; donatorsRequests = Collections.synchronizedMap(new HashMap<String, AtomicInteger>()); LOGGER.debug("Nb donnation requests: {}.", nbDonnation.intValue()); LOGGER.debug("Nb blockchain details requests: {}.", nbBlockchainDetails.intValue()); LOGGER.debug("Nb all exchange place requests: {}.", nbAllExchangePlace.intValue()); LOGGER.debug("Nb currency ticker requests: {}.", nbCurrencyTicker.intValue()); for (Entry<String, Map<String, AtomicInteger>> entry1 : currencyTickersOldMap.entrySet()) { for (Entry<String, AtomicInteger> entry2 : entry1.getValue().entrySet()) { LOGGER.debug("Nb currency ticker requests for exchange {} and currency {}: {}.", entry1.getKey(), entry2.getKey(), entry2.getValue().intValue()); }//from ww w. j a va2 s . co m } for (Entry<String, AtomicInteger> entry : donatorsRequestOld.entrySet()) { LOGGER.debug("Nb donators requests for {}: {}.", entry.getKey(), entry.getValue().get()); } LOGGER.debug(" "); LOGGER.debug(" "); LOGGER.debug(" "); nbCurrencyTicker.set(0); nbBlockchainDetails.set(0); nbAllExchangePlace.set(0); nbDonnation.set(0); }
From source file:at.tugraz.ist.catroweb.BaseTest.java
@BeforeClass(alwaysRun = true) @Parameters({ "webSite", "basedir" }) protected void constructor(String webSite, String basedir) { this.webSite = webSite; Config.setSeleniumGridTestdata(basedir); projectUploader = new ProjectUploader(webSite); this.driverSessions = Collections.synchronizedMap(new HashMap<String, WebDriver>()); }
From source file:org.apache.hadoop.hdfs.server.namenode.ha.TestHASafeMode.java
/** * Make sure the client retries when the active NN is in safemode *///from w w w . ja v a 2 s . co m @Test(timeout = 300000) public void testClientRetrySafeMode() throws Exception { final Map<Path, Boolean> results = Collections.synchronizedMap(new HashMap<Path, Boolean>()); final Path test = new Path("/test"); // let nn0 enter safemode NameNodeAdapter.enterSafeMode(nn0, false); NameNodeAdapter.enterSafeMode(nn1, false); SafeModeInfo safeMode = nn0.getNamesystem().getSafeModeInfoForTests(); Whitebox.setInternalState(safeMode, "extension", Integer.valueOf(30000)); HdfsVariables.setSafeModeInfo(safeMode, safeMode.getReached()); LOG.info("enter safemode"); Thread testThread = new Thread() { @Override public void run() { try { boolean mkdir = fs.mkdirs(test); LOG.info("mkdir finished, result is " + mkdir); synchronized (TestHASafeMode.this) { results.put(test, mkdir); TestHASafeMode.this.notifyAll(); } } catch (Exception e) { LOG.info("Got Exception while calling mkdir", e); } } }; testThread.setName("test"); testThread.start(); // make sure the client's call has actually been handled by the active NN assertFalse("The directory should not be created while NN in safemode", fs.exists(test)); Thread.sleep(1000); // let nn0 leave safemode NameNodeAdapter.leaveSafeMode(nn0); LOG.info("leave safemode"); synchronized (this) { while (!results.containsKey(test)) { this.wait(); } assertTrue(results.get(test)); } }
From source file:org.broadleafcommerce.common.util.EfficientLRUMap.java
protected synchronized boolean switchToLRUMap() { if (!usingLRUMap) { if (size() > maxEntries) { lruMap = Collections.synchronizedMap(new LRUMap<K, V>(maxEntries)); lruMap.putAll(concurrentMap); usingLRUMap = true;//from w w w. j ava2s .c om concurrentMap.clear(); } } return usingLRUMap; // this could be set by another thread }
From source file:strat.mining.multipool.stats.service.impl.DonationServiceImpl.java
@PostConstruct public void init() { transactionsNotThankedByAddress = Collections.synchronizedMap(new HashMap<String, List<Transaction>>()); updateDonations();/* ww w. java 2s. c o m*/ }
From source file:de.innovationgate.wgpublisher.webtml.portlet.TMLPortletStateSessionStorage.java
private Map<String, TMLPortletState> getSessionMap() { synchronized (_session) { Map<String, TMLPortletState> contexts = (Map<String, TMLPortletState>) _session .getAttribute(WGACore.SESSION_PORTLETMODES); if (contexts == null) { contexts = Collections.synchronizedMap(new HashMap<String, TMLPortletState>()); _session.setAttribute(WGACore.SESSION_PORTLETMODES, contexts); }/*from w ww .j a v a 2 s . c o m*/ return contexts; } }
From source file:be.fedict.trust.service.snmp.mbean.SNMPService.java
/** * Initialized the {@link SNMPAgent} if not yet done so. *///from www .ja v a2s . co m private synchronized void initSNMPAgent() { if (null == this.snmpAgent) { LOG.debug("Start SNMP agent @ address=" + this.address); try { this.snmpAgent = new SNMPAgent(this.address, new File("performance.snmp.agent.boot.counter.cfg"), new File("performance.snmp.agent.cfg")); } catch (IOException e) { LOG.error("Failed to start SNMP agent: " + e.getMessage(), e); throw new RuntimeException(e); } this.snmpThread = new Thread(this.snmpAgent); this.snmpThread.start(); this.snmpValues = Collections.synchronizedMap(new HashMap<String, Long>()); } }