Skip to content

Commit

Permalink
BeanDescriptionCache is not supposed to be shared across configurators
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Mar 29, 2016
1 parent 6354b7e commit 412fd07
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 65 deletions.
Expand Up @@ -36,7 +36,7 @@

public abstract class GenericConfigurator extends ContextAwareBase {

private final BeanDescriptionCache beanDescriptionCache=new BeanDescriptionCache();
private final BeanDescriptionCache beanDescriptionCache = new BeanDescriptionCache();

protected Interpreter interpreter;

Expand Down Expand Up @@ -103,12 +103,11 @@ public final void doConfigure(InputStream inputStream) throws JoranException {
doConfigure(new InputSource(inputStream));
}


protected BeanDescriptionCache getBeanDescriptionCache() {
return beanDescriptionCache;
}
return beanDescriptionCache;
}

protected abstract void addInstanceRules(RuleStore rs);
protected abstract void addInstanceRules(RuleStore rs);

protected abstract void addImplicitRules(Interpreter interpreter);

Expand All @@ -135,9 +134,9 @@ protected void buildInterpreter() {
public final void doConfigure(final InputSource inputSource) throws JoranException {

long threshold = System.currentTimeMillis();
// if (!ConfigurationWatchListUtil.wasConfigurationWatchListReset(context)) {
// informContextOfURLUsedForConfiguration(getContext(), null);
// }
// if (!ConfigurationWatchListUtil.wasConfigurationWatchListReset(context)) {
// informContextOfURLUsedForConfiguration(getContext(), null);
// }
SaxEventRecorder recorder = new SaxEventRecorder(context);
recorder.recordEvents(inputSource);
doConfigure(recorder.saxEventList);
Expand Down
Expand Up @@ -33,7 +33,6 @@
*/
public class NestedBasicPropertyIA extends ImplicitAction {


// We use a stack of IADataForBasicProperty objects in order to
// support nested elements which are handled by the same NestedBasicPropertyIA instance.
// We push a IADataForBasicProperty instance in the isApplicable method (if the
Expand All @@ -42,10 +41,11 @@ public class NestedBasicPropertyIA extends ImplicitAction {
// be followed by the corresponding pop.
Stack<IADataForBasicProperty> actionDataStack = new Stack<IADataForBasicProperty>();

private final BeanDescriptionCache beanDescriptionCache;
public NestedBasicPropertyIA(BeanDescriptionCache beanDescriptionCache) {
this.beanDescriptionCache=beanDescriptionCache;
}
private final BeanDescriptionCache beanDescriptionCache;

public NestedBasicPropertyIA(BeanDescriptionCache beanDescriptionCache) {
this.beanDescriptionCache = beanDescriptionCache;
}

public boolean isApplicable(ElementPath elementPath, Attributes attributes, InterpretationContext ec) {
// System.out.println("in NestedSimplePropertyIA.isApplicable [" + pattern +
Expand All @@ -58,7 +58,7 @@ public boolean isApplicable(ElementPath elementPath, Attributes attributes, Inte
}

Object o = ec.peekObject();
PropertySetter parentBean = new PropertySetter(beanDescriptionCache,o);
PropertySetter parentBean = new PropertySetter(beanDescriptionCache, o);
parentBean.setContext(context);

AggregationType aggregationType = parentBean.computeAggregationType(nestedElementTagName);
Expand Down
Expand Up @@ -7,34 +7,32 @@
*
* Cache for {@link BeanDescription} instances. All the cache users which use
* the same instance of BeanDescriptionCache can profit from each others cached
* bean descriptions. The cache is thread safe.
* bean descriptions.
*
* <p>The cache is not thread-safe and should not be shared across configurator instances.
*
* @author urechm
*
*/
public class BeanDescriptionCache {

private Map<Class<?>, BeanDescription> classToBeanDescription = new HashMap<Class<?>, BeanDescription>();
private Map<Class<?>, BeanDescription> classToBeanDescription = new HashMap<Class<?>, BeanDescription>();

/**
* Returned bean descriptions are hold in a cache. If the cache does not
* contain a description for a given class, a new bean description is
* created and put in the cache, before it is returned.
*
* @param clazz
* to get a bean description for.
* @return a bean description for the given class.
*/
public BeanDescription getBeanDescription(Class<?> clazz) {
synchronized (classToBeanDescription) { // avoid race conditions on the
// map
if (!classToBeanDescription.containsKey(clazz)) {
BeanDescription beanDescription = BeanDescriptionFactory.INSTANCE
.create(clazz);
classToBeanDescription.put(clazz, beanDescription);
}
return classToBeanDescription.get(clazz);
}
}
/**
* Returned bean descriptions are hold in a cache. If the cache does not
* contain a description for a given class, a new bean description is
* created and put in the cache, before it is returned.
*
* @param clazz
* to get a bean description for.
* @return a bean description for the given class.
*/
public BeanDescription getBeanDescription(Class<?> clazz) {
if (!classToBeanDescription.containsKey(clazz)) {
BeanDescription beanDescription = BeanDescriptionFactory.INSTANCE.create(clazz);
classToBeanDescription.put(clazz, beanDescription);
}
return classToBeanDescription.get(clazz);
}

}
Expand Up @@ -6,11 +6,10 @@
<file>mylog.txt</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>60</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
<fileNamePattern>mylog-%d{yyyy-MM-dd'T'HHmmss}.%i.txt</fileNamePattern>
<maxFileSize>100</maxFileSize>
<maxHistory>2</maxHistory>
<totalSizeCap>200</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%msg%n</pattern>
Expand Down

This file was deleted.

0 comments on commit 412fd07

Please sign in to comment.