SOA Suite 11g - api tricks part 2 - finding instances

In the last post we learned how to use the Locator to find a Composite (locator.lookupComposite(compositeDN);), and invoke it through a DeliveryService.

The next step is to use the API to find its instances and get some meaningful information, e.g. its instance id - what components executed and what not.


Composite composite =
locator.lookupComposite("default/OrderBookingComposite!1.0");
/*
* retrieve instances, we are already on a composite, no need to set the
* DN
*/
CompositeInstanceFilter filter = new CompositeInstanceFilter();
filter.setMinCreationDate(
new java.util.Date((System.currentTimeMillis() - 20000)));

// get composite instances by filter ..
List obInstances = composite.getInstances(filter);

// for each of the returned composite instances..
for (CompositeInstance instance : obInstances)
{
System.out.println(" DN: " + instance.getCompositeDN() +
"Instance: " + instance.getId() +
" creation-date: " + instance.getCreationDate() +
" state (" + instance.getState() + "): " +
getStateAsString(instance.getState()));

// setup a component filter
ComponentInstanceFilter cInstanceFilter =
new ComponentInstanceFilter ();

// get child component instances ..
List childComponentInstances =
instance.getChildComponentInstances(cInstanceFilter);

// for each child component instance (e.g. a bpel process)
for (ComponentInstance cInstance : childComponentInstances)
{
System.out.println(" -> componentinstance: " +
cInstance.getComponentName() + " type: " +
cInstance.getServiceEngine().getEngineType()+
" state: " +
getStateAsString(cInstance.getState()));
}

// retrieve composite sensors
List sensorData = instance.getSensorData();
for (SensorData data : sensorData)
{
System.out.println(" -> Sensor: " + data.getSensor().getName() +
" data: " + data.getData());
}
}


To make the compo(site/nent) states readable - here is the conversion method:

private String getStateAsString (int state)
{
// note that this is dependent on wheter the composite state is
// captured or not
if (state == CompositeInstance.STATE_COMPLETED_SUCCESSFULLY)
return ("success");
else if (state == CompositeInstance.STATE_FAULTED)
return ("faulted");
else if (state == CompositeInstance.STATE_RECOVERY_REQUIRED)
return ("recovery required");
else if (state == CompositeInstance.STATE_RUNNING)
return ("running");
else if (state == CompositeInstance.STATE_STALE)
return ("stale");
else
return ("unknown");
}

The above code executed against the FusionOrderDemo BamOrderBookingComposite prints the following:

DN: default/BamOrderBookingComposite!1.0Instance: 40103 creation-date: Thu Jul 30 12:31:24 PDT 2009 state (-1): unknown
-> componentinstance: EvaluatePreferredSupplierRule type: decision state: success
-> componentinstance: FulfillOrder type: mediator state: success
-> componentinstance: InternalWarehouseService type: bpel state: unknown
-> componentinstance: OrderProcessor type: bpel state: unknown
-> componentinstance: RequiresApprovalRule type: decision state: success
-> componentinstance: PartnerSupplierMediator type: mediator state: success
-> Sensor: CreditCardAuthResultSensor data: APPROVED
-> Sensor: OrderBookingCompositeProcessorResult data: 900
-> Sensor: OrderProcessingStart data: Order 900

On a side note - in case you don't want to start searching for the APIs, and packages .. All of those classes used are in

oracle.fabric.common.*, oracle.soa.management.facade.* and
oracle.soa.management.util.*

Comments:

the libraries you need are fabric-common.jar, weblogic.jar, and soa-infra-mgmt.jar. If you check my other posts (you can find all the jars / paths you need in the build scripts)

Posted by Clemens Utschig (author) on October 10, 2009 at 11:01 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Tips and tricks straight from the SOA / BPM development team at Oracle HQ

Search

Archives
« May 2015
SunMonTueWedThuFriSat
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      
Today