|
|
|
@ -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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|