}; private final ClassMetaCache<Field[]> cache = new ClassMetaCache<>();
/** * Puts value into cache * * @param key * @param value * @return value previously stored in cache for this key, or {@code null} if none */ public T put(Class<?> key, T value) { ConcurrentHashMap<String, T> container = getClassLoaderCache(key.getClassLoader(), true); return container.put(key(key), value); }
private Field[] getFromCache(Class<?> pClass) { Field[] fields = cache.get(pClass); return fields != null ? fields : putInCache(pClass); }
private Field[] putInCache(Class<?> pClass) { Field[] fields = collectAnnotatedFieldsForHierarchy(pClass); cache.put(pClass, fields); return fields; }
@Override public void dispatchEvent(final Object sink, final IEvent<?> event, final Component component) { AnnotationEventSink eventSink = eventSinkByClass.get(sink.getClass()); AnnotationEventDispatcherConfig config = Application.get().getMetaData( Initializer.ANNOTATION_EVENT_DISPATCHER_CONFIG_CONTEXT_KEY); if (eventSink != null && eventSink != EMPTY_SINK && (config.getEventFilter() == null || config.getEventFilter().isAssignableFrom( event.getPayload().getClass()))) { eventSink.onEvent(sink, event); } }
private static ClassMetaCache<NonContextual<?>> getCache(BeanManager manager) { ClassMetaCache<NonContextual<?>> meta = cache.get(manager); if (meta == null) { synchronized (lock) { meta = cache.get(manager); if (meta == null) { meta = new ClassMetaCache<NonContextual<?>>(); // copy-on-write the cache Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>( cache); newCache.put(manager, meta); cache = Collections.unmodifiableMap(newCache); } } } return meta; }
/** * Puts value into cache * * @param key * the class that will be used as the value's key * @param value * the value that should be stored in cache * @return value previously stored in cache for this key, or {@code null} if none */ public T put(final Class<?> key, final T value) { ConcurrentHashMap<String, T> container = getClassLoaderCache(key.getClassLoader(), true); return container.put(key(key), value); }
private Set<Method> getOnEventMethods(final Class<?> payloadType) { Set<Method> onEventMethods = onEventMethodsByPayloadType.get(payloadType); if (onEventMethods == null) { onEventMethods = new HashSet<Method>(); for (Class<?> type : CompatibleTypesCache.getCompatibleTypes(payloadType)) { Set<Method> methods = onEventMethodsByParameterType.get(type); if (methods != null) { onEventMethods.addAll(methods); } } onEventMethodsByPayloadType.put(payloadType, onEventMethods); } return onEventMethods; }
private static ClassMetaCache<NonContextual<?>> getCache() { ClassMetaCache<NonContextual<?>> meta = cache.get(BeanManagerLookup.lookup()); if (meta == null) { synchronized (lock) { BeanManager manager = BeanManagerLookup.lookup(); meta = cache.get(manager); if (meta == null) { meta = new ClassMetaCache<NonContextual<?>>(); // copy-on-write the cache Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>( cache); newCache.put(manager, meta); cache = Collections.unmodifiableMap(newCache); } } } return meta; }
/** * Gets value from cache or returns {@code null} if not in cache * * @param key * @return value stored in cache or {@code null} if none */ public T get(Class<?> key) { ConcurrentHashMap<String, T> container = getClassLoaderCache(key.getClassLoader(), false); if (container == null) { return null; } else { return container.get(key(key)); } }
@Override public void onInstantiation(final Component component) { Class<?> componentClass = component.getClass(); if (eventSinkByClass.get(componentClass) == null) { if (containsOnEventMethod(componentClass)) { eventSinkByClass.put(componentClass, new AnnotationEventSink(componentClass)); } else { eventSinkByClass.put(componentClass, EMPTY_SINK); } } }
private static ClassMetaCache<NonContextual<?>> getCache() { ClassMetaCache<NonContextual<?>> meta = cache.get(BeanManagerLookup.lookup()); if (meta == null) { synchronized (lock) { BeanManager manager = BeanManagerLookup.lookup(); meta = cache.get(manager); if (meta == null) { meta = new ClassMetaCache<NonContextual<?>>(); // copy-on-write the cache Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>( cache); newCache.put(manager, meta); cache = Collections.unmodifiableMap(newCache); } } } return meta; }
/** * Gets value from cache or returns {@code null} if not in cache * * @param key * the class that is the key for the value * @return value stored in cache or {@code null} if none */ public T get(final Class<?> key) { ConcurrentHashMap<String, T> container = getClassLoaderCache(key.getClassLoader(), false); if (container == null) { return null; } else { return container.get(key(key)); } }
/** * Determines which {@link Scheme} should be used to access the page * * @param pageClass * type of page * @return {@link Scheme} */ protected Scheme getDesiredSchemeFor(Class<? extends IRequestablePage> pageClass) { if (pageClass == null) { return Scheme.ANY; } Scheme SCHEME = cache.get(pageClass); if (SCHEME == null) { if (hasSecureAnnotation(pageClass)) { SCHEME = Scheme.HTTPS; } else { SCHEME = Scheme.HTTP; } cache.put(pageClass, SCHEME); } return SCHEME; }
private static ClassMetaCache<NonContextual<?>> getCache() { ClassMetaCache<NonContextual<?>> meta = cache.get(CDI.current().getBeanManager()); if (meta == null) { synchronized (lock) { BeanManager manager = CDI.current().getBeanManager(); meta = cache.get(manager); if (meta == null) { meta = new ClassMetaCache<>(); // copy-on-write the cache Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<>(cache); newCache.put(manager, meta); cache = Collections.unmodifiableMap(newCache); } } } return meta; }
/** * Determines which {@link Scheme} should be used to access the page * * @param pageClass * type of page * @return {@link Scheme} */ protected Scheme getDesiredSchemeFor(Class<? extends IRequestablePage> pageClass) { if (pageClass == null) { return Scheme.ANY; } Scheme SCHEME = cache.get(pageClass); if (SCHEME == null) { if (hasSecureAnnotation(pageClass)) { SCHEME = Scheme.HTTPS; } else { SCHEME = Scheme.HTTP; } cache.put(pageClass, SCHEME); } return SCHEME; }
/** * Factory method for creating non-contextual instances * * @param <T> * @param clazz * @return The NonContextual for the given class */ public static <T> NonContextual<T> of(Class<? extends T> clazz) { ClassMetaCache<NonContextual<?>> meta = getCache(); @SuppressWarnings("unchecked") NonContextual<T> nc = (NonContextual<T>)meta.get(clazz); if (nc == null) { nc = new NonContextual<T>(clazz); meta.put(clazz, nc); } return nc; }
/** * Factory method for creating noncontextual instances * * @param <T> Bean type. * @param clazz Bean class. * @return {@link NonContextual} instance. */ public static <T> NonContextual<T> of(Class<? extends T> clazz) { ClassMetaCache<NonContextual<?>> meta = getCache(); @SuppressWarnings("unchecked") NonContextual<T> nc = (NonContextual<T>) meta.get(clazz); if (nc == null) { nc = new NonContextual<>(clazz); meta.put(clazz, nc); } return nc; }