0 Replies Latest reply on Jul 25, 2008 5:46 PM by Ashish Chawla

    Serializing Session in jbpm???

    Ashish Chawla Newbie

      Hi All,
      I am running into another issue with Serializing jms session object in jbpm..
      I am using jms/tibco to store and retrieve the messages from a queue and in the workflow what I am doing as a first step is create a session and then at the end of the workflow ..ack the message and end that session.
      Now since tibco jms session is not serializable jbpm is not able to store that object in its db…

      So I created a session store and returned the id which I store….But when the execution transitions from one step to another, the static variable is cleared out…

      Here is the code what I am talking about….

      Step 1: to create session…

      public class QueueSessionHandler implements ActionHandler {
       public void execute(ExecutionContext context) throws Exception {
       context.getContextInstance().setVariable(CONSTANTS.SESSION_OBJECT_VAR, SessionStore.storeSession(CreateSession()));

      Here is the SessionStore Class:

      import java.io.Serializable;
      import java.util.HashMap;
      import java.util.Map;
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      import javax.jms.Session;
      public class SessionStore {
      private static Map<String,Session> StoreMap = null;
       private static int m_SeqNumber = 1;
       static {
       StoreMap = new HashMap<String,Session>();
       public static String storeSession(Session s)
       String token = "" + m_SeqNumber++;
       StoreMap.put(token, s);
       return token;
       public static Session getSession(String token)
       Session s = StoreMap.get(token);
       return s;
       public static void destroySession(String token)

      Step 2 of the workflow:

      public void execute(ExecutionContext context) throws Exception {
       context.getContextInstance().setVariable("actionName", actionName);
       context.getContextInstance().setVariable("queueName", queueName);
       String token = (String)context.getContextInstance().getVariable(CONSTANTS.SESSION_OBJECT_VAR);
       Session prevSession = SessionStore.getSession(token);
       log.info("Session token is " + token);
       if(prevSession != null)
       context.getContextInstance().setVariable(CONSTANTS.INCOMING_MSG_READ_VAR, ReadMessage(prevSession, queueName));
       log.info("Returning after reading message from incoming queue");
       else {
       context.getContextInstance().setVariable(CONSTANTS.INCOMING_MSG_READ_VAR, "");
       log.info("Session is null so not reading message...returning blank");

      In Step 2 of the WF I expect when I call SessionStore.getSession it should have the same StoreMap and return me the session which I stored in there….but actually the StoreMap is empty/null or recreated….that is what I am not understanding….

      Can you please advise on how should i be doing that....