[jboss-svn-commits] JBL Code SVN: r19039 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: common and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 17 14:59:57 EDT 2008
Author: tirelli
Date: 2008-03-17 14:59:57 -0400 (Mon, 17 Mar 2008)
New Revision: 19039
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
Log:
JBRULES-1507: adding option for statically caching objenesis
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2008-03-17 18:39:28 UTC (rev 19038)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2008-03-17 18:59:57 UTC (rev 19039)
@@ -17,9 +17,9 @@
package org.drools;
import java.io.Externalizable;
-import java.io.ObjectOutput;
import java.io.IOException;
import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -77,96 +77,100 @@
* drools.consequenceExceptionHandler = <qualified class name>
* drools.ruleBaseUpdateHandler = <qualified class name>
* drools.sessionClock = <qualified class name>
- *
+ * drools.useStaticObjenesis = <false|true>
+ *
*/
public class RuleBaseConfiguration
implements
Externalizable {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
- private ChainedProperties chainedProperties;
+ private ChainedProperties chainedProperties;
- private boolean immutable;
+ private boolean immutable;
- private boolean sequential;
- private SequentialAgenda sequentialAgenda;
+ private boolean sequential;
+ private SequentialAgenda sequentialAgenda;
- private boolean maintainTms;
- private boolean removeIdentities;
- private boolean shareAlphaNodes;
- private boolean shareBetaNodes;
- private boolean alphaMemory;
- private int alphaNodeHashingThreshold;
- private int compositeKeyDepth;
- private boolean indexLeftBetaMemory;
- private boolean indexRightBetaMemory;
- private AssertBehaviour assertBehaviour;
- private LogicalOverride logicalOverride;
- private String executorService;
- private ConsequenceExceptionHandler consequenceExceptionHandler;
- private String ruleBaseUpdateHandler;
- private Class< ? extends SessionClock> sessionClockClass;
+ private boolean maintainTms;
+ private boolean removeIdentities;
+ private boolean shareAlphaNodes;
+ private boolean shareBetaNodes;
+ private boolean alphaMemory;
+ private int alphaNodeHashingThreshold;
+ private int compositeKeyDepth;
+ private boolean indexLeftBetaMemory;
+ private boolean indexRightBetaMemory;
+ private AssertBehaviour assertBehaviour;
+ private LogicalOverride logicalOverride;
+ private String executorService;
+ private ConsequenceExceptionHandler consequenceExceptionHandler;
+ private String ruleBaseUpdateHandler;
+ private Class< ? extends SessionClock> sessionClockClass;
- private ConflictResolver conflictResolver;
+ private ConflictResolver conflictResolver;
- private boolean shadowProxy;
- private Map shadowProxyExcludes;
- private static final String STAR = "*";
+ private boolean shadowProxy;
+ private Map shadowProxyExcludes;
+ private boolean useStaticObjenesis;
- private NodeInstanceFactoryRegistry processNodeInstanceFactoryRegistry;
+ private static final String STAR = "*";
- private transient ClassLoader classLoader;
+ private NodeInstanceFactoryRegistry processNodeInstanceFactoryRegistry;
+ private transient ClassLoader classLoader;
+
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(chainedProperties);
- out.writeBoolean(immutable);
- out.writeBoolean(sequential);
- out.writeObject(sequentialAgenda);
- out.writeBoolean(maintainTms);
- out.writeBoolean(removeIdentities);
- out.writeBoolean(shareAlphaNodes);
- out.writeBoolean(shareBetaNodes);
- out.writeBoolean(alphaMemory);
- out.writeInt(alphaNodeHashingThreshold);
- out.writeInt(compositeKeyDepth);
- out.writeBoolean(indexLeftBetaMemory);
- out.writeBoolean(indexRightBetaMemory);
- out.writeObject(assertBehaviour);
- out.writeObject(logicalOverride);
- out.writeObject(executorService);
- out.writeObject(consequenceExceptionHandler);
- out.writeObject(ruleBaseUpdateHandler);
- out.writeObject(sessionClockClass);
- out.writeObject(conflictResolver);
- out.writeBoolean(shadowProxy);
- out.writeObject(shadowProxyExcludes);
- out.writeObject(processNodeInstanceFactoryRegistry);
+ out.writeObject( chainedProperties );
+ out.writeBoolean( immutable );
+ out.writeBoolean( sequential );
+ out.writeObject( sequentialAgenda );
+ out.writeBoolean( maintainTms );
+ out.writeBoolean( removeIdentities );
+ out.writeBoolean( shareAlphaNodes );
+ out.writeBoolean( shareBetaNodes );
+ out.writeBoolean( alphaMemory );
+ out.writeInt( alphaNodeHashingThreshold );
+ out.writeInt( compositeKeyDepth );
+ out.writeBoolean( indexLeftBetaMemory );
+ out.writeBoolean( indexRightBetaMemory );
+ out.writeObject( assertBehaviour );
+ out.writeObject( logicalOverride );
+ out.writeObject( executorService );
+ out.writeObject( consequenceExceptionHandler );
+ out.writeObject( ruleBaseUpdateHandler );
+ out.writeObject( sessionClockClass );
+ out.writeObject( conflictResolver );
+ out.writeBoolean( shadowProxy );
+ out.writeObject( shadowProxyExcludes );
+ out.writeObject( processNodeInstanceFactoryRegistry );
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- chainedProperties = (ChainedProperties)in.readObject();
- immutable = in.readBoolean();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ chainedProperties = (ChainedProperties) in.readObject();
+ immutable = in.readBoolean();
sequential = in.readBoolean();
- sequentialAgenda = (SequentialAgenda)in.readObject();
+ sequentialAgenda = (SequentialAgenda) in.readObject();
maintainTms = in.readBoolean();
removeIdentities = in.readBoolean();
shareAlphaNodes = in.readBoolean();
shareBetaNodes = in.readBoolean();
alphaMemory = in.readBoolean();
- alphaNodeHashingThreshold = in.readInt();
- compositeKeyDepth = in.readInt();
+ alphaNodeHashingThreshold = in.readInt();
+ compositeKeyDepth = in.readInt();
indexLeftBetaMemory = in.readBoolean();
indexRightBetaMemory = in.readBoolean();
- assertBehaviour = (AssertBehaviour)in.readObject();
- logicalOverride = (LogicalOverride)in.readObject();
- executorService = (String)in.readObject();
- consequenceExceptionHandler = (ConsequenceExceptionHandler)in.readObject();
- ruleBaseUpdateHandler = (String)in.readObject();
- sessionClockClass = (Class< ? extends SessionClock>)in.readObject();
- conflictResolver = (ConflictResolver)in.readObject();
+ assertBehaviour = (AssertBehaviour) in.readObject();
+ logicalOverride = (LogicalOverride) in.readObject();
+ executorService = (String) in.readObject();
+ consequenceExceptionHandler = (ConsequenceExceptionHandler) in.readObject();
+ ruleBaseUpdateHandler = (String) in.readObject();
+ sessionClockClass = (Class< ? extends SessionClock>) in.readObject();
+ conflictResolver = (ConflictResolver) in.readObject();
shadowProxy = in.readBoolean();
- shadowProxyExcludes = (Map)in.readObject();
- processNodeInstanceFactoryRegistry = (NodeInstanceFactoryRegistry)in.readObject();
+ shadowProxyExcludes = (Map) in.readObject();
+ processNodeInstanceFactoryRegistry = (NodeInstanceFactoryRegistry) in.readObject();
}
/**
@@ -300,6 +304,8 @@
setSessionClockClass( this.chainedProperties.getProperty( "drools.sessionClock",
SessionPseudoClock.class.getName() ) );
+ setUseStaticObjenesis( Boolean.valueOf( this.chainedProperties.getProperty( "drools.useStaticObjenesis",
+ "false" ) ).booleanValue() );
}
/**
@@ -570,7 +576,7 @@
RuleBaseConfiguration.class ) );
Map<Class< ? extends Node>, NodeInstanceFactory> map = (Map<Class< ? extends Node>, NodeInstanceFactory>) MVEL.eval( content,
- new HashMap() );
+ new HashMap() );
if ( map != null ) {
for ( Entry<Class< ? extends Node>, NodeInstanceFactory> entry : map.entrySet() ) {
@@ -638,6 +644,15 @@
return this.shadowProxy;
}
+ public boolean isUseStaticObjenesis() {
+ return useStaticObjenesis;
+ }
+
+ public void setUseStaticObjenesis(boolean useStaticObjenesis) {
+ checkCanChange(); // throws an exception if a change isn't possible;
+ this.useStaticObjenesis = useStaticObjenesis;
+ }
+
public ClassLoader getClassLoader() {
return classLoader;
}
@@ -747,27 +762,27 @@
private int value;
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- value = in.readInt();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ value = in.readInt();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(value);
+ out.writeInt( value );
}
public AssertBehaviour() {
}
+
private AssertBehaviour(final int value) {
this.value = value;
}
public boolean equals(Object obj) {
- if (obj == this)
- return true;
- else if (obj instanceof AssertBehaviour) {
- AssertBehaviour that = (AssertBehaviour)obj;
+ if ( obj == this ) return true;
+ else if ( obj instanceof AssertBehaviour ) {
+ AssertBehaviour that = (AssertBehaviour) obj;
return value == that.value;
}
@@ -810,12 +825,13 @@
private int value;
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- value = in.readInt();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ value = in.readInt();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(value);
+ out.writeInt( value );
}
public LogicalOverride() {
@@ -848,12 +864,11 @@
}
public boolean equals(Object obj) {
- if (obj == this) {
+ if ( obj == this ) {
return true;
+ } else if ( obj instanceof LogicalOverride ) {
+ return value == ((LogicalOverride) obj).value;
}
- else if (obj instanceof LogicalOverride) {
- return value == ((LogicalOverride)obj).value;
- }
return false;
}
@@ -872,12 +887,13 @@
private int value;
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- value = in.readInt();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ value = in.readInt();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(value);
+ out.writeInt( value );
}
public SequentialAgenda() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-03-17 18:39:28 UTC (rev 19038)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-03-17 18:59:57 UTC (rev 19039)
@@ -16,6 +16,23 @@
* limitations under the License.
*/
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.locks.ReentrantLock;
+
import org.drools.PackageIntegrationException;
import org.drools.RuleBase;
import org.drools.RuleBaseConfiguration;
@@ -25,7 +42,6 @@
import org.drools.event.RuleBaseEventListener;
import org.drools.event.RuleBaseEventSupport;
import org.drools.objenesis.Objenesis;
-import org.drools.objenesis.ObjenesisStd;
import org.drools.process.core.Process;
import org.drools.rule.CompositePackageClassLoader;
import org.drools.rule.DialectDatas;
@@ -38,24 +54,8 @@
import org.drools.spi.ExecutorServiceFactory;
import org.drools.spi.FactHandleFactory;
import org.drools.util.ObjectHashSet;
+import org.drools.util.ObjenesisFactory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.locks.ReentrantLock;
-
/**
* Implementation of <code>RuleBase</code>.
*
@@ -88,7 +88,7 @@
protected transient MapBackedClassLoader classLoader;
private transient Objenesis objenesis;
-
+
/** The fact handle factory. */
protected FactHandleFactory factHandleFactory;
@@ -275,13 +275,17 @@
}
}
- /**
- * Creates Objenesis instance for the RuleBase.
- * @return a standart Objenesis instanse with caching turned on.
- */
- protected Objenesis createObjenesis() {
- return new ObjenesisStd( true );
- }
+ /**
+ * Creates Objenesis instance for the RuleBase.
+ * @return a standart Objenesis instanse with caching turned on.
+ */
+ protected Objenesis createObjenesis() {
+ if( this.config.isUseStaticObjenesis() ) {
+ return ObjenesisFactory.getStaticObjenesis();
+ } else {
+ return ObjenesisFactory.getDefaultObjenesis();
+ }
+ }
private void populateTypeDeclarationMaps() {
this.classTypeDeclaration = new HashMap<Class<?>, TypeDeclaration>();
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java (from rev 19038, labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java 2008-03-17 18:59:57 UTC (rev 19039)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2008 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.
+ *
+ * Created on Mar 17, 2008
+ */
+package org.drools.util;
+
+import java.io.Serializable;
+
+import org.drools.objenesis.Objenesis;
+import org.drools.objenesis.ObjenesisStd;
+
+/**
+ * A factory interface for Objenesis instances
+ *
+ * @author etirelli
+ */
+public class ObjenesisFactory implements Serializable {
+
+ private static final long serialVersionUID = 969174504278340793L;
+ private static final Objenesis OBJENESIS_INSTANCE = null;
+
+ private ObjenesisFactory() {}
+
+ /**
+ * Returns a statically cached objenesis instance
+ */
+ public static Objenesis getStaticObjenesis() {
+ if( OBJENESIS_INSTANCE == null ) {
+ new ObjenesisStd(true);
+ }
+ return OBJENESIS_INSTANCE;
+ }
+
+ /**
+ * Returns a newly instantiated objenesis instance
+ */
+ public static Objenesis getDefaultObjenesis() {
+ return new ObjenesisStd(true);
+ }
+
+}
More information about the jboss-svn-commits
mailing list