1 Reply Latest reply on Mar 1, 2010 4:19 PM by nimo stephan

    Asynchronous problem

    iwan Nugraha Newbie

      Hi, i have a problem with @Asynchronous method


      this is my Bean




      package com.domain.matricehrm.session;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.web.RequestParameter;
      import org.jboss.seam.log.Log;
      
      import com.domain.matricehrm.entity.Employee;
      import com.domain.matricehrm.entity.Paymenttask;
      import com.domain.matricehrm.entity.Payrollperiod;
      
      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("paymentbillingAction")
      public class PaymentbillingAction implements Paymentbilling, Serializable {
      
              /**
               * 
               */
              private static final long serialVersionUID = 1L;
              private Integer period;
              private String loccode;
              private String deptcode;
              private String groupcode;
              private String idemployee;
          private List<String> itemselects = new ArrayList<String>();
              
              public String[] noRegs;
          
          
              public PaymentbillingAction(){
      
              }
      
              
              
              public PaymentbillingAction(Integer period, String loccode, String deptcode, String groupcode,
                              String idemployee, List<String> itemselects){
                      this.period = period;
                      this.loccode = loccode;
                      this.deptcode = deptcode;
                      this.groupcode = groupcode;
                      this.idemployee = idemployee;
                      this.itemselects = itemselects;
              }
      
              
          @DataModel
          List<Employee> selectedemployees;
      
          @DataModel
          List<Payrollperiod> pperiods;
          
          @In(required = false)
          Asynpayment asyncpayment;
         
          @PersistenceContext //(type=PersistenceContextType.EXTENDED)
          EntityManager em;
      
          @DataModel
          List<String> employeeRegisters;
          
          @Out(required = false)
          Employee employee;
          
              @Logger
              private Log log;
      
          @RequestParameter
          String freqpay;
              
          private Paymenttask payments;
          @In(required = false)
          @Out(required = false, scope = ScopeType.SESSION)
          private List<Employee> hasilEmployee = new ArrayList<Employee>();
          private Paymenttask paytask = new Paymenttask();
          @In(required = false)
          @Out(required = false, scope = ScopeType.SESSION)
          private String paramRegister = new String();
          @In(required = false)
          @Out(required = false, scope = ScopeType.SESSION)
              private Integer periodID;
          
          // VARIABLE - VARIABLE
              String locationcode;
              String departmentcode;
              String employeegroup;
              String employeeid;
              String payfrekuency;
              String[] arrayRegs;
              String pemisah = ",";
              String semikolon = "'";
              Integer regsize;
          
          
          @SuppressWarnings("unchecked")
              public void pilihPegawai(){
      //      inisialisasi();
                      periodID = getPeriod();
                      locationcode = "";
                      departmentcode = "";
                      employeegroup =  "";
                      employeeid = "";
              List<Payrollperiod> periodes = em.createQuery("select per, taxparam from Payrollperiod per "+
                                      "INNER JOIN FETCH per.taxparameter taxparam "+
                                      "where per.payrollperiodid= :perID")
                                      .setParameter("perID", periodID)
                                      .getResultList();
              pperiods = periodes;
              for (Payrollperiod prd : pperiods)
              {
                      payfrekuency = prd.getPeriodtype();
                      freqpay = payfrekuency;
              }
                      
                      locationcode = getLoccode();
                      departmentcode = getDeptcode();
                      employeegroup =  getGroupcode();
                      if (locationcode == null || locationcode.equals("")) { locationcode = "%"; }
                      if (departmentcode == null || departmentcode.equals("")) { departmentcode = "%"; }
                      if (employeegroup == null || employeegroup.equals("")) { employeegroup = "%"; }
                      if (freqpay == null || freqpay.equals("")) {  freqpay = "%";}
                      
                      hasilEmployee = em.createQuery("select emp, pos, dep, loc, emppay, payscheme From Employee emp "+
                                      "INNER JOIN FETCH emp.position pos "+
                                      "INNER JOIN FETCH emp.position.department dep "+
                                      "INNER JOIN FETCH emp.position.department.location loc "+
                                      "INNER JOIN FETCH emp.employeepayroll emppay "+
                                      "INNER JOIN FETCH emp.employeepayroll.payrollschema payscheme "+
                                      "where emp.position.department.location.code like :locid "+
                                      "and emp.position.department.code like :depid "+
                                      "and emp.employeepayroll.payrollschema.schemaname like :scheme "+
                                      "and emp.employeepayroll.payfrequency like :payfrekuen ")
                                      .setParameter("locid", locationcode)
                                      .setParameter("depid", departmentcode)
                                      .setParameter("scheme", employeegroup)
                                      .setParameter("payfrekuen", freqpay)
                                      .getResultList();
                      
                      
          }
      
              
       
          
          
          public void prosesBilling(){
      //      periodID = getPeriod();
                      // merubah data list employee menjadi string
                      employeeRegisters = new ArrayList<String>();
              employeeRegisters = getItemselects();
              if (employeeRegisters.size() > 0 )
              {
                      regsize = employeeRegisters.size();
                      noRegs = new String[regsize];
                      noRegs = employeeRegisters.toArray(new String[regsize]);
                      arrayRegs = new String[regsize];
                      arrayRegs[0] = semikolon+noRegs[0]+semikolon;
                      for (int n = 1; n <= employeeRegisters.size() - 1; n++)
                      {
                              arrayRegs[n] = pemisah+semikolon+noRegs[n]+semikolon;
                              log.info("registerNo "+arrayRegs[n]);
                      }
                      
                      // cara baru perubahan array ke string dengan menggunakan buffer
                  StringBuffer result = new StringBuffer();
                  if (noRegs.length > 0) {
                      result.append(semikolon+noRegs[0]+semikolon);
                      for (int i=1; i<noRegs.length; i++) {
                          result.append(pemisah);
                          result.append(semikolon);
                          result.append(noRegs[i]);
                          result.append(semikolon);
                      }
                  }
                      paramRegister = result.toString();
                      
              }else
              {
                      paramRegister = semikolon+"%"+semikolon;
              }
              
              
              
              log.info("========== parsing ke synchronous proses =========>>>>>>");
              asyncpayment.prosesHitung(regs);
              System.out.println("coba ke DB");
              for(int i = 1; i<= 5; i ++)
              {
                      this.paytask = new Paymenttask();
                      this.paytask.setPeriodinfo("olaa ciecie beibeh");
                      em.persist(this.paytask);
                      log.info("simpan");
              }
          }
              
          
          public void reset() { 
          }
          
          @Destroy
          @Remove
              public void destroy() {
              
              }
      
          
          
          
          // getter dan setter..
          
              public void setPeriod(Integer period) {
                      this.period = period;
              }
      
              public Integer getPeriod() {
                      return period;
              }
      
              public void setLoccode(String loccode) {
                      this.loccode = loccode;
              }
      
              public String getLoccode() {
                      return loccode;
              }
      
              public void setDeptcode(String deptcode) {
                      this.deptcode = deptcode;
              }
      
              public String getDeptcode() {
                      return deptcode;
              }
      
              public void setGroupcode(String groupcode) {
                      this.groupcode = groupcode;
              }
      
              public String getGroupcode() {
                      return groupcode;
              }
      
              public void setIdemployee(String idemployee) {
                      this.idemployee = idemployee;
              }
      
              public String getIdemployee() {
                      return idemployee;
              }
      
              public void setItemselects(List<String> itemselects) {
                      this.itemselects = itemselects;
              }
      
              public List<String> getItemselects() {
                      return itemselects;
              }
      
              public void setPayments(Paymenttask payments) {
                      this.payments = payments;
              }
      
              public Paymenttask getPayments() {
                      return payments;
              }
         
      }
      
      
      and this is my stateless bean,
      
      package com.domain.matricehrm.session;
      
      import java.io.Serializable;
      
      import javax.ejb.Stateless;
      
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.log.Log;
      
      @Stateless
      @Name("asyncpayment")
      public class Asyncpayment implements Asynchronouspayment, Serializable{
      
              
          /**
               * 
               */
              private static final long serialVersionUID = 1L;
              /**
               * 
               */
              @Logger
          Log log;
              
          public void prosesHitung(String gila) {
               try {
                //  Contexts.getEventContext().set("payments",payments);
                  do some work here..
      
              } catch (Exception e) {
                  log.error("Error trying to process payment..", e);
              }
          }
      
          public void goBilling(){
              log.info("testing");
          }
      
              
      }
      
      this is my interface..
      package com.domain.matricehrm.session;
      
      import javax.ejb.Local;
      
      import org.jboss.seam.annotations.async.Asynchronous;
      
      @Local
      public interface Asynchronouspayment {
              @Asynchronous
          public void prosesHitung(String gila);
              @Asynchronous
              public void goBilling();
       
      }
      
      




      and the problem is i can't call processHitung();
      please how to solve my problem..