List of usage examples for com.google.common.cache LoadingCache getIfPresent
@Nullable V getIfPresent(Object key);
From source file:org.jasig.portal.portlet.container.cache.PrivatePortletCacheKeyTracker.java
protected void removeEntry(Element element) { final PrivatePortletCacheKey key = (PrivatePortletCacheKey) element.getKey(); final LoadingCache<IPortletWindowId, Set<PrivatePortletCacheKey>> privatePortletCacheKeys = privatePortletCacheKeysBySession .get(key.getSessionId());/* www. j a va2 s . c o m*/ if (privatePortletCacheKeys != null) { final Set<PrivatePortletCacheKey> keySet = privatePortletCacheKeys .getIfPresent(key.getPortletWindowId()); if (keySet != null) { logger.debug("Removed cache key {} from tracker {}", key, this.sessionKey); keySet.remove(key); } } }
From source file:org.jasig.portal.portlet.container.cache.PrivatePortletCacheKeyTracker.java
public Set<PrivatePortletCacheKey> getCacheKeys(HttpSession session, IPortletWindowId portletWindowId) { final LoadingCache<IPortletWindowId, Set<PrivatePortletCacheKey>> privatePortletCacheKeys = privatePortletCacheKeysBySession .get(session.getId());/*from w ww. java2 s.co m*/ if (privatePortletCacheKeys == null) { return Collections.emptySet(); } final Set<PrivatePortletCacheKey> keySet = privatePortletCacheKeys.getIfPresent(portletWindowId); if (keySet == null) { return Collections.emptySet(); } return keySet; }
From source file:org.apereo.portal.utils.cache.TagTrackingCacheEventListener.java
/** * If the element has a TaggedCacheKey remove the tag associations *///from w w w . j a v a2s .c o m protected void removeElement(Ehcache cache, Element element) { final Set<CacheEntryTag> tags = this.getTags(element); //Check if the key is tagged if (tags != null && !tags.isEmpty()) { final String cacheName = cache.getName(); final LoadingCache<CacheEntryTag, Set<Object>> cacheKeys = taggedCacheKeys.getIfPresent(cacheName); //If there are tracked tagged keys remove matching tags if (cacheKeys != null) { final Object key = element.getObjectKey(); logger.debug("Tracking removing key cache {} with tag {} : {}", cacheName, tags, key); for (final CacheEntryTag tag : tags) { final Set<Object> taggedKeys = cacheKeys.getIfPresent(tag); //Remove the tagged key if (taggedKeys != null) { taggedKeys.remove(key); } } } } }
From source file:org.waveprotocol.box.server.waveserver.Wave.java
private <T extends WaveletContainer> T getWavelet(WaveletId waveletId, LoadingCache<WaveletId, T> waveletsMap) throws WaveletStateException { ImmutableSet<WaveletId> storedWavelets; try {//from w w w .j av a2s . c o m storedWavelets = FutureUtil.getResultOrPropagateException(lookedupWavelets, PersistenceException.class); } catch (PersistenceException e) { throw new WaveletStateException("Failed to lookup wavelet " + WaveletName.of(waveId, waveletId), e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new WaveletStateException("Interrupted looking up wavelet " + WaveletName.of(waveId, waveletId), e); } if (LOG.isFineLoggable()) { if (storedWavelets != null) { if (storedWavelets.contains(waveletId)) { LOG.fine("Wavelet is in storedWavelets"); } if (waveletsMap.getIfPresent(waveletId) != null) { LOG.fine("Wavelet is in wavletsMap"); } } } // Since waveletsMap is a computing map, we must call getIfPresent(waveletId) // to tell if waveletId is mapped, we cannot test if get(waveletId) returns null. if (storedWavelets != null && !storedWavelets.contains(waveletId) && waveletsMap.getIfPresent(waveletId) == null) { return null; } else { try { T wavelet = waveletsMap.get(waveletId); return wavelet; } catch (CacheLoader.InvalidCacheLoadException ex) { return null; } catch (ExecutionException ex) { throw new RuntimeException(ex); } } }
From source file:org.jboss.weld.bootstrap.BeanDeployer.java
public void createClassBeans() { LoadingCache<Class<?>, Set<SlimAnnotatedType<?>>> otherWeldClasses = Multimaps.newConcurrentSetMultimap(); for (SlimAnnotatedTypeContext<?> ctx : getEnvironment().getAnnotatedTypes()) { createClassBean(ctx.getAnnotatedType(), otherWeldClasses); }/*from w w w . j a v a2 s . c om*/ // create session beans for (InternalEjbDescriptor<?> ejbDescriptor : getEnvironment().getEjbDescriptors()) { if (getEnvironment().isVetoed(ejbDescriptor.getBeanClass()) || Beans.isVetoed(ejbDescriptor.getBeanClass())) { continue; } if (ejbDescriptor.isSingleton() || ejbDescriptor.isStateful() || ejbDescriptor.isStateless()) { if (otherWeldClasses.getIfPresent(ejbDescriptor.getBeanClass()) != null) { for (SlimAnnotatedType<?> annotatedType : getCacheValue(otherWeldClasses, ejbDescriptor.getBeanClass())) { EnhancedAnnotatedType<?> weldClass = classTransformer .getEnhancedAnnotatedType(annotatedType); createSessionBean(ejbDescriptor, Reflections.<EnhancedAnnotatedType>cast(weldClass)); } } else { createSessionBean(ejbDescriptor); } } } }
From source file:org.jboss.weld.bootstrap.ConcurrentBeanDeployer.java
@Override public void createClassBeans() { final LoadingCache<Class<?>, Set<SlimAnnotatedType<?>>> otherWeldClasses = Multimaps .newConcurrentSetMultimap(); executor.invokeAllAndCheckForExceptions( new IterativeWorkerTaskFactory<SlimAnnotatedTypeContext<?>>(getEnvironment().getAnnotatedTypes()) { @Override/*from ww w . j a v a 2s . c o m*/ protected void doWork(SlimAnnotatedTypeContext<?> ctx) { createClassBean(ctx.getAnnotatedType(), otherWeldClasses); } }); executor.invokeAllAndCheckForExceptions( new IterativeWorkerTaskFactory<InternalEjbDescriptor<?>>(getEnvironment().getEjbDescriptors()) { @Override protected void doWork(InternalEjbDescriptor<?> descriptor) { if (!getEnvironment().isVetoed(descriptor.getBeanClass()) && !Beans.isVetoed(descriptor.getBeanClass())) { if (descriptor.isSingleton() || descriptor.isStateful() || descriptor.isStateless()) { if (otherWeldClasses.getIfPresent(descriptor.getBeanClass()) != null) { for (SlimAnnotatedType<?> annotatedType : getCacheValue(otherWeldClasses, descriptor.getBeanClass())) { EnhancedAnnotatedType<?> weldClass = classTransformer .getEnhancedAnnotatedType(annotatedType); createSessionBean(descriptor, Reflections.<EnhancedAnnotatedType>cast(weldClass)); } } else { createSessionBean(descriptor); } } } } }); }