public static Boolean evaluate(String string, String regex, int flags, Navigator navigator) { ThreadLocalCache<Map<String, Pattern>> threadLocalPatterns = ThreadLocalCacheManager.getThreadLocalCache( Lifecycle.ETERNAL, MatchesFunction.class.getName()); Map<String, Pattern> patterns = threadLocalPatterns.get(_THREAD_LOCAL_PATTERNS_KEY); if (patterns == null) { patterns = new HashMap<String, Pattern>(); } Pattern pattern = patterns.get(regex); if (pattern != null) { Matcher matcher = pattern.matcher(string); return matcher.find(); } pattern = Pattern.compile(regex, flags); patterns.put(regex, pattern); threadLocalPatterns.put(_THREAD_LOCAL_PATTERNS_KEY, patterns); Matcher matcher = pattern.matcher(string); return matcher.find(); }
public List<Group> getMySites(String[] classNames, boolean includeControlPanel, int max) throws PortalException, SystemException { ThreadLocalCache<List<Group>> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache(Lifecycle.REQUEST, UserImpl.class.getName()); String key = StringUtil.toHexString(max); if ((classNames != null) && (classNames.length > 0)) { key = StringUtil.merge(classNames).concat(StringPool.POUND).concat(key); } key = key.concat(StringPool.POUND).concat(String.valueOf(includeControlPanel)); List<Group> myPlaces = threadLocalCache.get(key); if (myPlaces != null) { return myPlaces; } myPlaces = GroupServiceUtil.getUserPlaces(getUserId(), classNames, includeControlPanel, max); threadLocalCache.put(key, myPlaces); return myPlaces; }
/** * Returns <code>true</code> if the user is associated with the named regular role. * * @param userId the primary key of the user * @param companyId the primary key of the company * @param name the name of the role * @param inherited whether to include the user's inherited roles in the search * @return <code>true</code> if the user is associated with the regular role; <code>false</code> * otherwise * @throws PortalException if a role with the name could not be found in the company or if a * default user for the company could not be found * @throws SystemException if a system exception occurred */ @ThreadLocalCachable public boolean hasUserRole(long userId, long companyId, String name, boolean inherited) throws PortalException, SystemException { Role role = rolePersistence.findByC_N(companyId, name); if (role.getType() != RoleConstants.TYPE_REGULAR) { throw new IllegalArgumentException(name + " is not a regular role"); } long defaultUserId = userLocalService.getDefaultUserId(companyId); if (userId == defaultUserId) { if (name.equals(RoleConstants.GUEST)) { return true; } else { return false; } } if (inherited) { if (userPersistence.containsRole(userId, role.getRoleId())) { return true; } ThreadLocalCache<Integer> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache( Lifecycle.REQUEST, RoleLocalServiceImpl.class.getName()); String key = String.valueOf(role.getRoleId()).concat(String.valueOf(userId)); Integer value = threadLocalCache.get(key); if (value == null) { value = roleFinder.countByR_U(role.getRoleId(), userId); threadLocalCache.put(key, value); } if (value > 0) { return true; } else { return false; } } else { return userPersistence.containsRole(userId, role.getRoleId()); } }
public void afterReturning(MethodInvocation methodInvocation, Object result) throws Throwable { MethodTargetClassKey methodTargetClassKey = buildMethodTargetClassKey(methodInvocation); ThreadLocalCachable threadLocalCachable = findAnnotation(methodTargetClassKey); if (threadLocalCachable == _nullThreadLocalCacheable) { return; } ThreadLocalCache<Object> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache( threadLocalCachable.scope(), methodTargetClassKey.toString()); String cacheKey = _buildCacheKey(methodInvocation.getArguments()); if (result == null) { threadLocalCache.put(cacheKey, nullResult); } else { threadLocalCache.put(cacheKey, result); } }
public Object before(MethodInvocation methodInvocation) throws Throwable { MethodTargetClassKey methodTargetClassKey = buildMethodTargetClassKey(methodInvocation); ThreadLocalCachable threadLocalCachable = findAnnotation(methodTargetClassKey); if (threadLocalCachable == _nullThreadLocalCacheable) { return null; } ThreadLocalCache<?> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache( threadLocalCachable.scope(), methodTargetClassKey.toString()); String cacheKey = _buildCacheKey(methodInvocation.getArguments()); Object value = threadLocalCache.get(cacheKey); if (value == nullResult) { return null; } return value; }
@Override public void init() throws ServletException { if (_log.isDebugEnabled()) { _log.debug("Initialize"); } ServletContext servletContext = getServletContext(); servletContext.setAttribute(MainServlet.class.getName(), Boolean.TRUE); callParentInit(); if (_log.isDebugEnabled()) { _log.debug("Initialize servlet context pool"); } if (_log.isDebugEnabled()) { _log.debug("Process startup events"); } try { processStartupEvents(); } catch (Exception e) { _log.error(e, e); System.out.println("Stopping the server due to unexpected startup errors"); System.exit(0); } if (_log.isDebugEnabled()) { _log.debug("Initialize server detector"); } try { initServerDetector(); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize plugin package"); } PluginPackage pluginPackage = null; try { pluginPackage = initPluginPackage(); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize portlets"); } List<Portlet> portlets = new ArrayList<Portlet>(); try { portlets.addAll(initPortlets(pluginPackage)); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize layout templates"); } try { initLayoutTemplates(pluginPackage, portlets); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize social"); } try { initSocial(pluginPackage); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize themes"); } try { initThemes(pluginPackage, portlets); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize web settings"); } try { initWebSettings(); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize extension environment"); } try { initExt(); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Process global startup events"); } try { processGlobalStartupEvents(); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize resource actions"); } try { initResourceActions(portlets); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize companies"); } try { initCompanies(); } catch (Exception e) { _log.error(e, e); } if (_log.isDebugEnabled()) { _log.debug("Initialize plugins"); } try { initPlugins(); } catch (Exception e) { _log.error(e, e); } servletContext.setAttribute(WebKeys.STARTUP_FINISHED, true); StartupHelperUtil.setStartupFinished(true); ThreadLocalCacheManager.clearAll(Lifecycle.REQUEST); }