org.apache.commons.collections4.map.ReferenceMap Java Examples

The following examples show how to use org.apache.commons.collections4.map.ReferenceMap. 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: AbstractTransaction.java    From ontopia with Apache License 2.0 6 votes vote down vote up
AbstractTransaction(String id, StorageAccessIF access) {
  this.id = id;
  this.access = access;
  this.mapping = access.getStorage().getMapping();

  // Map containing named queries
  this.querymap = new HashMap<String, QueryIF>();
  
  // Identity map - maintains the relationships between object
  // identities and the single(ton) instances used with the
  // transaction. This enforces the constraint that only one
  // instance per object identity should exist at a given time in a
  // transaction.
  
  // NOTE: Even though it's the keys that are garbage collected
  // there is a strict mapping between IdentityIF and PersistentIF
  // that lets us do this, i.e. the objects reference their
  // identities, so the identity will not be garbage collected as
  // long as the object is reachable.
  this.identity_map = new ReferenceMap<IdentityIF, PersistentIF>(AbstractReferenceMap.ReferenceStrength.HARD, AbstractReferenceMap.ReferenceStrength.SOFT);

  log.debug(getId() + ": Transaction created.");
  this.timestamp = System.currentTimeMillis();
}
 
Example #2
Source File: XmlStringBuffer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * inernal, clear cache
 */
private void clearCache()
{
  if(this.cache == null)
  {
    this.cache = new ReferenceMap();
  }
  else
  {
    this.cache.clear();
  }
}
 
Example #3
Source File: XmlStringBuffer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * inernal, clear cache
 */
private void clearCache()
{
  if(this.cache == null)
  {
    this.cache = new ReferenceMap();
  }
  else
  {
    this.cache.clear();
  }
}
 
Example #4
Source File: XmlStringBuffer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * internal
 *
 * @return  reference map
 */
private ReferenceMap getCache()
{
  if(this.cache == null)
  {
    this.cache = new ReferenceMap();
  }

  return this.cache;
}
 
Example #5
Source File: CastorUtil.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected Map<Object, XMLContext> getXmlContextCache(String contextCacheKey)
{
	Map<Object, XMLContext> xmlContextCache = 
			(Map<Object, XMLContext>) jasperReportsContext.getOwnValue(contextCacheKey);
	if (xmlContextCache == null)
	{
		//TODO lucianc prevent double cache creation?
		xmlContextCache = Collections.synchronizedMap(
				new ReferenceMap<Object, XMLContext>(ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.SOFT));//using soft values is safer
		jasperReportsContext.setValue(contextCacheKey, xmlContextCache);
	}
	return xmlContextCache;
}
 
Example #6
Source File: LocatorLookup.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public LocatorLookup(String qname, TransactionIF txn, TopicMapIF tm, int lrusize, E nullObject) {
  this.qname = qname;
  this.txn = txn;
  this.tm = tm;
  this.lrusize = lrusize;
  this.cache = new ReferenceMap<LocatorIF, E>(AbstractReferenceMap.ReferenceStrength.SOFT, AbstractReferenceMap.ReferenceStrength.HARD);
  this.lru = new LRUMap<LocatorIF, E>(lrusize);
  NULLOBJECT = nullObject;
}
 
Example #7
Source File: JRAbstractLRUVirtualizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected JRAbstractLRUVirtualizer(VirtualizationSerializer serializer, int maxSize)
{
	this.serializer = serializer;
	
	this.pagedIn = new Cache(maxSize);
	this.pagedOut = new ReferenceMap<String, Object>(ReferenceMap.ReferenceStrength.HARD, ReferenceMap.ReferenceStrength.WEAK);
	this.lastObjectRef = null;

	this.lastObjectMap = new ReferenceMap<JRVirtualizationContext, Object>(ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.WEAK);
	this.lastObjectSet = new ReferenceMap<Object, Boolean>(ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.HARD);
}
 
Example #8
Source File: StoreFactoryVirtualizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
public StoreFactoryVirtualizer(int maxSize, VirtualizerStoreFactory storeFactory)
{
	super(maxSize);

	this.storeFactory = storeFactory;
	
	this.contextStores = 
		new ReferenceMap<JRVirtualizationContext, VirtualizerStore>(
			ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.HARD
			);
}
 
