[JBoss Microcontainer Development] - Re: Optimizing ControllerState
by alesj
"adrian(a)jboss.org" wrote : The whole point is that you're supposed to be able to add/interpolate new states.
|
Sure, but that doesn't mean we should to create 2M immutable instances where only a hand full of them differ.
Not to mention huge contention on equals/hashCode.
Having some synched registry of those immutable instances,
who's equals/hashCode impl is O(1) op is what we need.
"adrian(a)jboss.org" wrote :
| The real problem is using an ad hoc shared list of states and having to find out where in
| the list you are everytime, i.e. are you trying to transistion to before
| or after the current state.
|
| Like we've discussed before, this logic goes away if you specify what
| transistions/path the context should go through.
| https://jira.jboss.org/jira/browse/JBKERNEL-48
|
| The only hard part is for backwards comapbility you've got to generate a path
| from the legacy shared states when somebody invokes
|
| change(ControllerContext, newControllerState);
|
| and similar for install() if the ControllerMode is AUTOMATIC.
|
| So I'd spend my time on JBKERNEL-48 rather than trying to fix the before/after
| stuff that is going to go away anyway.
I definitely agree JBKERNEL-48 is what we should have at the end,
but this doesn't change the fact that we need to change the actual
ControllerState impl to be a lot more optimal - instance # and compareTo.
CompareTo is, like you already mentioned, trickier with more generic transitions/path.
It might not even be able to compare, but that would mostly come from abusing api (e.g. wrong usage).
But still the new impl shouldn't be as slow as states.indexOf is/was,
some additional data/computation can easily be executed,
specially with limited number of instances flowing around.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260350#4260350
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260350
16 years, 5 months
[JBoss Microcontainer Development] - Optimizing ControllerState
by alesj
At AS6 meeting we came across some "shocking" ControllerState numbers. :-)
Number of created instances was big,
and the number of equals() and hashCode() invocations was just outrageous ~ 12M.
(if I remember the numbers correctly)
The equals/hash invocations are result of state comparison,
which is done via List::indexOf. (we keep the states in a list)
| protected int getStateIndex(ControllerState state, boolean allowNotFound)
| {
| if (state == null)
| throw new IllegalArgumentException("Null state");
|
| int stateIndex = states.indexOf(state);
| if (stateIndex < 0 && allowNotFound == false)
| throw new IllegalArgumentException("No such state " + state + " in states " + states);
|
| return stateIndex;
| }
|
So, each time we compare two states, which we do quite a lot,
we're checking it against the list's elements.
This definitely calls for some optimization,
specially as we only expect to have a few diff ControllerState instances.
We should have some CS registry to reuse existing immutable instances,
not to mention changing compare impl.
This is my (very) naive approach, hence some feedback welcome.
| Index: dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
| ===================================================================
| --- dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java (revision 91575)
| +++ dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java (working copy)
| @@ -265,6 +265,8 @@
| if (states.contains(state))
| return;
|
| + state.order(before);
| +
| if (before == null)
| {
| states.add(state);
| @@ -1973,16 +1975,12 @@
|
| public boolean isBeforeState(ControllerState state, ControllerState reference)
| {
| - int stateIndex = getStateIndex(state, true);
| - int referenceIndex = getStateIndex(reference, true);
| - return stateIndex < referenceIndex;
| + return state.compareTo(reference) < 0;
| }
|
| public boolean isAfterState(ControllerState state, ControllerState reference)
| {
| - int stateIndex = getStateIndex(state, true);
| - int referenceIndex = getStateIndex(reference, true);
| - return stateIndex > referenceIndex;
| + return state.compareTo(reference) > 0;
| }
|
| public Iterator<ControllerState> iterator()
| Index: dependency/src/main/java/org/jboss/dependency/spi/ControllerState.java
| ===================================================================
| --- dependency/src/main/java/org/jboss/dependency/spi/ControllerState.java (revision 91575)
| +++ dependency/src/main/java/org/jboss/dependency/spi/ControllerState.java (working copy)
| @@ -24,7 +24,9 @@
| import java.io.ObjectStreamException;
| import java.io.Serializable;
| import java.util.HashMap;
| +import java.util.List;
| import java.util.Map;
| +import java.util.ArrayList;
|
| import org.jboss.util.JBossObject;
| import org.jboss.util.JBossStringBuilder;
| @@ -33,43 +35,48 @@
| * Description of state.
| *
| * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
| + * @author <a href="ales.justin(a)jboss.com">Ales Justin</a>
| * @version $Revision$
| */
| -public class ControllerState extends JBossObject implements Serializable
| +public class ControllerState extends JBossObject implements Serializable, Comparable<ControllerState>
| {
| - private static final long serialVersionUID = 2L;
| + private static final long serialVersionUID = 3L;
|
| /** Error */
| - public static final ControllerState ERROR = new ControllerState("**ERROR**");
| + public static final ControllerState ERROR = new ControllerState("**ERROR**", -1);
|
| /** Not installed state */
| - public static final ControllerState NOT_INSTALLED = new ControllerState("Not Installed");
| + public static final ControllerState NOT_INSTALLED = new ControllerState("Not Installed", 0);
|
| /** Pre install state */
| - public static final ControllerState PRE_INSTALL = new ControllerState("PreInstall");
| + public static final ControllerState PRE_INSTALL = new ControllerState("PreInstall", 1);
|
| /** Described state */
| - public static final ControllerState DESCRIBED = new ControllerState("Described");
| + public static final ControllerState DESCRIBED = new ControllerState("Described", 2);
|
| /** Instantiated state */
| - public static final ControllerState INSTANTIATED = new ControllerState("Instantiated");
| + public static final ControllerState INSTANTIATED = new ControllerState("Instantiated", 3);
|
| /** Configured state */
| - public static final ControllerState CONFIGURED = new ControllerState("Configured");
| + public static final ControllerState CONFIGURED = new ControllerState("Configured", 4);
|
| /** Create state */
| - public static final ControllerState CREATE = new ControllerState("Create");
| + public static final ControllerState CREATE = new ControllerState("Create", 5);
|
| /** Start state */
| - public static final ControllerState START = new ControllerState("Start");
| + public static final ControllerState START = new ControllerState("Start", 6);
|
| /** Installed state */
| - public static final ControllerState INSTALLED = new ControllerState("Installed");
| + public static final ControllerState INSTALLED = new ControllerState("Installed", 7);
|
| /** The state string */
| protected final String stateString;
|
| + /** The dynamic order */
| + protected int order;
| +
| private static Map<String, ControllerState> values = new HashMap<String, ControllerState>();
| + private static List<ControllerState> states = new ArrayList<ControllerState>();
|
| static
| {
| @@ -88,12 +95,15 @@
| * Create a new state
| *
| * @param stateString the string representation
| + * @param order the order
| */
| - public ControllerState(String stateString)
| + private ControllerState(String stateString, int order)
| {
| if (stateString == null)
| throw new IllegalArgumentException("Null state string");
| +
| this.stateString = stateString;
| + this.order = order;
| }
|
| /**
| @@ -110,10 +120,16 @@
| {
| if (object == null || object instanceof ControllerState == false)
| return false;
| +
| ControllerState other = (ControllerState) object;
| - return stateString.equals(other.stateString);
| + return order == other.order;
| }
| -
| +
| + public int compareTo(ControllerState other)
| + {
| + return order - other.order;
| + }
| +
| public void toString(JBossStringBuilder buffer)
| {
| buffer.append(stateString);
| @@ -133,4 +149,56 @@
| {
| return values.get(stateString);
| }
| +
| + /**
| + * Get state instance.
| + *
| + * @param stateString the state string
| + * @return new state instance
| + */
| + public static ControllerState getInstance(String stateString)
| + {
| + if (stateString == null)
| + throw new IllegalArgumentException("Null state string.");
| +
| + ControllerState state = values.get(stateString);
| + if (state != null)
| + return state;
| +
| + state = new ControllerState(stateString, -1);
| + // cache it
| + values.put(stateString, state);
| + return state;
| + }
| +
| + /**
| + * Modify order.
| + *
| + * @param before the before ref
| + */
| + public void order(ControllerState before)
| + {
| + // do string, as we might not be properly ordered yet
| + for (ControllerState cs : states)
| + {
| + if (cs.stateString.equals(stateString))
| + return;
| + }
| +
| + if (before == null)
| + {
| + order = states.size();
| + states.add(this);
| + }
| + else
| + {
| + int index = states.indexOf(before);
| + order = index;
| + // shift others
| + for (int i = index; i < states.size(); i++)
| + states.get(i).order++;
| + // add this state
| + states.add(index, this);
| + }
| + }
| }
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260336#4260336
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260336
16 years, 5 months
[jBPM Development PVM] - Error in initializing object 'org.jbpm.pvm.internal.reposito
by swapnasangal
Hi All,
I have created a simle process.jpdl.xml using the version 4.1 and have executed using the Junit TestCase, its working fine,
The requirement in the project is I need to integrate the jbpm process flow in my module which I'm building my project using maven
so, i hav added the *.jpdl.xml and all the required class files and configuration files and jbpm.jar as dependency but getting the exception :
couldn't initialize object 'org.jbpm.pvm.internal.repository.RepositorySessionImpl
The following is the stack trace :
INFO: exception while executing command org.jbpm.pvm.internal.cmd.DeployCmd@a9c09e
org.jbpm.pvm.internal.wire.WireException: couldn't initialize object 'org.jbpm.pvm.internal.repository.RepositorySessionImp
l': couldn't construct new 'null' with args null
at org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor.initialize(ObjectDescriptor.java:233)
at org.jbpm.pvm.internal.wire.WireContext.performInitialization(WireContext.java:537)
at org.jbpm.pvm.internal.wire.WireContext.initialize(WireContext.java:499)
at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:453)
at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:441)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:421)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:331)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:707)
at org.jbpm.pvm.internal.env.BasicEnvironment.get(BasicEnvironment.java:139)
at org.jbpm.pvm.internal.env.BasicEnvironment.get(BasicEnvironment.java:130)
at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:46)
at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:33)
at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:54)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:46)
at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
at org.jbpm.pvm.internal.repository.DeploymentImpl.deploy(DeploymentImpl.java:89)
at com.nexant.mdm.jbpm.documentcollection.MdmJbpmClient.setUp(MdmJbpmClient.java:33)
at com.nexant.mdm.jbpm.documentcollection.MdmJbpmClient.initiateProcess(MdmJbpmClient.java:77)
at com.nexant.mdm.service.rp.events.task.de.documentevent.DocumentEventImpl.documentAvailable(DocumentEventImpl.jav
a:112)
at com.nexant.mdm.service.rp.events.task.de.documentevent.DocumentEventImplTest.testDocumentAvailable(DocumentEvent
ImplTest.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:308)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:879)
Caused by: org.jbpm.api.JbpmException: couldn't construct new 'null' with args null
at org.jbpm.pvm.internal.util.ReflectUtil.newInstance(ReflectUtil.java:224)
at org.jbpm.pvm.internal.util.ReflectUtil.newInstance(ReflectUtil.java:193)
at org.jbpm.pvm.internal.wire.descriptor.HibernateConfigurationDescriptor.construct(HibernateConfigurationDescripto
r.java:61)
at org.jbpm.pvm.internal.wire.WireContext.construct(WireContext.java:473)
at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:452)
at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:441)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:421)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:331)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:707)
at org.jbpm.pvm.internal.wire.descriptor.HibernateSessionFactoryDescriptor.construct(HibernateSessionFactoryDescrip
tor.java:57)
at org.jbpm.pvm.internal.wire.WireContext.construct(WireContext.java:473)
at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:452)
at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:441)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:421)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:331)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:707)
at org.jbpm.pvm.internal.env.BasicEnvironment.get(BasicEnvironment.java:139)
at org.jbpm.pvm.internal.env.BasicEnvironment.get(BasicEnvironment.java:130)
at org.jbpm.pvm.internal.wire.descriptor.HibernateSessionDescriptor.construct(HibernateSessionDescriptor.java:63)
at org.jbpm.pvm.internal.wire.WireContext.construct(WireContext.java:473)
at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:452)
at org.jbpm.pvm.internal.wire.WireContext.create(WireContext.java:441)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:421)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:331)
at org.jbpm.pvm.internal.wire.WireContext.get(WireContext.java:707)
at org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor.autoWire(ObjectDescriptor.java:294)
at org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor.initialize(ObjectDescriptor.java:225)
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260252#4260252
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260252
16 years, 5 months