List of usage examples for java.util Collections synchronizedMap
public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m)
From source file:info.joseluismartin.gtc.AbstractTileCache.java
public void setConfig(CacheConfig config) { this.tileMap = Collections.synchronizedMap(new LRUMap(config.getSize())); this.name = config.getName(); this.serverUrl = config.getUrl(); this.cachePath = config.getDiskCachePath(); this.path = config.getPath(); this.age = config.getAge(); }
From source file:org.openhab.binding.modbus.internal.ModbusConfiguration.java
@Override @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { // remove all known items if configuration changed Collections.synchronizedMap(modbusSlaves).clear(); if (config != null) { Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; }// w w w. j ava 2 s .c o m Matcher matcher = EXTRACT_MODBUS_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { if ("poll".equals(key)) { poll = Integer.valueOf((String) config.get(key)); } else if ("writemultipleregisters".equals(key)) { ModbusSlave.setWriteMultipleRegisters(Boolean.valueOf(config.get(key).toString())); } else { logger.debug("given modbus-slave-config-key '" + key + "' does not follow the expected pattern 'poll' or '<slaveId>.<connection|id|start|length|type>'"); } continue; } matcher.reset(); matcher.find(); String slave = matcher.group(2); ModbusSlave modbusSlave = Collections.synchronizedMap(modbusSlaves).get(slave); if (modbusSlave == null) { if (matcher.group(1).equals(TCP_PREFIX)) { modbusSlave = new ModbusTcpSlave(slave); } else if (matcher.group(1).equals(SERIAL_PREFIX)) { modbusSlave = new ModbusSerialSlave(slave); } else throw new ConfigurationException(slave, "the given slave type '" + slave + "' is unknown"); Collections.synchronizedMap(modbusSlaves).put(slave, modbusSlave); } String configKey = matcher.group(3); String value = (String) config.get(key); if ("connection".equals(configKey)) { String[] chunks = value.split(":"); if (modbusSlave instanceof ModbusTcpSlave) { ((ModbusTcpSlave) modbusSlave).setHost(chunks[0]); if (chunks.length == 2) { ((ModbusTcpSlave) modbusSlave).setPort(Integer.valueOf(chunks[1])); } } else if (modbusSlave instanceof ModbusSerialSlave) { ((ModbusSerialSlave) modbusSlave).setPort(chunks[0]); if (chunks.length == 2) { ((ModbusSerialSlave) modbusSlave).setBaud(Integer.valueOf(chunks[1])); } } } else if ("start".equals(configKey)) { modbusSlave.setStart(Integer.valueOf(value)); } else if ("length".equals(configKey)) { modbusSlave.setLength(Integer.valueOf(value)); } else if ("id".equals(configKey)) { modbusSlave.setId(Integer.valueOf(value)); } else if ("type".equals(configKey)) { if (ArrayUtils.contains(ModbusBindingProvider.SLAVE_DATA_TYPES, value)) { modbusSlave.setType(value); } else { throw new ConfigurationException(configKey, "the given slave type '" + value + "' is invalid"); } } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } } // connect instances to modbus slaves for (ModbusSlave slave : Collections.synchronizedMap(modbusSlaves).values()) { slave.connect(); } }
From source file:com.apporiented.hermesftp.session.impl.FtpSessionContextImpl.java
/** * Constructor.//from www . ja va 2 s .c om * * @param options The server options. * @param userManager The user manager. * @param resourceBundle The resource bundle that containts messages and texts. * @param listener The listener that is informed on session events. */ public FtpSessionContextImpl(FtpServerOptions options, UserManager userManager, ResourceBundle resourceBundle, FtpEventListener listener) { super(); this.userManager = userManager; this.resourceBundle = resourceBundle; this.options = options; this.attributes = Collections.synchronizedMap(new HashMap<String, Object>()); this.eventListener = listener; }
From source file:org.zaproxy.zap.extension.ascanrules.PersistentXSSUtils.java
/** Resets the state of {@code PersistentXSSUtils}. */ @SuppressWarnings("unchecked") public static void reset() { uniqueIndex = 0;// ww w.ja v a 2 s . c o m map = new HashMap<>(); sourceToSinks = new HashMap<>(); cachedUris = Collections.synchronizedMap(new ReferenceMap(ReferenceMap.SOFT, ReferenceMap.SOFT)); cachedParams = Collections.synchronizedMap(new ReferenceMap(ReferenceMap.SOFT, ReferenceMap.SOFT)); }
From source file:info.magnolia.cms.i18n.DefaultMessagesManager.java
/** * The lazy Map creates messages objects with a fall back to the default locale. *///www. j ava 2 s .c o m protected void initMap() { // FIXME use LRU: new LRUMap(20); // LazyMap will instanciate bundles on demand. final Map map = LazyMap.decorate(new HashMap(), new Transformer() { // this transformer will wrap the Messages in a MessagesChain which // will fall back to a Messages instance for the same bundle with // default locale. @Override public Object transform(Object input) { final MessagesID id = (MessagesID) input; return newMessages(id); } }); messages = Collections.synchronizedMap(map); }
From source file:org.springframework.extensions.webscripts.processor.ClojureScriptProcessor.java
/** * {@inheritDoc}/*www . java 2 s . c o m*/ */ public void reset() { init(); this.compiledWebScripts = Collections.synchronizedMap(new HashMap<String, WebScript>()); }
From source file:org.apache.solr.handler.admin.CoreAdminHandler.java
/** * Overloaded ctor to inject CoreContainer into the handler. * * @param coreContainer Core Container of the solr webapp installed. *///from www. j av a2 s . c o m public CoreAdminHandler(final CoreContainer coreContainer) { this.coreContainer = coreContainer; 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:org.vaadin.spring.internal.VaadinUIScope.java
@Override public void registerDestructionCallback(String name, Runnable callback) { final VaadinUIIdentifier uiIdentifier = currentUiId(); logger.debug(String.format("Registering destruction callback [%s] for bean with name [%s] in UI space [%s]", callback, name, uiIdentifier)); Map<String, Runnable> destructionSpace = destructionCallbackMap.get(uiIdentifier); if (destructionSpace == null) { destructionSpace = Collections.synchronizedMap(new LinkedHashMap<String, Runnable>()); destructionCallbackMap.put(uiIdentifier, destructionSpace); }//w w w . j a va 2 s .co m destructionSpace.put(name, callback); }
From source file:de.innovationgate.utils.UserHashMap.java
@SuppressWarnings("unchecked") protected UserHashMap(UserHashMapGroup mapGroup, String id) { _id = id;//from ww w. ja v a 2 s . c o m _group = mapGroup; int max = DEFAULT_MAX_CONCURRENT_PRIVATE_USERCACHES; try { max = Integer.parseInt(System.getProperty(SYSPROP_MAX_CONCURRENT_PRIVATE_USERCACHES, Integer.toString(DEFAULT_MAX_CONCURRENT_PRIVATE_USERCACHES))); } catch (NumberFormatException e) { } _userMaps = Collections.synchronizedMap(new LRUMap(max)); }
From source file:op.care.dfn.PnlDFN.java
private void initPanel() { mapShift2Pane = Collections.synchronizedMap(new HashMap<Byte, CollapsiblePane>()); mapShift2DFN = Collections.synchronizedMap(new HashMap<Byte, ArrayList<DFN>>()); for (Byte shift : new Byte[] { DFNTools.SHIFT_ON_DEMAND, DFNTools.SHIFT_VERY_EARLY, DFNTools.SHIFT_EARLY, DFNTools.SHIFT_LATE, DFNTools.SHIFT_VERY_LATE }) { mapShift2DFN.put(shift, new ArrayList<DFN>()); }/* ww w. j av a2 s . co m*/ mapDFN2Pane = Collections.synchronizedMap(new HashMap<DFN, CollapsiblePane>()); prepareSearchArea(); }