Example #9
Source File: JRAbstractJavaCompiler.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static synchronized void putClassInCache(String className, Class<?> loadedClass)
{
	Object key = classCacheKey();
	Map<String,Class<?>> contextMap = classCache.get(key);
	if (contextMap == null)
	{
		contextMap = new ReferenceMap<String,Class<?>>(ReferenceMap.ReferenceStrength.HARD, ReferenceMap.ReferenceStrength.SOFT);
		classCache.put(key, contextMap);
	}
	contextMap.put(className, loadedClass);
}
 
Example #10
Source File: JRSingletonCache.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Map<String,T> getContextInstanceCache()
{
	Object contextKey = getContextKey();
	Map<String,T> contextCache = cache.get(contextKey);
	if (contextCache == null)
	{
		contextCache = new ReferenceMap<String,T>();
		cache.put(contextKey, contextCache);
	}
	return contextCache;
}
 
Example #11
Source File: QueryLookup.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public QueryLookup(String qname, TransactionIF txn, int lrusize, V nullObject) {
   this.qname = qname;
   this.txn = txn;
   this.cache = new ReferenceMap(AbstractReferenceMap.ReferenceStrength.SOFT, AbstractReferenceMap.ReferenceStrength.HARD);
   this.lru = new LRUMap(lrusize);
NULLOBJECT = nullObject;
 }
 
Example #12
Source File: MailRepositoryStoreBeanFactory.java    From james-project with Apache License 2.0 5 votes vote down vote up
@PostConstruct
@SuppressWarnings("unchecked")
public void init() throws Exception {

    LOGGER.info("JamesMailStore init...");

    repositories = new ReferenceMap();
    classes = new HashMap<>();
    defaultConfigs = new HashMap<>();
    List<HierarchicalConfiguration<ImmutableNode>> registeredClasses = configuration.configurationsAt("mailrepositories.mailrepository");
    for (HierarchicalConfiguration<ImmutableNode> registeredClass : registeredClasses) {
        registerRepository(registeredClass);
    }

}
 
Example #13
Source File: XmlValueHandlerUtils.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
private XmlValueHandlerUtils()
{
	cache = 
		new ReferenceMap<Object, List<XmlValueHandler>>(
			ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.HARD
			);
}
 
Example #14
Source File: BaseSaxParserFactory.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setGrammarPoolProperty(SAXParser parser, String poolClassName)
{
	try
	{
		Object cacheKey = getGrammarPoolCacheKey();
		
		// we're using thread local caches to avoid thread safety problems
		ThreadLocal<ReferenceMap<Object, Object>> grammarPoolCache = getGrammarPoolCache();
		ReferenceMap<Object, Object> cacheMap = grammarPoolCache.get();
		if (cacheMap == null)
		{
			cacheMap = new ReferenceMap<Object, Object>(ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.SOFT);
			grammarPoolCache.set(cacheMap);
		}
		
		Object grammarPool = cacheMap.get(cacheKey);
		if (grammarPool == null)
		{
			if (log.isDebugEnabled())
			{
				log.debug("Instantiating grammar pool of type " + poolClassName
						+ " for cache key " + cacheKey);
			}

			grammarPool = ClassUtils.instantiateClass(poolClassName, Object.class);
			cacheMap.put(cacheKey, grammarPool);
		}
		
		parser.setProperty(XERCES_PARSER_PROPERTY_GRAMMAR_POOL, grammarPool);
	}
	catch (Exception e)
	{
		if (log.isDebugEnabled())
		{
			log.debug("Error setting Xerces grammar pool of type " + poolClassName, e);
		}
	}
}
 
Example #15
Source File: XmlStringBuffer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * internal
 *
 * @return  reference map
 */
private ReferenceMap getCache()
{
  if(this.cache == null)
  {
    this.cache = new ReferenceMap();
  }

  return this.cache;
}
 
Example #16
Source File: JRReportSaxParserFactory.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected ThreadLocal<ReferenceMap<Object, Object>> getGrammarPoolCache()
{
	return GRAMMAR_POOL_CACHE;
}
 
