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.opencms.workplace.explorer.CmsExplorerTypeAccess.java
/** * Creates the access control list from the temporary map.<p> * // www. jav a 2 s . c o m * @param resourceType the name of the resource type * * @throws CmsException if something goes wrong */ public void createAccessControlList(String resourceType) throws CmsException { if (OpenCms.getRunLevel() < OpenCms.RUNLEVEL_2_INITIALIZING) { // we don't need this for simple test cases return; } if (m_permissionsCache == null) { Map<String, CmsPermissionSetCustom> lruMap = CmsCollectionsGenericWrapper.createLRUMap(2048); m_permissionsCache = Collections.synchronizedMap(lruMap); OpenCms.getMemoryMonitor().register(this.getClass().getName() + "." + resourceType, lruMap); } else { m_permissionsCache.clear(); } m_accessControlList = new CmsAccessControlList(); Iterator<String> i = m_accessControl.keySet().iterator(); while (i.hasNext()) { String key = i.next(); if (!PRINCIPAL_DEFAULT.equals(key)) { String value = m_accessControl.get(key); // get the principal name from the principal String String principal = key.substring(key.indexOf('.') + 1, key.length()); // create an OpenCms user context with "Guest" permissions CmsObject cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); CmsUUID principalId = null; if (key.startsWith(I_CmsPrincipal.PRINCIPAL_GROUP)) { // read the group principal = OpenCms.getImportExportManager().translateGroup(principal); try { principalId = cms.readGroup(principal).getId(); } catch (CmsException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } } else if (key.startsWith(I_CmsPrincipal.PRINCIPAL_USER)) { // read the user principal = OpenCms.getImportExportManager().translateUser(principal); try { principalId = cms.readUser(principal).getId(); } catch (CmsException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } } else { // read the role with role name CmsRole role = CmsRole.valueOfRoleName(principal); if (role == null) { // try to read the role in the old fashion with group name role = CmsRole.valueOfGroupName(principal); } principalId = role.getId(); } if (principalId != null) { // create a new entry for the principal CmsAccessControlEntry entry = new CmsAccessControlEntry(null, principalId, value); m_accessControlList.add(entry); } } } }
From source file:org.commonreality.sensors.base.BaseSensor.java
public BaseSensor(CommonReality cr) { super(cr);// w w w . ja v a2s. c o m _toBeAdded = Collections.synchronizedMap(new HashMap<IIdentifier, Collection<ISimulationObject>>()); _toBeRemoved = Collections.synchronizedMap(new HashMap<IIdentifier, Collection<IIdentifier>>()); _toBeChanged = Collections.synchronizedMap(new HashMap<IIdentifier, Collection<IObjectDelta>>()); _delayedCommands = Collections.synchronizedList(new ArrayList<IMessage>()); _committer = new Committer(); _service = Executors.newSingleThreadExecutor(); _perceptManager = createPerceptManager(); }
From source file:org.jcodec.samples.streaming.MTSIndex.java
public MTSIndex() { this.streams = Collections.synchronizedMap(new HashMap<Integer, StreamEntry>()); }
From source file:net.sf.morph.reflect.reflectors.BaseReflector.java
/** * Initialize this Reflector./* w w w. j av a 2 s . c o m*/ * @throws ReflectionException */ protected final void initialize() throws ReflectionException { if (!initialized) { if (isPerformingLogging() && log.isInfoEnabled()) { log.info("Initializing reflector " + ObjectUtils.getObjectDescription(this)); } try { initializeImpl(); reflectableClasses = getReflectableClassesImpl(); reflectableCallCache = Collections.synchronizedMap(new HashMap()); setInitialized(true); } catch (ReflectionException e) { throw e; } catch (Exception e) { if (e instanceof RuntimeException && !isWrappingRuntimeExceptions()) { throw (RuntimeException) e; } throw new ReflectionException("Could not initialize " + ObjectUtils.getObjectDescription(this), e); } } }
From source file:es.caib.seycon.ng.servei.PuntEntradaServiceImpl.java
public PuntEntradaServiceImpl() { permisosCache = Collections.synchronizedMap(new LRUMap(50)); }
From source file:org.jahia.modules.external.ExternalAccessControlManager.java
public ExternalAccessControlManager(NamespaceRegistry namespaceRegistry, ExternalSessionImpl session, ExternalDataSource dataSource) { this.session = session; this.workspaceName = session.getWorkspace().getName(); this.aclReadOnly = dataSource instanceof ExternalDataSource.AccessControllable; this.writable = dataSource instanceof ExternalDataSource.Writable; this.pathPermissionCache = Collections.synchronizedMap( new LRUMap(SettingsBean.getInstance().getAccessManagerPathPermissionCacheMaxSize())); this.jahiaPrincipal = new JahiaPrincipal(session.getUserID(), session.getRealm(), session.getUserID().startsWith(JahiaLoginModule.SYSTEM), JahiaLoginModule.GUEST.equals(session.getUserID())); try {/*from ww w. ja va 2 s . c o m*/ registry = new JahiaPrivilegeRegistry(namespaceRegistry); this.modifyAccessControlPrivilege = registry.getPrivilege("jcr:modifyAccessControl", workspaceName); this.writePrivilege = registry.getPrivilege("jcr:write", workspaceName); } catch (RepositoryException e) { throw new JahiaRuntimeException(e); } }
From source file:it.anyplace.sync.core.configuration.ConfigurationService.java
private ConfigurationService(Properties properties) { deviceName = properties.getProperty(DEVICE_NAME); if (isBlank(deviceName)) { try {//from w w w.ja v a2 s .c o m deviceName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException ex) { } if (isBlank(deviceName) || equal(deviceName, "localhost")) { deviceName = "s-client"; } } deviceId = properties.getProperty(DEVICE_ID); keystoreAlgo = properties.getProperty(KEYSTORE_ALGO); folders = Collections.synchronizedMap(Maps.<String, FolderInfo>newHashMap()); String folderValue = properties.getProperty(FOLDERS); try { FolderConfigList folderConfigList = isBlank(folderValue) ? new FolderConfigList() : gson.fromJson(folderValue, FolderConfigList.class); for (FolderConfig folderConfig : folderConfigList.getFolders()) { folders.put(folderConfig.getFolder(), new FolderInfo(folderConfig.getFolder(), folderConfig.getLabel())); } } catch (Exception ex) { logger.error("error reading folder field = " + folderValue, ex); } String keystoreValue = properties.getProperty(KEYSTORE); if (!Strings.isNullOrEmpty(keystoreValue)) { keystore = BaseEncoding.base64().decode(keystoreValue); } String cacheDir = properties.getProperty(CACHE); if (!isBlank(cacheDir)) { cache = new File(cacheDir); } else { cache = new File(System.getProperty("java.io.tmpdir"), "a_sync_client_cache"); } cache.mkdirs(); checkArgument(cache.isDirectory() && cache.canWrite(), "invalid cache dir = %s", cache); String tempDir = properties.getProperty(TEMP); if (!isBlank(tempDir)) { temp = new File(tempDir); } else { temp = new File(System.getProperty("java.io.tmpdir"), "a_sync_client_temp"); } temp.mkdirs(); checkArgument(temp.isDirectory() && temp.canWrite(), "invalid temp dir = %s", temp); String dbDir = properties.getProperty(DATABASE); if (!isBlank(dbDir)) { database = new File(dbDir); } else { database = new File(System.getProperty("user.home"), ".config/sclient/db"); } database.mkdirs(); checkArgument(database.isDirectory() && database.canWrite(), "invalid database dir = %s", database); peers = Collections.synchronizedMap(Maps.<String, DeviceInfo>newHashMap()); String peersValue = properties.getProperty(PEERS); try { DeviceConfigList deviceConfigList = isBlank(peersValue) ? new DeviceConfigList() : gson.fromJson(peersValue, DeviceConfigList.class); for (DeviceConfig deviceConfig : deviceConfigList.getDevices()) { peers.put(deviceConfig.getDeviceId(), new DeviceInfo(deviceConfig.getDeviceId(), deviceConfig.getName())); } } catch (Exception ex) { logger.error("error reading peers field = " + peersValue, ex); } String discoveryServerValue = properties.getProperty(DISCOVERY_SERVERS); discoveryServers = Strings.isNullOrEmpty(discoveryServerValue) ? Collections.<String>emptyList() : Arrays.asList(discoveryServerValue.split(",")); clientVersion = MoreObjects.firstNonNull(emptyToNull(getClass().getPackage().getImplementationVersion()), "0.0.0");// version info from MANIFEST, with 'safe' default fallback String configurationValue = properties.getProperty(CONFIGURATION); if (!isBlank(configurationValue)) { configuration = new File(configurationValue); } repositoryH2Config = properties.getProperty(REPOSITORY_H2_CONFIG); }
From source file:com.workplacesystems.queuj.process.ProcessIndexesImpl.java
private boolean updateIndex(final Map index_map, ProcessWrapper process, boolean add) { boolean modified = false; final Queue queue = process.getQueue(); if (queue.hasIndex()) { Map sub_index_map = (Map) SyncUtils.synchronizeWrite(index_map, new Callback() { @Override//from w w w . j a va2s. c o m protected void doAction() { Map custom_index_map = (Map) index_map.get(queue.toString()); if (custom_index_map == null) { custom_index_map = Collections.synchronizedMap(new HashMap()); index_map.put(queue.toString(), custom_index_map); } _return(custom_index_map); } }); modified = updateIndexMap(sub_index_map, process, add, queue.getIndexKey(new Process(process))); updateIndexMap(sub_index_map, process, add, NULL_INDEX_KEY); } else modified = updateIndexMap(index_map, process, add, queue.toString()); updateIndexMap(index_map, process, add, NULL_QUEUE_KEY); return modified; }
From source file:org.apache.cxf.management.web.logging.atom.AtomPushOverWebSocketServer.java
@Override public void init() { super.init(); activeStreams = Collections.synchronizedMap(new HashMap<String, Object>()); }
From source file:aarddict.android.ArticleViewActivity.java
@Override void initUI() {/*from w ww . j av a 2s. com*/ this.scrollPositionsH = Collections.synchronizedMap(new HashMap<Article, ScrollXY>()); this.scrollPositionsV = Collections.synchronizedMap(new HashMap<Article, ScrollXY>()); loadAssets(); if (DeviceInfo.EINK_SCREEN) { useAnimation = false; setContentView(R.layout.eink_article_view); articleView = (ArticleView) findViewById(R.id.EinkArticleView); N2EpdController.n2MainActivity = this; EinkScreen.ResetController(2, articleView); // force full screen // refresh when changing // articles } // Setup animations only on non-eink screens else { useAnimation = true; fadeOutAnimation = new AlphaAnimation(1f, 0f); fadeOutAnimation.setDuration(600); fadeOutAnimation.setAnimationListener(new AnimationAdapter() { public void onAnimationEnd(Animation animation) { Button nextButton = (Button) findViewById(R.id.NextButton); nextButton.setVisibility(Button.GONE); } }); getWindow().requestFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.article_view); articleView = (ArticleView) findViewById(R.id.ArticleView); } timer = new Timer(); backItems = Collections.synchronizedList(new LinkedList<HistoryItem>()); if (android.os.Build.VERSION.SDK_INT >= 11) { try { showFindDialogMethod = articleView.getClass().getMethod("showFindDialog", String.class, boolean.class); } catch (NoSuchMethodException e1) { Log.d(TAG, "showFindDialog method not found"); } } articleView.setOnScrollListener(new ArticleView.ScrollListener() { public void onScroll(int l, int t, int oldl, int oldt) { saveScrollPos(l, t); } }); articleView.getSettings().setJavaScriptEnabled(true); articleView.addJavascriptInterface(new SectionMatcher(), "matcher"); articleView.addJavascriptInterface(articleView, "scrollControl"); articleView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { Log.d(TAG + ".js", String.format("[%s]: %s", url, message)); result.cancel(); return true; } public void onProgressChanged(WebView view, int newProgress) { Log.d(TAG, "Progress: " + newProgress); setProgress(5000 + newProgress * 50); } }); articleView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { Log.d(TAG, "Page finished: " + url); currentTask = null; String section = null; if (url.contains("#")) { LookupWord lookupWord = LookupWord.splitWord(url); section = lookupWord.section; if (backItems.size() > 0) { HistoryItem currentHistoryItem = backItems.get(backItems.size() - 1); HistoryItem h = new HistoryItem(currentHistoryItem); h.article.section = section; backItems.add(h); } } else if (backItems.size() > 0) { Article current = backItems.get(backItems.size() - 1).article; section = current.section; } if (!restoreScrollPos()) { goToSection(section); } updateNextButtonVisibility(); } @Override public boolean shouldOverrideUrlLoading(WebView view, final String url) { Log.d(TAG, "URL clicked: " + url); String urlLower = url.toLowerCase(); if (urlLower.startsWith("http://") || urlLower.startsWith("https://") || urlLower.startsWith("ftp://") || urlLower.startsWith("sftp://") || urlLower.startsWith("mailto:")) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent); } else { if (currentTask == null) { currentTask = new TimerTask() { public void run() { try { Article currentArticle = backItems.get(backItems.size() - 1).article; try { Iterator<Entry> currentIterator = dictionaryService.followLink(url, currentArticle.volumeId); List<Entry> result = new ArrayList<Entry>(); while (currentIterator.hasNext() && result.size() < 20) { result.add(currentIterator.next()); } showNext(new HistoryItem(result)); } catch (ArticleNotFound e) { showMessage(getString(R.string.msgArticleNotFound, e.word.toString())); } } catch (Exception e) { StringBuilder msgBuilder = new StringBuilder( "There was an error following link ").append("\"").append(url) .append("\""); if (e.getMessage() != null) { msgBuilder.append(": ").append(e.getMessage()); } final String msg = msgBuilder.toString(); Log.e(TAG, msg, e); showError(msg); } } }; try { timer.schedule(currentTask, 0); } catch (Exception e) { Log.d(TAG, "Failed to schedule task", e); } } } return true; } }); final Button nextButton = (Button) findViewById(R.id.NextButton); nextButton.getBackground().setAlpha(180); nextButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (nextButton.getVisibility() == View.VISIBLE) { updateNextButtonVisibility(); nextArticle(); updateNextButtonVisibility(); } } }); articleView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { updateNextButtonVisibility(); return false; } }); setProgressBarVisibility(true); }