@10g - This post is motivated by one of my close friends and colleague - who wanted to proactively know when a BPEL process shuts down/re-activates. This typically happens when you have a BPEL Process that has an inbound polling
adapter, when the
adapter loses connectivity to the source system. Or whatever causes it.
One valuable suggestion came in from one of my colleagues - he suggested I write my own ActivationAgent to do the job. Well, it really worked.
Here is a sample ActivationAgent that you can use.
There are few methods you need to override from BaseActivationAgent, and you are on your way to receiving notifications/what not, whenever the shutdown/startup events occur.
In the example below, I am retrieving the emailAddress property [that is specified in your bpel.xml activationAgent section] and use that to send out an email notification on the activation agent initialization. You could choose to do different things. But bottomline is that you can use the below-mentioned API to access the very same properties that you specify in the bpel.xml.
package com.
adapter.custom.activation;
import com.collaxa.cube.activation.BaseActivationAgent;
import com.collaxa.cube.engine.ICubeContext;
import com.oracle.bpel.client.BPELProcessId;
import java.util.Date;
import java.util.Properties;
public class LifecycleManagerActivationAgent extends BaseActivationAgent {
public BPELProcessId getBPELProcessId() {
return super.getBPELProcessId();
}
private void handleInit() throws Exception {
//Write initialization code here
System.err.println("Entered initialization code....");
//e.g.
String emailAddress = getActivationAgentDescriptor().getPropertyValue(emailAddress);
//send an email
sendEmail(emailAddress);
}
private void handleLoad() throws Exception {
//Write load code here
System.err.println("Entered load code....");
}
private void handleUnload() throws Exception {
//Write unload code here
System.err.println("Entered unload code....");
}
private void handleUninit() throws Exception {
//Write uninitialization code here
System.err.println("Entered uninitialization code....");
}
public void init(ICubeContext icubecontext)
throws Exception {
super.init(icubecontext);
System.err.println("Initializing LifecycleManager Activation Agent .....");
handleInit();
}
public void unload(ICubeContext icubecontext)
throws Exception {
super.unload(icubecontext);
System.err.println("Unloading LifecycleManager Activation Agent .....");
handleUnload();
}
public void uninit(ICubeContext icubecontext)
throws Exception{
super.uninit(icubecontext);
System.err.println("Uninitializing LifecycleManager Activation Agent .....");
handleUninit();
}
public String getName() {
return "Lifecyclemanageractivationagent";
}
public void onStateChanged(int i, ICubeContext iCubeContext) {
}
public void onLifeCycleChanged(int i, ICubeContext iCubeContext) {
}
public void onUndeployed(ICubeContext iCubeContext) {
}
public void onServerShutdown() {
}
}
Once you compile this code, generate a jar file and ensure you add it to the server startup classpath. The library is ready for use after the server restarts.
To use this activationAgent, add an additional activationAgent entry in the bpel.xml for the BPEL Process that you wish to monitor.
After you deploy the process, the ActivationAgent object will be called back whenever the events mentioned in the overridden methods are raised. [init(), load(), unload(), uninit()]. Subsequently, your custom code is executed.
Sample bpel.xml illustrating activationAgent definition and property definition.
<?xml version="1.0" encoding="UTF-8"?
<BPELSuitcase timestamp="1291943469921" revision="1.0"
<BPELProcess wsdlPort="{http://xmlns.oracle.com/BPELTest}BPELTestPort" src="BPELTest.bpel" wsdlService="{http://xmlns.oracle.com/BPELTest}BPELTest" id="BPELTest"
<partnerLinkBindings
<partnerLinkBinding name="client"
<property name="wsdlLocation"BPELTest.wsdl</property
</partnerLinkBinding
<partnerLinkBinding name="test"
<property name="wsdlLocation"test.wsdl</property
</partnerLinkBinding
</partnerLinkBindings
<activationAgents
<activationAgent className="oracle.tip.
adapter.fw.agent.jca.JCAActivationAgent" partnerLink="test"
<property name="portType"Read_ptt</property
</activationAgent
<activationAgent className="com.oracle.bpel.activation.LifecycleManagerActivationAgent" partnerLink="test"
<property name="emailAddress"
[email protected]</property
</activationAgent
</activationAgents
</BPELProcess
</BPELSuitcase
em