Home > BPEL > Purge instances in Oracle SOA 11G from Java Client

Purge instances in Oracle SOA 11G from Java Client

There are many strategies to managing how to purge oracle soa 11G instances.
Now In this post we will see how to purge Oracle SOA 11G instances from Simple Java Class.

Jars Required :
1. fabric-common.jar ($ORACLE_HOME\oracle_common\modules\oracle.fabriccommon_11.1.1)
2. fabric-runtime.jar ($ORACLE_HOME\Oracle_SOA\soa\modules\oracle.soa.fabric_11.1.1)
3. soa-infra-mgmt.jar ($ORACLE_HOME\oracle_common\soa\modules\oracle.soa.mgmt_11.1.1)
4. wlfullclient.jar ($ORACLE_HOME\wlserver_10.3\server\lib)

Java class to purge oracle soa 11G instances

package com.sample.purgeinstance;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import javax.naming.Context;

import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.CompositeFilter;
import oracle.soa.management.util.CompositeInstanceFilter;

public class InstanceManager {

	public Hashtable<String,String> getJNDIProps() {
        Hashtable<String,String> jndiProps = new Hashtable<String,String>();
        jndiProps.put(Context.PROVIDER_URL, "t3://localhost:8011/soa-infra");
        jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
        jndiProps.put(Context.SECURITY_CREDENTIALS, "password1");
        jndiProps.put("dedicated.connection", "true");
        return jndiProps;
    public Locator getLocator() {
        try {
            return LocatorFactory.createLocator(getJNDIProps());
        } catch (Exception e) {
        return null;
    public void purgeStaleInstances(CompositeFilter compositeFilter, int state) {
        Locator locator = null;
        int purgedInstanceCount = 0;
        try {
            locator = this.getLocator();
            CompositeInstanceFilter instanceFilter=new CompositeInstanceFilter();
            System.out.println("------- Setting the process State --------");
             * Retrieve all the instances based on the filter criteria given
            List<Composite> composites=locator.getComposites(compositeFilter);
            System.out.println("## Composite Instance Size: " + composites.size() +" matching composites.");
            Iterator compositeIter = composites.iterator();
            while (compositeIter.hasNext()) {
                Composite composite=(Composite)compositeIter.next();
                int compositeInstanceSize=composite.getInstances(instanceFilter).size();
                if (compositeInstanceSize > 0) {
                    purgedInstanceCount += compositeInstanceSize;
                    System.out.println("## Purged " + compositeInstanceSize +" instances for composite " + composite.getCompositeDN().getCompositeName());
                } else {
                    System.out.println("## No instances found for composite " + composite.getCompositeDN().getCompositeName());
            System.out.println("## Cleaned a total of " + purgedInstanceCount +" instances.");
        } catch (Exception e) {
    public static void main(String[] args) {
        InstanceManager instanceManager = new InstanceManager();
         *Clean instances based on instance state 
        int instanceState = CompositeInstance.STATE_STALE;
        CompositeFilter compositeFilter = new CompositeFilter();        
        System.out.println("------ Starting to purge Instance -----");
        instanceManager.purgeStaleInstances(compositeFilter, instanceState);


Purge instance Result

------ Starting to purge Instance -----
SEVERE: Failed to create a DirectConnectionFactory instance (oracle.soa.api.JNDIDirectConnectionFactory): oracle.soa.api.JNDIDirectConnectionFactory
------- Setting the process State --------
## Composite Instance Size: 13 matching composites.
## No instances found for composite SampleHumanTask
## No instances found for composite SimpleApproval
## Purged 5 instances for composite TrainBooking
## Purged 2 instances for composite MediatorDVMTest
## No instances found for composite MediatorXrefTest
## No instances found for composite BPELBAMSensor
## Purged 2 instances for composite AsynExternalBPEL
## Purged 3 instances for composite DVMTest
## Purged 4 instances for composite FaultHandlerBPEL
## Purged 4 instances for composite BPEL_BAM_Monitor
## No instances found for composite FaultHandlingByFaultCode
## No instances found for composite CustomXpathTest
## Purged 1 instances for composite FaulthandlingClientBPEL
## Cleaned a total of 21 instances.

  1. Rodrigo Chafik Choueiri
    February 15, 2012 at 2:24 am

    Thanks! It was helpful.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: