org.springframework.util.ConcurrentReferenceHashMap Java Examples

The following examples show how to use org.springframework.util.ConcurrentReferenceHashMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MappingAuditableBeanWrapperFactory.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link MappingAuditableBeanWrapperFactory} using the given
 * {@link PersistentEntities}.
 * @param entities must not be {@literal null}.
 */
public MappingAuditableBeanWrapperFactory(PersistentEntities entities) {

	Assert.notNull(entities, "PersistentEntities must not be null!");

	this.entities = entities;
	this.metadataCache = new ConcurrentReferenceHashMap<>();
}
 
Example #2
Source File: AnnotationTypeMappings.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Create a cache instance with the specified filter.
 * @param filter the annotation filter
 */
Cache(AnnotationFilter filter) {
	this.filter = filter;
	this.mappings = new ConcurrentReferenceHashMap<>();
}
 
Example #3
Source File: MissingMergedAnnotationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void asMapWithFactoryReturnsNewMapFromFactory() {
	Map<String, Object> map = this.missing.asMap(annotation->new ConcurrentReferenceHashMap<>());
	assertThat(map).isInstanceOf(ConcurrentReferenceHashMap.class);
}
 
Example #4
Source File: CachedIntrospectionResults.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * @param beanClass the bean class to analyze
 * @throws BeansException in case of introspection failure
 */
private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
	try {
		if (logger.isTraceEnabled()) {
			logger.trace("Getting BeanInfo for class [" + beanClass.getName() + "]");
		}
		this.beanInfo = getBeanInfo(beanClass);

		if (logger.isTraceEnabled()) {
			logger.trace("Caching PropertyDescriptors for class [" + beanClass.getName() + "]");
		}
		this.propertyDescriptorCache = new LinkedHashMap<>();

		// This call is slow so we do it once.
		PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
		for (PropertyDescriptor pd : pds) {
			if (Class.class == beanClass &&
					("classLoader".equals(pd.getName()) ||  "protectionDomain".equals(pd.getName()))) {
				// Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
				continue;
			}
			if (logger.isTraceEnabled()) {
				logger.trace("Found bean property '" + pd.getName() + "'" +
						(pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]" : "") +
						(pd.getPropertyEditorClass() != null ?
								"; editor [" + pd.getPropertyEditorClass().getName() + "]" : ""));
			}
			pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
			this.propertyDescriptorCache.put(pd.getName(), pd);
		}

		// Explicitly check implemented interfaces for setter/getter methods as well,
		// in particular for Java 8 default methods...
		Class<?> currClass = beanClass;
		while (currClass != null && currClass != Object.class) {
			introspectInterfaces(beanClass, currClass);
			currClass = currClass.getSuperclass();
		}

		this.typeDescriptorCache = new ConcurrentReferenceHashMap<>();
	}
	catch (IntrospectionException ex) {
		throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex);
	}
}
 
Example #5
Source File: CachedIntrospectionResults.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * @param beanClass the bean class to analyze
 * @throws BeansException in case of introspection failure
 */
private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
	try {
		if (logger.isTraceEnabled()) {
			logger.trace("Getting BeanInfo for class [" + beanClass.getName() + "]");
		}
		this.beanInfo = getBeanInfo(beanClass);

		if (logger.isTraceEnabled()) {
			logger.trace("Caching PropertyDescriptors for class [" + beanClass.getName() + "]");
		}
		this.propertyDescriptorCache = new LinkedHashMap<>();

		// This call is slow so we do it once.
		PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
		for (PropertyDescriptor pd : pds) {
			if (Class.class == beanClass &&
					("classLoader".equals(pd.getName()) ||  "protectionDomain".equals(pd.getName()))) {
				// Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
				continue;
			}
			if (logger.isTraceEnabled()) {
				logger.trace("Found bean property '" + pd.getName() + "'" +
						(pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]" : "") +
						(pd.getPropertyEditorClass() != null ?
								"; editor [" + pd.getPropertyEditorClass().getName() + "]" : ""));
			}
			pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
			this.propertyDescriptorCache.put(pd.getName(), pd);
		}

		// Explicitly check implemented interfaces for setter/getter methods as well,
		// in particular for Java 8 default methods...
		Class<?> currClass = beanClass;
		while (currClass != null && currClass != Object.class) {
			introspectInterfaces(beanClass, currClass);
			currClass = currClass.getSuperclass();
		}

		this.typeDescriptorCache = new ConcurrentReferenceHashMap<>();
	}
	catch (IntrospectionException ex) {
		throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex);
	}
}
 
Example #6
Source File: CachedIntrospectionResults.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * @param beanClass the bean class to analyze
 * @throws BeansException in case of introspection failure
 */
private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
	try {
		if (logger.isTraceEnabled()) {
			logger.trace("Getting BeanInfo for class [" + beanClass.getName() + "]");
		}

		BeanInfo beanInfo = null;
		for (BeanInfoFactory beanInfoFactory : beanInfoFactories) {
			beanInfo = beanInfoFactory.getBeanInfo(beanClass);
			if (beanInfo != null) {
				break;
			}
		}
		if (beanInfo == null) {
			// If none of the factories supported the class, fall back to the default
			beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses ?
					Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO) :
					Introspector.getBeanInfo(beanClass));
		}
		this.beanInfo = beanInfo;

		if (logger.isTraceEnabled()) {
			logger.trace("Caching PropertyDescriptors for class [" + beanClass.getName() + "]");
		}
		this.propertyDescriptorCache = new LinkedHashMap<String, PropertyDescriptor>();

		// This call is slow so we do it once.
		PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
		for (PropertyDescriptor pd : pds) {
			if (Class.class == beanClass &&
					("classLoader".equals(pd.getName()) ||  "protectionDomain".equals(pd.getName()))) {
				// Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
				continue;
			}
			if (logger.isTraceEnabled()) {
				logger.trace("Found bean property '" + pd.getName() + "'" +
						(pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]" : "") +
						(pd.getPropertyEditorClass() != null ?
								"; editor [" + pd.getPropertyEditorClass().getName() + "]" : ""));
			}
			pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
			this.propertyDescriptorCache.put(pd.getName(), pd);
		}

		this.typeDescriptorCache = new ConcurrentReferenceHashMap<PropertyDescriptor, TypeDescriptor>();
	}
	catch (IntrospectionException ex) {
		throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex);
	}
}
 
Example #7
Source File: KeyValueDelegate.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
public KeyValueDelegate(VaultOperations operations) {
	this(operations, ConcurrentReferenceHashMap::new);
}