Tuesday, November 20, 2007

Helper for Purging Oracle Bpel Instances.

I had written a piece of code during my free time, which I thought would share with some Bpel enthusiasts. There had always been questions regarding purging of Bpel instances, if it's faulted or completed abnormally..

The following code removed all the bpel instances which are:


  • Closed Faulted
  • Stale
  • Cancelled



import com.oracle.bpel.client.IActivityConstants;
import com.oracle.bpel.client.IInstanceHandle;
import com.oracle.bpel.client.Locator;

public class PurgeHelper {

    
public static void purgeInstances(String aDomainId, String aPassword, String aIPAddress) throws Exception {
        
        // initialize the instance handler
        IInstanceHandle instances[] = null;
        try {
            //check if parameters are invalid
            if(aDomainId ==null || aPassword == null )//|| aIPAddress ==null)
                throw new  Exception(" Invalid Parameter");
            // get the instances
            instances = new Locator(aDomainId, aPassword).listInstances(1, -1);
            // check for null
            if (instances == null) {
                throw new Exception("No Instances Retrieved");
            }

            // get the instance length
            int instancesLength = instances.length;
            // iterate
            for (int j = 0; j <=instancesLength;++j)
                // get the instance
                IInstanceHandle tempInstance = instances[j];
                // check for null
                if (tempInstance == null)
                    continue;
                
                //check  the state
                if(tempInstance.getState()!= IActivityConstants.STATE_CLOSED_FAULTED ||
                        tempInstance.getState()!= IActivityConstants.STATE_CLOSED_STALE ||
                        tempInstance.getState()!= IActivityConstants.STATE_CLOSED_CANCELLED)||
                        ){
                    // remove the instance from the Dehydration Store
                    tempInstance.delete();
                }

            }

        } catch (Exception err) {
            // handle exception
        }

    }

/* Some usefull Bpel instance status */

// IActivityConstants.STATE_CLOSED_FAULTED);
     // IActivityConstants.STATE_CLOSED_ABORTED);
     // IActivityConstants.STATE_CLOSED_COMPLETED);
     // IActivityConstants.STATE_CLOSED_CANCELLED);
     // IActivityConstants.STATE_CLOSED_COMPENSATED);
     // IActivityConstants.STATE_CLOSED_FINALIZED);
     // IActivityConstants.STATE_CLOSED_PENDING_CANCEL);
     // IActivityConstants.STATE_CLOSED_STALE);

   

}

Note. You need to add orabpel.jar for compilation.

No comments: