Removed all JMX references from core module.

pull/5/head
Drem Darios 10 years ago
parent 8f0cf22ff0
commit 3b001e118b

@ -24,17 +24,14 @@
package org.easyrules.api;
import javax.management.MXBean;
/**
* Abstraction for a rule that can be fired by the rules engine.<br/>
* Abstraction for a rule that can be fired by the rules engine.
*
* Rules are registered in the rules engine registry and must have a <strong>unique</strong> name.<br/>
* Rules are registered in the rules engine registry and must have a <strong>unique</strong> name.
*
* @author Mahmoud Ben Hassine (md.benhassine@gmail.com)
*/
@MXBean
public interface Rule {
/**

@ -44,23 +44,6 @@ public interface RulesEngine<R> {
*/
void unregisterRule(R rule);
/**
* Register a rule in the rules engine registry.
* This method also registers the rule as a Jmx bean.
* The rule object <strong>must</strong> be JMX compliant.
*
* @param rule the rule to register
*/
void registerJmxRule(R rule);
/**
* Unegister a rule from the rules engine registry.
* This method also unregisters the rule from MBean server.
*
* @param rule the rule to register
*/
void unregisterJmxRule(R rule);
/**
* Fire all registered rules.
*/

@ -1,16 +1,11 @@
package org.easyrules.core;
import org.easyrules.api.RulesEngine;
import org.easyrules.util.EasyRulesConstants;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.easyrules.api.RulesEngine;
import org.easyrules.util.EasyRulesConstants;
/**
* Abstract rules engine class.
*
@ -35,11 +30,6 @@ public abstract class AbstractRulesEngine<R> implements RulesEngine<R> {
*/
protected int rulePriorityThreshold;
/**
* The JMX server instance in which rule's MBeans will be registered.
*/
protected MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
@Override
public void registerRule(R rule) {
rules.add(rule);
@ -50,18 +40,6 @@ public abstract class AbstractRulesEngine<R> implements RulesEngine<R> {
rules.remove(rule);
}
@Override
public void registerJmxRule(R rule) {
rules.add(rule);
registerJmxMBean(rule);
}
@Override
public void unregisterJmxRule(R rule) {
rules.remove(rule);
unregisterJmxMBean(rule);
}
@Override
public abstract void fireRules();
@ -71,47 +49,4 @@ public abstract class AbstractRulesEngine<R> implements RulesEngine<R> {
LOGGER.info("Rules cleared.");
}
/*
* Register a JMX MBean for a rule.
*/
protected void registerJmxMBean(final R rule) {
ObjectName name;
try {
name = getObjectName(rule);
if (!mBeanServer.isRegistered(name)) {
mBeanServer.registerMBean(rule, name);
LOGGER.log(Level.INFO, "JMX MBean registered successfully as: {0} for rule: {1}", new Object[]{name.getCanonicalName(), rule.toString()});
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Unable to register JMX MBean for rule: " + rule.toString(), e);
}
}
/*
* Unregister the JMX MBean of a rule.
*/
protected void unregisterJmxMBean(final R rule) {
ObjectName name;
try {
name = getObjectName(rule);
if (mBeanServer.isRegistered(name)) {
mBeanServer.unregisterMBean(name);
LOGGER.log(Level.INFO, "JMX MBean unregistered successfully for rule: {0}", new Object[]{rule.toString()});
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Unable to unregister JMX MBean for rule: " + rule.toString(), e);
}
}
/*
* Utility method to get rule's JMX Object name
*/
private ObjectName getObjectName(R rule) throws MalformedObjectNameException {
return new ObjectName("org.easyrules.core.jmx:type=" + rule.getClass().getSimpleName() + ",name=" + rule.toString());
}
}

@ -62,12 +62,6 @@ public class AnnotatedRulesEngine extends AbstractRulesEngine<Object> {
this.rulePriorityThreshold = rulePriorityThreshold;
}
@Override
public void registerJmxRule(Object rule) {
registerRule(rule);
registerJmxMBean(rule);
}
@Override
public void registerRule(Object rule) {
@ -136,12 +130,6 @@ public class AnnotatedRulesEngine extends AbstractRulesEngine<Object> {
}
@Override
public void unregisterJmxRule(Object rule) {
unregisterRule(rule);
unregisterJmxMBean(rule);
}
@Override
public void fireRules() {

@ -86,9 +86,6 @@ public class DefaultRulesEngine extends AbstractRulesEngine<Rule> {
return;
}
//resort rules in case priorities were modified via JMX
rules = new TreeSet<Rule>(rules);
for (Rule rule : rules) {
if (rule.getPriority() > rulePriorityThreshold) {

@ -1,12 +1,12 @@
package org.easyrules.core.test;
import junit.framework.TestSuite;
import org.easyrules.core.test.annotation.EasyRulesAnnotationTestSuite;
import org.easyrules.core.test.composite.CompositeRuleTest;
import org.easyrules.core.test.jmx.JmxRuleRegistrationTest;
import org.easyrules.core.test.parameters.RulePriorityComparisonTest;
import org.easyrules.core.test.parameters.RulePriorityThresholdTest;
import org.easyrules.core.test.parameters.SkipOnFirstAppliedRuleTest;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@ -21,7 +21,6 @@ import org.junit.runners.Suite;
RulePriorityComparisonTest.class,
RulePriorityThresholdTest.class,
SkipOnFirstAppliedRuleTest.class,
JmxRuleRegistrationTest.class,
CompositeRuleTest.class,
EasyRulesAnnotationTestSuite.class})
public class EasyRulesTestSuite extends TestSuite {

Loading…
Cancel
Save