How to Programmatically Access Oracle CEP MBeans

Developers of Oracle CEP applications frequently ask how they can access the components of their application -- adapters, processors, etc. -- directly from Java. For example, suppose one wants to code a bean that adds a new rule to a processor component. Adding a new rule, whether it be a query or a view, is best done using the processor's configuration MBean. Fortunately, Spring provides built-in way to inject a reference to an MBean into another bean that would like to perform the aforementioned rule manipulation.  Here are the steps for accomplishing this:

1)  Use MBeanProxyFactoryBean to create a proxy bean that represents the MBean. Here's a sample.

 

<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
<property name="objectName"
value="com.bea.wlevs:Name=helloworldProcessor,Type=CQLProcessor,Application=helloworld" />
<property name="proxyInterface"
value="com.bea.wlevs.management.configuration.CQLProcessorMBean" />
</bean>

If you're not sure about the objectName of your particular MBean, you can run the wlevsjconsole script which is included with the release to take a look at the MBean metadata. Be sure to start the server using the -disablesecurity commandline option when using wlevsjconsole.


 

2)  Declare the bean that will do the rule manipulation and inject a reference to the MBean proxy.

 
<bean id="control" class="com.bea.wlevs.example.helloworld.ProcessorControlBean">
<property name="processor" ref="proxy" />
</bean>

3)  The Java code for the control bean could look something like this:

package com.bea.wlevs.example.helloworld;

import java.util.Map;

import org.springframework.beans.factory.InitializingBean;
import com.bea.wlevs.ede.api.ActivatableBean;
import com.bea.wlevs.management.configuration.CQLProcessorMBean;

public class ProcessorControlBean implements InitializingBean ,ActivatableBean{

private CQLProcessorMBean processor;

public void setProcessor(CQLProcessorMBean processor) {
this.processor = processor;
}

@Override
public void afterPropertiesSet() throws Exception {
// don't access processor MBean here as it is not available yet
}

@Override
public void afterConfigurationActive() throws Exception {
// example of accessing processor MBean
Map<String, String> rules = processor.getAllRules();

for ( String key: rules.keySet()) {
System.out.println ("rule id-" + key + "rule-" + rules.get (key));
}
}

}

 

4) The last step is to import a few additional packages into the application bundle that are required by our new usage of spring.  To do this, if you are using Eclipse, click on MANIFEST.MF in the Package Explorer view.  Then click on the Dependencies tab and add the packages below:

 
org.aopalliance.aop
org.springframework.aop
org.springframework.aop.framework
org.springframework.jmx.access
 


Now, deploy and run the application.

 


Technorati Tags: ,,,

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

bocadmin_ww

Search

Categories
Archives
« April 2014
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
   
       
Today