8 Replies Latest reply on Apr 23, 2008 4:17 PM by Ronald van Kuijk

    Identifying tokens

    richard bradwell Newbie

      Hi,

      I want to signal a token pragmatically. I'm wondering how I would identify the right token however. A token obviously has an id but this is no good because the id is different for each process instance. I notice that is a name property in the database table jbpm_token. Is there a way to name a token from within the processdefinition.xml? Then use that name to retrieve the correct token and signal over a transition on that token?

      Thanks.

        • 1. Re: Identifying tokens
          Mauricio Salatino Master

          can you explain a little more what are you trying to achive?
          because you can get the token with
          processInstance.getRootToken()
          and then .signal()...

          • 2. Re: Identifying tokens
            richard bradwell Newbie

             

            "salaboy21" wrote:
            can you explain a little more what are you trying to achive?
            because you can get the token with
            processInstance.getRootToken()
            and then .signal()...


            Yes I am using that to signal the root token but I am thinking now what if I need to signal another token. How do I know which one to signal.

            I want to retrieve exactly where I am in a overall process at any one time i.e. which nodes I am at in all execution threads of the process. I am currently performing something like this
            Token token = processInstance.getRootToken()
            String nodeName = token.getNode().getName() ;
            


            Obviously though this is only any good if there is only one route through the process. I would like to return a list of tokens and the associated node name they are currently at.

            The reason I am doing this is as follows. I have a client/server setup. The server component is an EJB wrapping the jbpm in a command pattern.
            So for example the client would send a SignalProcessDTO holding the transition name, processInstanceId etc to the server. The server will detect the type of payload and run a signal process command. The signal process command will use the info in the DTO to get the process instance and then perform the signal.

            I am delivering an adapter jar to the client (a web app). The adapter makes the interface to the server simple. Through the adapter the client is exposed to a very simple API. Essentially it allows them to say one of two things
            - Can I make this transition.
            - Perform this transition.

            . Hence the reason I want to pull back the list of tokens, to determine which "actions" in my adapter can be performed given the currrent state of the process.


            • 3. Re: Identifying tokens
              Mauricio Salatino Master

              Thats ok..
              have you look the MultichoiceForkAH example in the wiki..?
              May be some part of this code can give you some pointers ...

              http://wiki.jboss.org/wiki/MultiChoiceForkAH

              Look at the java class attached.. and notice that the
              code look for all the available transitions and then signal
              the token looking in a process variable...

              • 4. Re: Identifying tokens
                richard bradwell Newbie

                 

                "salaboy21" wrote:
                Thats ok..
                have you look the MultichoiceForkAH example in the wiki..?
                May be some part of this code can give you some pointers ...

                http://wiki.jboss.org/wiki/MultiChoiceForkAH

                Look at the java class attached.. and notice that the
                code look for all the available transitions and then signal
                the token looking in a process variable...


                At first glance that looks exactly what I am looking for. Thanks a lot .. still finding my way around things.

                • 5. Re: Identifying tokens
                  Mauricio Salatino Master

                  Let me know if you are stuck in some point.. i wanna help people hera
                  to gain expertise!

                  • 6. Re: Identifying tokens
                    richard bradwell Newbie

                     

                    "salaboy21" wrote:
                    Let me know if you are stuck in some point.. i wanna help people hera
                    to gain expertise!


                    I have just had a look at that example you suggested and it seems to be creating tokens dynamically. Do you know if there are any bare bones examples where a fork is defined in the process definition and a junit test works through the graph signalling the different "routes" through the graph and eventually joining at the end.

                    • 7. Re: Identifying tokens
                      richard bradwell Newbie

                      Salaboy just for info I think I have found out by looking at the code what I need to do. Fork seems to create new tokens for each leaving transaction. These tokens are added as children to the current token. They are named after the transition name.

                      To gather all of the child tokens underneath the root recursively I think I need to call the collectChildrenRecusively on the root token.

                      • 8. Re: Identifying tokens
                        Ronald van Kuijk Master

                        correct and remember... there are a LOT of testcases in the source, they demonstrate all kinds of things, like tokentraversing etc...