The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
AppenderDynamicMBean.java
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file. */
package org.apache.log4j.jmx;
import java.lang.reflect.Constructor;
import org.apache.log4j.*;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.spi.OptionHandler;
import java.util.Vector;
import java.util.Hashtable;
import java.lang.reflect.Method;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.ObjectName;
import javax.management.MBeanInfo;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.MBeanException;
import javax.management.AttributeNotFoundException;
import javax.management.RuntimeOperationsException;
import javax.management.ReflectionException;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import java.beans.Introspector;
import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.beans.IntrospectionException;
public class AppenderDynamicMBean extends AbstractDynamicMBean {
private MBeanConstructorInfo[] dConstructors = new MBeanConstructorInfo[1];
private Vector dAttributes = new Vector();
private String dClassName = this.getClass().getName();
private Hashtable dynamicProps = new Hashtable(5);
private MBeanOperationInfo[] dOperations = new MBeanOperationInfo[2];
private String dDescription =
"This MBean acts as a management facade for log4j appenders.";
// This category instance is for logging.
private static Logger cat = Logger.getLogger(AppenderDynamicMBean.class);
// We wrap this appender instance.
private Appender appender;
public AppenderDynamicMBean(Appender appender) throws IntrospectionException {
this.appender = appender;
buildDynamicMBeanInfo();
}
private
void buildDynamicMBeanInfo() throws IntrospectionException {
Constructor[] constructors = this.getClass().getConstructors();
dConstructors[0] = new MBeanConstructorInfo(
"AppenderDynamicMBean(): Constructs a AppenderDynamicMBean instance",
constructors[0]);
BeanInfo bi = Introspector.getBeanInfo(appender.getClass());
PropertyDescriptor[] pd = bi.getPropertyDescriptors();
int size = pd.length;
for(int i = 0; i < size; i++) {
String name = pd[i].getName();
Method readMethod = pd[i].getReadMethod();
Method writeMethod = pd[i].getWriteMethod();
if(readMethod != null) {
Class returnClass = readMethod.getReturnType();
if(isSupportedType(returnClass)) {
String returnClassName;
if(returnClass.isAssignableFrom(Priority.class)) {
returnClassName = "java.lang.String";
} else {
returnClassName = returnClass.getName();
}
dAttributes.add(new MBeanAttributeInfo(name,
returnClassName,
"Dynamic",
true,
writeMethod != null,
false));
dynamicProps.put(name, new MethodUnion(readMethod, writeMethod));
}
}
}
MBeanParameterInfo[] params = new MBeanParameterInfo[0];
dOperations[0] = new MBeanOperationInfo("activateOptions",
"activateOptions(): add an appender",
params,
"void",
MBeanOperationInfo.ACTION);
params = new MBeanParameterInfo[1];
params[0] = new MBeanParameterInfo("layout class", "java.lang.String",
"layout class");
dOperations[1] = new MBeanOperationInfo("setLayout",
"setLayout(): add a layout",
params,
"void",
MBeanOperationInfo.ACTION);
}
private
boolean isSupportedType(Class clazz) {
if(clazz.isPrimitive()) {
return true;
}
if(clazz == String.class) {
return true;
}
if(clazz.isAssignableFrom(Priority.class)) {
return true;
}
return false;
}
public
MBeanInfo getMBeanInfo() {
cat.debug("getMBeanInfo called.");
MBeanAttributeInfo[] attribs = new MBeanAttributeInfo[dAttributes.size()];
dAttributes.toArray(attribs);
return new MBeanInfo(dClassName,
dDescription,
attribs,
dConstructors,
dOperations,
new MBeanNotificationInfo[0]);
}
public
Object invoke(String operationName, Object params[], String signature[])
throws MBeanException,
ReflectionException {
if(operationName.equals("activateOptions") &&
appender instanceof OptionHandler) {
OptionHandler oh = (OptionHandler) appender;
oh.activateOptions();
return "Options activated.";
} else if (operationName.equals("setLayout")) {
Layout layout = (Layout) OptionConverter.instantiateByClassName((String)
params[0],
Layout.class,
null);
appender.setLayout(layout);
registerLayoutMBean(layout);
}
return null;
}
void registerLayoutMBean(Layout layout) {
if(layout == null)
return;
String name = appender.getName()+",layout="+layout.getClass().getName();
cat.debug("Adding LayoutMBean:"+name);
ObjectName objectName = null;
try {
LayoutDynamicMBean appenderMBean = new LayoutDynamicMBean(layout);
objectName = new ObjectName("log4j:appender="+name);
server.registerMBean(appenderMBean, objectName);
dAttributes.add(new MBeanAttributeInfo("appender="+name,
"javax.management.ObjectName",
"The "+name+" layout.",
true,
true,
false));
} catch(Exception e) {
cat.error("Could not add DynamicLayoutMBean for ["+name+"].", e);
}
}
protected
Logger getLogger() {
return cat;
}
public
Object getAttribute(String attributeName) throws AttributeNotFoundException,
MBeanException,
ReflectionException {
// Check attributeName is not null to avoid NullPointerException later on
if (attributeName == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(
"Attribute name cannot be null"),
"Cannot invoke a getter of " + dClassName + " with null attribute name");
}
cat.debug("getAttribute called with ["+attributeName+"].");
if(attributeName.startsWith("appender="+appender.getName()+",layout")) {
try {
return new ObjectName("log4j:"+attributeName );
} catch(Exception e) {
cat.error("attributeName", e);
}
}
MethodUnion mu = (MethodUnion) dynamicProps.get(attributeName);
//cat.debug("----name="+attributeName+", b="+b);
if(mu != null && mu.readMethod != null) {
try {
return mu.readMethod.invoke(appender, null);
} catch(Exception e) {
return null;
}
}
// If attributeName has not been recognized throw an AttributeNotFoundException
throw(new AttributeNotFoundException("Cannot find " + attributeName +
" attribute in " + dClassName));
}
public
void setAttribute(Attribute attribute) throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
// Check attribute is not null to avoid NullPointerException later on
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute cannot be null"),
"Cannot invoke a setter of " + dClassName +
" with null attribute");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name cannot be null"),
"Cannot invoke the setter of "+dClassName+
" with null attribute name");
}
MethodUnion mu = (MethodUnion) dynamicProps.get(name);
if(mu != null && mu.writeMethod != null) {
Object[] o = new Object[1];
Class[] params = mu.writeMethod.getParameterTypes();
if(params[0] == org.apache.log4j.Priority.class) {
value = OptionConverter.toLevel((String) value,
(Level) getAttribute(name));
}
o[0] = value;
try {
mu.writeMethod.invoke(appender, o);
} catch(Exception e) {
cat.error("FIXME", e);
}
} else if(name.endsWith(".layout")) {
} else {
throw(new AttributeNotFoundException("Attribute " + name +
" not found in " +
this.getClass().getName()));
}
}
public
ObjectName preRegister(MBeanServer server, ObjectName name) {
cat.debug("preRegister called. Server="+server+ ", name="+name);
this.server = server;
registerLayoutMBean(appender.getLayout());
return name;
}
}