[jboss-svn-commits] JBL Code SVN: r36535 - labs/jbossrules/soa_branches/BRMS-5.0.2-GA_BRMS-532_BRMS-533/drools-core/src/main/java/org/drools/common.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jan 14 15:58:24 EST 2011
Author: tsurdilovic
Date: 2011-01-14 15:58:24 -0500 (Fri, 14 Jan 2011)
New Revision: 36535
Modified:
labs/jbossrules/soa_branches/BRMS-5.0.2-GA_BRMS-532_BRMS-533/drools-core/src/main/java/org/drools/common/ObjectTypeConfigurationRegistry.java
Log:
BRMS-535: Fix for BRMS-532 and BRMS-533
Modified: labs/jbossrules/soa_branches/BRMS-5.0.2-GA_BRMS-532_BRMS-533/drools-core/src/main/java/org/drools/common/ObjectTypeConfigurationRegistry.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.0.2-GA_BRMS-532_BRMS-533/drools-core/src/main/java/org/drools/common/ObjectTypeConfigurationRegistry.java 2011-01-14 20:57:24 UTC (rev 36534)
+++ labs/jbossrules/soa_branches/BRMS-5.0.2-GA_BRMS-532_BRMS-533/drools-core/src/main/java/org/drools/common/ObjectTypeConfigurationRegistry.java 2011-01-14 20:58:24 UTC (rev 36535)
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.drools.common;
import java.io.Serializable;
@@ -2,4 +18,4 @@
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
@@ -12,15 +28,17 @@
import org.drools.rule.EntryPoint;
public class ObjectTypeConfigurationRegistry implements Serializable {
+ private static final long serialVersionUID = 510l;
+
private InternalRuleBase ruleBase;
- private Map<Object, ObjectTypeConf> typeConfMap;
+ private ConcurrentMap<Object, ObjectTypeConf> typeConfMap;
public ObjectTypeConfigurationRegistry(InternalRuleBase ruleBase ) {
super();
this.ruleBase = ruleBase;
- this.typeConfMap = new HashMap<Object, ObjectTypeConf>();
+ this.typeConfMap = new ConcurrentHashMap<Object, ObjectTypeConf>();
}
@@ -37,14 +55,8 @@
// first see if it's a ClassObjectTypeConf
ObjectTypeConf objectTypeConf = null;
- Class cls = null;
- if ( object instanceof Fact ) {
- String key = ((Fact) object).getFactTemplate().getName();
- objectTypeConf = (ObjectTypeConf) this.typeConfMap.get( key );
- } else {
- cls = object.getClass();
- objectTypeConf = this.typeConfMap.get( cls );
- }
+ Object key = ( object instanceof Fact ) ? ((Fact) object).getFactTemplate().getName() : object.getClass();
+ objectTypeConf = this.typeConfMap.get( key );
// it doesn't exist, so create it.
if ( objectTypeConf == null ) {
@@ -52,16 +64,17 @@
objectTypeConf = new FactTemplateTypeConf( entrypoint,
((Fact) object).getFactTemplate(),
this.ruleBase );
- this.typeConfMap.put( ((Fact) object).getFactTemplate().getName(),
- objectTypeConf );
} else {
objectTypeConf = new ClassObjectTypeConf( entrypoint,
- cls,
+ (Class<?>) key,
this.ruleBase );
- this.typeConfMap.put( cls, objectTypeConf );
}
}
-
+ ObjectTypeConf existing = this.typeConfMap.putIfAbsent( key, objectTypeConf );
+ if ( existing != null ) {
+ // Raced, take the (now) existing.
+ objectTypeConf = existing;
+ }
return objectTypeConf;
}
More information about the jboss-svn-commits
mailing list