[JBoss jBPM] - Action ; Token.signal( ... ) ; Exception: locked tokens
by JimKnopf
Hi again,
I am calling an action and in this action i am fire a Rule from JRules. Based on the result of this rule i want to use a transition ( token.signal( "xxx" ) ).
But when i do this, i get an Exception. Is it not possible to use use token.signal in an action? And then, how should i realise actions in which i want to move to a next token? Is it only Possible with DecicionHandlers?
The Exception:
anonymous wrote :
| org.jbpm.JbpmException: can't continue execution on locked tokens. signalling the same token that executes an action is not allowed
| at org.jbpm.graph.exe.Token.signal(Token.java:164)
| at org.jbpm.graph.exe.Token.signal(Token.java:137)
|
| </decision>
| <decision name="SGA">
| <event type="node-enter">
| <action name="checkSGA" class="actions.DefaultRuleAction">
| <ruleFile>etr2.drl</ruleFile>
| <transitionName>t_sga a</transitionName>
| <transitionName_False>t_sga c</transitionName_False>
| </action>
| </event>
| <transition name="t_sga a" to="SGA A"></transition>
| <transition name="t_sga b" to="SGA B"></transition>
| <transition name="t_sga c" to="SGA C"></transition>
| </decision>
| <state name="SGA A">
|
Action:
| public class DefaultRuleAction extends RuleAction {
| private static final long serialVersionUID = 8459834862286126414L;
|
| //Name der Variablen die in der Action beruecksichtigt werden.
| public List objectNames = null;
| public String transitionName = null;
| public String transitionName_False = null;
|
| public void execute( ExecutionContext executionContext) throws Exception {
| // TODO Auto-generated method stub
| System.err.println("My Timer-Rule-Action!");
|
| if (this.ruleFile == null) {
| System.err.println("Es wurde kein Rule-File angegeben.");
| // TODO String aus einer Property laden.
| return;
| }
|
| // load up the RuleBase
| WorkingMemory workingMemory = null;
| try {
| RuleBase ruleBase = readRule(this.ruleFile);
|
| workingMemory = this.generateWorkingMemory( ruleBase );
|
| this.assertObjectsIn( workingMemory, executionContext );
| workingMemory.fireAllRules();
|
| if( RuleAction.getResultFrom( workingMemory ) == true ){
| if(this.transitionName != null){
| executionContext.getToken().signal( transitionName );
| }
| }else{
| if(this.transitionName_False != null){
| executionContext.getToken().signal( transitionName_False );
| }
| }
|
| } catch (FileNotFoundException fnfe) {
| System.err.println("Es wurde ein falsches Rule-File angegeben.");
| fnfe.printStackTrace();
| // TODO String aus einer Property laden.
| } catch (MissingRuleResultException mrre){
| System.err.println("Es wurde kein RuleResult-Object im WorkingMemory der Regel gefunden.");
| mrre.printStackTrace();
| // TODO String aus einer Property laden.
| } catch (Exception e){
| System.err.println("Rule-Base konnte nicht angelegt werden.");
| e.printStackTrace();
| // TODO String aus einer Property laden.
| } finally{
| if(workingMemory != null)
| workingMemory.dispose();
| }
|
| //ArcaViaController.getInstance().cancelTimer( executionContext.getTimer() );
|
| }
|
|
| public abstract class RuleAction implements ActionHandler{
| /* Name der Variablen des Workflows welche in das WorkingMemory
| der Regel eingepflegt werden sollen.*/
| protected List objectNames = null;
|
| protected String ruleFile = null;
| private RuleResult ruleResult = new RuleResult();
|
| /**
| * Please note that this is the "low level" rule assembly API.
| * @throws Exception
| */
| protected static RuleBase readRule(String ruleFileLocation) throws Exception{
| // ruleFileLocation = "src" +
| // System.getProperty("file.separator") +
| // "rules" +
| // System.getProperty("file.separator") +
| // ruleFileLocation;
|
| System.err.println( ruleFileLocation );
|
| //read in the source
| Reader source = null;
| try{
| source = new InputStreamReader( RuleAction.class.getResourceAsStream( "/"+ruleFileLocation ) );
| // source = new InputStreamReader( new FileInputStream( new File(ruleFileLocation) ) );
|
| }catch( Exception e ){
| throw new FileNotFoundException();
| }
|
| //optionally read in the DSL (if you are using it).
| //Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );
|
| //Use package builder to build up a rule package.
| //An alternative lower level class called "DrlParser" can also be used...
|
| DrlParser parser = new DrlParser();
| PackageDescr packageDescr = parser.parse( source);
|
| /*
| * Wenn der default PackageBuilder eine Exception erzeugt (was er tat),
| * soll man ihn dann durch diese Code-Zeilen ersetzen laut der JBoss wiki Seite
| */
| PackageBuilderConfiguration pkgBuilderCfg = new PackageBuilderConfiguration();
| pkgBuilderCfg.setCompiler(PackageBuilderConfiguration.JANINO);
| PackageBuilder builder = new PackageBuilder(pkgBuilderCfg);
|
|
| //default PackageBuilder
| //PackageBuilder builder = new PackageBuilder();
|
| //this wil parse and compile in one step
| //NOTE: There are 2 methods here, the one argument one is for normal DRL.
| //builder.addPackageFromDrl( source );
| builder.addPackage(packageDescr);
|
| //Use the following instead of above if you are using a DSL:
| //builder.addPackageFromDrl( source, dsl );
|
| //get the compiled package (which is serializable)
| Package pkg = builder.getPackage();
|
| //add the package to a rulebase (deploy the rule package).
| RuleBase ruleBase = RuleBaseFactory.newRuleBase();
| ruleBase.addPackage( pkg );
| return ruleBase;
| }
|
| /**
| * Lädt aus dem uebergebenen WorkingMemory ein RuleResult-Object und
| * liefert den Result-Wert von diesem Object zurueck.
| * Dieser Result-Wert kann in einer Regel dazu verwendet werden,
| * ein Ergebniss zurueck zu liefern (zur Zeit nur true oder false).
| *
| * @param wm WorkingMemory aus welchem das RuleResult-Object geprueft werden soll.
| * @return Den Result-Wert des RuleResult-Objectes in dem uebergeben WorkingMemory.
| * @throws MissingRuleResultException Es gibt kein RuleResult-Object im uebergebenen WorkingMemory.
| */
| protected static boolean getResultFrom( WorkingMemory wm ) throws MissingRuleResultException{
| // if( wm == null )
| // throw new NullPointerException();
|
| List ruleResults = wm.getObjects( RuleResult.class );
|
| if( ruleResults.size() < 1 )
| throw new MissingRuleResultException();
|
| RuleResult rs = (RuleResult)ruleResults.get(0);
| return rs.getResult();
|
| }
|
| /**
| * Lädt das RuleResult Object in den WorkingMemory
| * so das man Ihn später in der Rule verwenden kann und
| * das in Ihm stehende Ergebniss der Regel mit der Methode
| * <code>getResultFrom(WorkingMemory wm)</code> auslesen kann.
| *
| * @param wm WorkingMemory welches mit einem RuleResult Object vorbereitet werden soll.
| */
| protected void prepareWorkingMemory( WorkingMemory wm ){
| // if( wm == null )
| // throw new NullPointerException();
| wm.assertObject( this.ruleResult );
| }
|
| /**
| * Erzeugt einen neuen WorkingMemory in der uebergebenen RuleBase und
| * ruft fuer diesen dann <code>prepareWorkingMemory( WorkingMemory wm )</code>
| * auf um den WorkingMemory mit dem RuleResult-Object zu beladen.
| *
| * @param ruleBase RuleBase in welchem das neue WorkingMemory erzeugt werden soll.
| * @return Das Erzeugte WorkingMemory.
| */
| protected WorkingMemory generateWorkingMemory( RuleBase ruleBase){
| WorkingMemory wm = ruleBase.newWorkingMemory();
| this.prepareWorkingMemory( wm );
|
| return wm;
| }
|
| /**
| * Lädt die Variablen des Workflows welche der Action bei Ihrem Aufruf
| * durch den Workflow uebergeben wurden in den WorkingMemory der Regel.
| *
| * @param wm WorkingMemory welcher mit den Objecten beladen werden soll.
| * @param executionContext Context mittels welcher die Variablen enthaelt.
| */
| protected void assertObjectsIn( WorkingMemory wm, ExecutionContext executionContext ){
|
| if (objectNames != null) {
| // Ausgewählte Variablen einladen
| ContextInstance ci = executionContext.getContextInstance();
| Iterator it = objectNames.iterator();
| while (it.hasNext()) {
| String objectName = (String) it.next();
| wm.assertObject(ci.getVariable(objectName));
| }
| }/*
| * Zu gefährlich in der Handhabung daher deaktiviert else{ //
| * Alle Variablen einladen wenn keine uebergeben wurden
| * ContextInstance ci = executionContext.getContextInstance();
| * Iterator it = ci.getVariables().entrySet().iterator();
| * while(it.hasNext()){ workingMemory.assertObject( it.next() ); } }
| */
|
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3989613#3989613
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3989613
19Â years, 5Â months
[JBoss Seam] - Re: Seam 1.1 & Tomahawk Datatable
by Newlukai
Sure. Here we go:
The session bean:
@Stateful
| @Scope(ScopeType.SESSION)
| @LoggedIn
| @Name("searchTestaction")
| public class SearchTestactionAction implements Serializable, SearchTestaction {
| @PersistenceContext(unitName = "aresDatabase")
| private transient EntityManager em;
|
| @In(required=false)
| private Testaction testaction;
|
| private List<Testaction> foundTestactions;
| @DataModelSelection
| @Out(required=false, scope=ScopeType.SESSION)
| private Testaction foundTestaction;
| //@DataModelSelectionIndex workaround
| private int foundTestactionIndex;
|
| @In(required=false)
| private Release selectedRelease;
|
| private String sortColumn = "id";
| private boolean ascending = true;
|
| @Factory("foundTestactions")
| public String search() {
| //omitted: generate the query
|
| if(query.length() != 0) {
| if(selectedRelease != null) {
| addPrefix(query);
| query.append("TACT_REL_ID=");
| query.append(selectedRelease.getID());
| }
| foundTestactions = EMHelper.execQuery(em, "from Testaction " + query.toString() + " order by TACT_ID asc");
| Collections.sort(foundTestactions, new TestactionComparator(sortColumn, ascending));
| }
|
| return "search";
| }
|
| @DataModel
| public List<Testaction> getFoundTestactions() {
| return foundTestactions;
| }
The page with a search form and a result list:
<ui:define name="content">
| <h1>#{ares_messages.header_searchTestaction}</h1>
| <h:form>
| <div id="errors"><h:messages layout="table" /></div>
| <div class="buttonLine">
| <h:outputText rendered="#{not empty searchTestaction.foundTestactions}"
| value="#{ares_messages.label_search_displaySearchForm}"
| onclick="switchVisibility('searchForm'); this.style.display='none';" styleClass="button"
| style="margin-right: 30px; padding: 5px; cursor: pointer;" />
| <h:commandButton action="#{searchTestaction.search}" image="img/find.gif" styleClass="graphical"
| style="margin-left: 0px; margin-right: 15px;" title="#{ares_messages.tooltip_searchTestaction}" />
| </div>
|
| <div id="release">
| <h:outputText value="#{ares_messages.filter_release}: " />
| <h:selectOneMenu value="#{releaseSelector.selectedReleaseNumber}">
| <f:selectItems value="#{releaseSelector.releaseItems}" />
| </h:selectOneMenu>
| </div>
|
| <div id="searchForm" style="display: #{empty searchTestaction.foundTestactions ? 'block' : 'none'};">
|
| ....
|
|
| <t:dataTable var="testaction_var"
| value="#{foundTestactions}"
| id="foundTestactionsTable"
| renderedIfEmpty="false"
| sortColumn="#{searchTestaction.sortColumn}"
| sortAscending="#{searchTestaction.ascending}"
| preserveSort="true"
| rows="20">
| <f:facet name="header">
| <h:outputText value="#{ares_messages.label_ResultCount}: #{foundTestactions.rowCount}" />
| </f:facet>
This ocde adresses the first problem I mentioned. The second problem occurs here:
Bean:
@Stateful
| @Scope(ScopeType.SESSION)
| @LoggedIn
| @Name("testactionValidator")
| public class TestactionValidatorAction extends TestactionHandling implements Serializable, TestactionValidator {
| @In(required=false)
| private Release selectedRelease;
|
| @In(required=false)
| private User selectedUser;
|
| private Long lastSelectedReleaseID;
| private String lastSelectedUserID;
|
| @Factory("testactionsForValidator")
| public void initTestactions() {
| if(hasAFilterChanged() || shouldRefresh() || testactions == null) {
| StringBuffer filter = new StringBuffer();
| if(selectedRelease != null) {
| filter.append(" and TACT_REL_ID=");
| filter.append(selectedRelease.getID());
| }
| testactions = EMHelper.execQuery(em.createQuery(
| "from Testaction where TACT_VALIDATOR_USR_ID=:validator and " +
| "TACT_BFV_ID=" + BugfixValidation.Constants.TO_VALIDATE.value() + " and " +
| "TACT_REV_ID!=" + Revisionclass.Constants.TO_BUGFIX.value() +
| filter.toString() +
| " order by TACT_ID asc"
| ).setParameter("validator", user.getIsAdmin().equals(new Integer(-1)) ? selectedUser.getID() : user.getID()));
|
| lastSelectedReleaseID = (selectedRelease == null) ? null : selectedRelease.getID();
| lastSelectedUserID = (selectedUser == null) ? null : selectedUser.getID();
| }
| Collections.sort(testactions, new TestactionComparator(column, ascending));
| }
|
| @DataModel(scope=ScopeType.PAGE)
| public List<Testaction> getTestactionsForValidator() {
| initTestactions();
| return testactions;
| }
And the page:
<t:dataTable var="testaction_var" value="#{testactionsForValidator}"
| renderedIfEmpty="false" sortColumn="#{testactionValidator.column}"
| sortAscending="#{testactionValidator.ascending}" preserveSort="true">
| <f:facet name="header">
| <h:outputText value="#{ares_messages.label_ResultCount}: #{testactionsForValidator.rowCount}" />
| </f:facet>
| <h:column>
| <f:facet name="header">
| <t:commandSortHeader columnName="id">
| <h:outputText value="#{ares_messages.label_testaction_ID}" />
| </t:commandSortHeader>
| </f:facet>
| <h:commandLink value="#{testaction_var.ID}"
| action="#{testactionValidator.select}" styleClass="rightAlignment" />
| </h:column>
The members "column" and "ascending" are defined in the superclass (with getters and setters). Perhaps that's is the problem?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3989607#3989607
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3989607
19Â years, 5Â months
[Installation, Configuration & Deployment] - Re: packaging ear with datasource and jdbc driver
by Oyabun
I think .sar files are first to be deployed. In your case mysar.sar executes something before the rest of the files get to be deployed. That's why you get the Exception. Read more about the jboss-service.xml...
| C:\jboss-4.0.2\server\default\conf\jboss-service.xml
| ...
| <!-- ==================================================================== -->
| <!-- Deployment Scanning -->
| <!-- ==================================================================== -->
|
| <!-- An mbean for hot deployment/undeployment of archives.
| -->
| <mbean code="org.jboss.deployment.scanner.URLDeploymentScanner"
| name="jboss.deployment:type=DeploymentScanner,flavor=URL">
|
| <!-- Uncomment (and comment/remove version below) to enable usage of the
| DeploymentCache
| <depends optional-attribute-name="Deployer">jboss.deployment:type=DeploymentCache</depends>
| -->
| <depends optional-attribute-name="Deployer">jboss.system:service=MainDeployer</depends>
|
| <!-- The URLComparator can be used to specify a deployment ordering
| for deployments found in a scanned directory. The class specified
| must be an implementation of java.util.Comparator, it must be able
| to compare two URL objects, and it must have a no-arg constructor.
| Two deployment comparators are shipped with JBoss:
| - org.jboss.deployment.DeploymentSorter
| Sorts by file extension, as follows:
| "sar", "service.xml", "rar", "jar", "war", "wsr", "ear", "zip",
| "*"
| - org.jboss.deployment.scanner.PrefixDeploymentSorter
| If the name portion of the url begins with 1 or more digits, those
| digits are converted to an int (ignoring leading zeroes), and
| files are deployed in that order. Files that do not start with
| any digits will be deployed first, and they will be sorted by
| extension as above with DeploymentSorter.
| -->
| <attribute name="URLComparator">org.jboss.deployment.DeploymentSorter</attribute>
| <!--
| <attribute name="URLComparator">org.jboss.deployment.scanner.PrefixDeploymentSorter</attribute>
| -->
|
My EAR file contains META-INF/application.xml which looks like this
| <application>
| <display-name>My App</display-name>
| <module>
| <ejb>core.jar</ejb>
| </module>
| <module>
| <ejb>session.jar</ejb>
| </module>
| <module>
| <connector>services.sar</connector>
| </module>
| </application>
|
The services.sar archive is deployed last.
I had to configure the stuff below in my META-INF/jboss-service.xml in the services.sar file. I execute some methods right after my applications has been successfully deployed.
| <?xml version="1.0" encoding="UTF-8"?>
| <server>
|
| <mbean code="myservices.MyServiceNumberOne"
| name=":name=MyServiceNumberOne">
| </mbean>
|
| <mbean code="org.jboss.varia.scheduler.Scheduler"
| name=":service=Scheduler,name=MyServiceNumberOne">
| <attribute name="StartAtStartup">true</attribute>
| <attribute name="SchedulableMBean">:name=MyServiceNumberOne</attribute>
| <attribute name="SchedulableMBeanMethod">create()</attribute>
| <attribute name="InitialStartDate">NOW</attribute>
| <attribute name="SchedulePeriod">1</attribute>
| <attribute name="InitialRepetitions">1</attribute>
| <depends>jboss.j2ee:module=session.jar,service=EjbModule</depends>
| </mbean>
|
| <mbean code="myservices.MyServiceNumberTwo"
| name=":name=MyServiceNumberTwo">
| </mbean>
|
| <mbean code="org.jboss.varia.scheduler.Scheduler"
| name=":service=Scheduler,name=MyServiceNumberTwo">
| <attribute name="StartAtStartup">true</attribute>
| <attribute name="SchedulableMBean">:name=MyServiceNumberTwo</attribute>
| <attribute name="SchedulableMBeanMethod">create()</attribute>
| <attribute name="InitialStartDate">NOW</attribute>
| <attribute name="SchedulePeriod">1</attribute>
| <attribute name="InitialRepetitions">1</attribute>
| <depends>jboss.j2ee:module=session.jar,service=EjbModule</depends>
| </mbean>
|
| </server>
|
|
Regards,
Alex
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3989606#3989606
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3989606
19Â years, 5Â months
[EJB 3.0] - Setting up an Interceptor with jBoss
by Haensel
Hello,
my name is Hans-Martin. I am a student from Germany.
I have a very big problem. My Professor wants me to send events via JMS to a Complex Event Processing Platform.
First of all my professor gave me the simple job to create a jsp with 4 Buttons. He wants to see ?something move??.
The task is following:
Every time a button is pushed it calls a Method on a Servlet/Bean. The Interceptor realizes this call and creates a simple ?Button_X-was-pushed? event (for example as a string) . This event will be sent via JMS to a CEP Platform which checks for patterns like ?Button_X was pushed? and updates a database which counts the pushes of a single Button.
This database can be called by a simple page/dashboard to show the number of times a button was pushed.
All that must be realized on jBoss.
It is a pretty simple example but we have absolutely NO idea of jBoss, how I can plug in the interceptors or send JMS messages.
What software do I need for this ? Do I need EJB3.0 for that task ?
Do you know a tutorial for the installation/implementation/configuration ?
I don´t even know how what project I have to create in jBoss IDE for eclipse.
I created an jBossAOP Project. And it was pretty simple to connect an Interceptor to a method of another class. But I am not able to do this in a dynamic Web Project (for JSPs, Servlets and so on)
PLEASE HELP ME. I have just 1 week to do this :(
Haensel
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3989604#3989604
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3989604
19Â years, 5Â months