Example #17
Source File: JGroupsCaches.java    From ontopia with Apache License 2.0 4 votes vote down vote up
private <K, V> Map<K, V> createSoftHashMap() {
  return new ReferenceMap<K, V>(AbstractReferenceMap.ReferenceStrength.SOFT, AbstractReferenceMap.ReferenceStrength.HARD);
}
 
Example #18
Source File: DefaultCaches.java    From ontopia with Apache License 2.0 4 votes vote down vote up
private <K, V> Map<K, V> createSoftHashMap() {
  return new ReferenceMap<K, V>(AbstractReferenceMap.ReferenceStrength.SOFT, AbstractReferenceMap.ReferenceStrength.HARD);
}
 
Example #19
Source File: JRSingletonCache.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a cache of singleton instances.
 * 
 * @param itf a interface or class that should be implemented by all classes cached by this object
 */
public JRSingletonCache(Class<T> itf)
{
	cache = new ReferenceMap<Object, Map<String,T>>(ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.SOFT);
	this.itf = itf;
}
 
Example #20
Source File: PrintSaxParserFactory.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected ThreadLocal<ReferenceMap<Object, Object>> getGrammarPoolCache()
{
	return GRAMMAR_POOL_CACHE;
}
 
Example #21
Source File: TemplateSaxParserFactory.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected ThreadLocal<ReferenceMap<Object, Object>> getGrammarPoolCache()
{
	return GRAMMAR_POOL_CACHE;
}
 
Example #22
Source File: JRFillCellContents.java    From jasperreports with GNU Lesser General Public License v3.0 3 votes vote down vote up
protected JRFillCellContents(JRFillCellContents cellContents, JRFillCloneFactory factory)
{
	super(cellContents, factory);
	
	defaultStyleProvider = cellContents.defaultStyleProvider;
	
	parentCell = cellContents.parentCell;
	cellType = cellContents.cellType;
	printElementOriginator = cellContents.printElementOriginator;
	
	lineBox = cellContents.getLineBox().clone(this);
	
	width = cellContents.width;
	height = cellContents.height;
	
	initStyle = cellContents.initStyle;
	
	initElements();
	
	initConditionalStyles();
	
	this.templateFrames = cellContents.templateFrames;
	
	this.originProvider = cellContents.originProvider;
	
	transformedContentsCache = new ReferenceMap<StretchedContents,JRFillCellContents>();
	boxContentsCache = new HashMap<BoxContents,JRFillCellContents>();
	clonePool = new JRClonePool(this, true, true);
	
	verticalPositionType = cellContents.verticalPositionType;
}
 
Example #23
Source File: JRFillCellContents.java    From jasperreports with GNU Lesser General Public License v3.0 3 votes vote down vote up
public JRFillCellContents(JRBaseFiller filler, JRCellContents cell, String cellType, 
		JRFillCrosstabObjectFactory factory)
{
	super(filler, cell, factory);
	
	defaultStyleProvider = factory.getDefaultStyleProvider();
	
	parentCell = cell;
	this.cellType = cellType;
	
	
	int elementId = filler.getFillContext().generateFillElementId();
	printElementOriginator = new DefaultPrintElementOriginator(elementId);
	
	lineBox = cell.getLineBox().clone(this);
	
	width = cell.getWidth();
	height = cell.getHeight();
	
	factory.registerDelayedStyleSetter(this, parentCell);
	
	initElements();
	
	initConditionalStyles();
	
	initTemplatesMap();
	
	this.originProvider = factory.getParentOriginProvider();
	setElementOriginProvider(this.originProvider);
	
	transformedContentsCache = new ReferenceMap<StretchedContents,JRFillCellContents>();
	boxContentsCache = new HashMap<BoxContents,JRFillCellContents>();
	clonePool = new JRClonePool(this, true, true);
}
 
Example #24
Source File: BaseSaxParserFactory.java    From jasperreports with GNU Lesser General Public License v3.0 votes vote down vote up
protected abstract ThreadLocal<ReferenceMap<Object, Object>> getGrammarPoolCache();