0 Replies Latest reply on Jun 8, 2012 3:59 AM by santos2178

    SFSB state is not beeing maintained in jboss5.1

    santos2178

      Hi Guys,

       

      I am using jboss 5.1 and have written a SFSB - BillItemsListFacadBean which i am trying to invoke from a SLSB - BillFacadBean. The basic purpose of this SFSB is to store list of billitems that were selected as part of generating a document .No database calls involved in the SFSB. It has got 2 simple methods updateDeliveryMemoSelectionList and fetchDeliveryMemoSelectionList .updateDeliveryMemoSelectionList  updates the instance variable arrCummulativeDMSelectionList , which is a list and fetchDeliveryMemoSelectionList  returns this to the calling program. I am using the below code in a struts action class to update the instance variable of the SFSB

                               BillItemsListFacadBeanInterface billItemsListFacadBean = null;
                     try{
                          billItemsListFacadBean = (BillItemsListFacadBeanInterface) new InitialContext().lookup("inticraftEAR/BillItemsListFacadBean/local");
                     }catch(NamingException name){
                          throw new ECSystemException(name.getMessage(),BillCreationAction.class.getName(),METHOD_NAME);
                     }
                     ArrayList<String> arrCheckedItems = new ArrayList<String>();
                     StringTokenizer billitemString = new StringTokenizer(request.getParameter("dmCheckBoxSelectionList_Hidden"),",");
                     while(billitemString.hasMoreTokens()){
                          String billitem_id = billitemString.nextToken();
                          arrCheckedItems.add(billitem_id);
                     }
                     ArrayList<String> arrUnCheckedItems = new ArrayList<String>();
                     StringTokenizer billitemString2 = new StringTokenizer(request.getParameter("dmCheckBoxUnSelectionList_Hidden"),",");
                     while(billitemString2.hasMoreTokens()){
                          String billitem_id = billitemString2.nextToken();
                          arrUnCheckedItems.add(billitem_id);
                     }
                     billItemsListFacadBean.updateDeliveryMemoSelectionList(arrCheckedItems, arrUnCheckedItems);

      After this now when i try to access this variable in BillFacadBean(SLSB)  using the below code the value of the instance variable(arrCummulativeDMSelectionList) of the SFSB is null and hence the method
      fetchDeliveryMemoSelectionList returns an empty arraylist.

                      BillItemsListFacadBeanInterface billItemsListFacadBean = null;
                try{
                     billItemsListFacadBean = (BillItemsListFacadBeanInterface) new InitialContext().lookup("inticraftEAR/BillItemsListFacadBean/local");
                }catch(NamingException name){
                     throw new ECSystemException(name.getMessage(),BillFacadBean.class.getName(),METHOD_NAME);
                }
                if(null != billItemsListFacadBean){
                     arrSelectedBillItems = billItemsListFacadBean.fetchDeliveryMemoSelectionList();
                }

      Code of SFSB BillItemsListFacadBean  is as below:

      package com.inticraft.facad;

      import java.util.ArrayList;
      import java.util.Iterator;
      import java.util.List;

      import javax.annotation.PostConstruct;
      import javax.annotation.PreDestroy;
      import javax.ejb.PostActivate;
      import javax.ejb.PrePassivate;
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.interceptor.Interceptors;

      import com.inticraft.ejbutil.CommitAndCloseInterceptor;
      import com.inticraft.ejbutil.LoggingInterceptor;
      import com.inticraft.exceptions.ECException;

      /**
        * Session Bean implementation class BillItemsListFacadBean
        */
      @Interceptors({LoggingInterceptor.class})
      @Stateful
      public class BillItemsListFacadBean implements BillItemsListFacadBeanInterface {
           private List <String> arrCummulativeDMSelectionList;
           private String first_element;
           /**
            * Default constructor.
            */
           public BillItemsListFacadBean() {
               // TODO Auto-generated constructor stub
           }

           @PostConstruct
           @PostActivate
           public void openConnection(){

           }

           @PrePassivate
           @PreDestroy
           public void cleanup() {


           }

           @Remove
           @Interceptors({CommitAndCloseInterceptor.class})
           public void closeDM() throws ECException{
                arrCummulativeDMSelectionList = null;
           }



           @Interceptors({CommitAndCloseInterceptor.class})
           public void updateDeliveryMemoSelectionList(ArrayList<String> arrSelectedItems , ArrayList<String>arrUnSelectedItems) throws ECException {
                arrCummulativeDMSelectionList = new ArrayList<String>();
                //Step1 iterate through the unselecteditems and remove from the cummulative list if any entry matches
                Iterator <String>it1 = arrUnSelectedItems.iterator();
                while(it1.hasNext()){
                     String unSelectedItem = (String)it1.next();
                     if(arrCummulativeDMSelectionList.contains(unSelectedItem)){
                          arrCummulativeDMSelectionList.remove(unSelectedItem);
                     }
                }
                Iterator <String>it2 = arrSelectedItems.iterator();
                while(it2.hasNext()){
                     String selectedItem = (String)it2.next();
                     if(!arrCummulativeDMSelectionList.contains(selectedItem)){
                          arrCummulativeDMSelectionList.add(selectedItem);
                          first_element = selectedItem;
                     }
                }
           }

           @Interceptors({CommitAndCloseInterceptor.class})
           public ArrayList<String> fetchDeliveryMemoSelectionList() throws ECException {
                if(null == arrCummulativeDMSelectionList){
                     return new ArrayList();
                }else{
                     return new ArrayList(arrCummulativeDMSelectionList);
                }

           }


      }

      I am not understaning , why is this variable value null always ie the STATE IS NOT BEING MAINTAINED. Also another thing that i observed was in the jobss jmx console , every time this SFSB was accessed the count got incrmented by 1 , which is making me think , every time this bean is called a new instance of the bean is created , instead of returning the already created instance. I am going nuts over this . any help is greatly appreciated. Thanks a ton in advance and also please let me know if you would need any other information.