You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2004/05/26 05:22:21 UTC
cvs commit: incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/serverinfo ServerInfo.java
dain 2004/05/25 20:22:21
Modified: modules/deployment/src/java/org/apache/geronimo/deployment/service
GBeanBuilder.java
modules/kernel/src/java/org/apache/geronimo/gbean/jmx
AbstractManagedObject.java DependencyService.java
DependencyServiceMBean.java GBeanMBean.java
GBeanMBeanOperation.java
ProxyMethodInterceptor.java
modules/kernel/src/java/org/apache/geronimo/kernel
Kernel.java
modules/kernel/src/java/org/apache/geronimo/kernel/jmx
JMXUtil.java
modules/system/src/java/org/apache/geronimo/system/serverinfo
ServerInfo.java
Added: modules/kernel/src/java/org/apache/geronimo/gbean/jmx
DependencyServiceProxy.java GBeanInvoker.java
JMXGBeanInvoker.java RawGBeanInvoker.java
RawInvoker.java
Log:
Added an index based invoker to GBeans
Added a DependencyServiceProxy to ease interaction with the dependency manager
Revision Changes Path
1.5 +1 -5 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
Index: GBeanBuilder.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GBeanBuilder.java 10 Mar 2004 09:58:49 -0000 1.4
+++ GBeanBuilder.java 26 May 2004 03:22:21 -0000 1.5
@@ -18,11 +18,9 @@
package org.apache.geronimo.deployment.service;
import java.beans.PropertyEditor;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.management.AttributeNotFoundException;
-import javax.management.InvalidAttributeValueException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@@ -66,8 +64,6 @@
throw new DeploymentException("Unable to find PropertyEditor for " + type, e);
} catch (AttributeNotFoundException e) {
throw new DeploymentException("Unknown attribute " + name);
- } catch (InvalidAttributeValueException e) {
- throw new DeploymentException("Invalid value for attribute " + name + ": " + text, e);
} catch (Exception e) {
throw new DeploymentException("Unable to set attribute " + name + " to " + text, e);
}
1.9 +2 -6 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
Index: AbstractManagedObject.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractManagedObject.java 23 Apr 2004 07:18:04 -0000 1.8
+++ AbstractManagedObject.java 26 May 2004 03:22:21 -0000 1.9
@@ -146,11 +146,7 @@
public synchronized ObjectName preRegister(MBeanServer server, ObjectName objectName) throws Exception {
this.server = server;
this.objectName = objectName;
- dependencyService = (DependencyServiceMBean) MBeanProxyFactory.getProxy(
- DependencyServiceMBean.class,
- server,
- new ObjectName("geronimo.boot:role=DependencyService2"));
-
+ dependencyService = new DependencyServiceProxy(server);
return objectName;
}
1.4 +3 -2 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/DependencyService.java
Index: DependencyService.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/DependencyService.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DependencyService.java 10 Mar 2004 09:59:00 -0000 1.3
+++ DependencyService.java 26 May 2004 03:22:21 -0000 1.4
@@ -36,6 +36,7 @@
import javax.management.ObjectName;
import org.apache.geronimo.kernel.jmx.JMXUtil;
+import org.apache.geronimo.kernel.Kernel;
/**
* DependencyService is the record keeper of the dependencies in Geronimo. The DependencyService
@@ -75,7 +76,7 @@
public ObjectName preRegister(MBeanServer server, ObjectName objectName) throws Exception {
if (objectName == null) {
- objectName = JMXUtil.DEPENDENCY_SERVICE_NAME;
+ objectName = Kernel.DEPENDENCY_SERVICE;
}
this.server = server;
1.4 +33 -20 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/DependencyServiceMBean.java
Index: DependencyServiceMBean.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/DependencyServiceMBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DependencyServiceMBean.java 10 Mar 2004 09:59:00 -0000 1.3
+++ DependencyServiceMBean.java 26 May 2004 03:22:21 -0000 1.4
@@ -17,80 +17,93 @@
package org.apache.geronimo.gbean.jmx;
+import java.util.Collection;
+import java.util.Set;
+import javax.management.ObjectName;
+
+import org.apache.geronimo.kernel.jmx.JMXUtil;
+
/**
* JMX MBean interface for {@link org.apache.geronimo.gbean.jmx.DependencyService}.
*
* @version $Revision$ $Date$
*/
-public interface DependencyServiceMBean
-{
-
+public interface DependencyServiceMBean {
/**
* Declares a dependency from a child to a parent.
- * @param child the dependent component
+ *
+ * @param child the dependent component
* @param parent the component the child is depending on
*/
- void addDependency(javax.management.ObjectName child,javax.management.ObjectName parent) ;
+ void addDependency(ObjectName child, ObjectName parent);
/**
* Removes a dependency from a child to a parent
- * @param child the dependnet component
+ *
+ * @param child the dependnet component
* @param parent the component that the child wil no longer depend on
*/
- void removeDependency(javax.management.ObjectName child,javax.management.ObjectName parent) ;
+ void removeDependency(ObjectName child, ObjectName parent);
/**
* Removes all dependencies for a child
+ *
* @param child the component that will no longer depend on anything
*/
- void removeAllDependencies(javax.management.ObjectName child) ;
+ void removeAllDependencies(ObjectName child);
/**
* Adds dependencies from the child to every parent in the parents set
- * @param child the dependent component
+ *
+ * @param child the dependent component
* @param parents the set of components the child is depending on
*/
- void addDependencies(javax.management.ObjectName child,java.util.Set parents) ;
+ void addDependencies(ObjectName child, Set parents);
/**
* Gets the set of parents that the child is depending on
+ *
* @param child the dependent component
* @return a collection containing all of the components the child depends on; will never be null
*/
- java.util.Set getParents(javax.management.ObjectName child) ;
+ Set getParents(ObjectName child);
/**
* Gets all of the MBeans that have a dependency on the specified startParent.
+ *
* @param parent the component the returned childen set depend on
* @return a collection containing all of the components that depend on the parent; will never be null
*/
- java.util.Set getChildren(javax.management.ObjectName parent) ;
+ Set getChildren(ObjectName parent);
/**
* Adds a hold on a collection of object name patterns. If the name of a component matches an object name pattern in the collection, the component should not start.
+ *
* @param objectName the name of the component placing the holds
- * @param holds a collection of object name patterns which should not start
+ * @param holds a collection of object name patterns which should not start
*/
- void addStartHolds(javax.management.ObjectName objectName,java.util.Collection holds) ;
+ void addStartHolds(ObjectName objectName, Collection holds);
/**
* Removes a collection of holds.
+ *
* @param objectName the object name of the components owning the holds
- * @param holds a collection of the holds to remove
+ * @param holds a collection of the holds to remove
*/
- void removeStartHolds(javax.management.ObjectName objectName,java.util.Collection holds) ;
+ void removeStartHolds(ObjectName objectName, Collection holds);
/**
* Removes all of the holds owned by a component.
+ *
* @param objectName the object name of the component that will no longer have any holds
*/
- void removeAllStartHolds(javax.management.ObjectName objectName) ;
+ void removeAllStartHolds(ObjectName objectName);
/**
* Gets the object name of the mbean blocking the start specified mbean.
+ *
* @param objectName the mbean to check for blockers
* @return the mbean blocking the specified mbean, or null if there are no blockers
*/
- javax.management.ObjectName checkBlocker(javax.management.ObjectName objectName) ;
-
+ ObjectName checkBlocker(ObjectName objectName);
}
1.15 +203 -137 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
Index: GBeanMBean.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- GBeanMBean.java 13 Mar 2004 23:48:56 -0000 1.14
+++ GBeanMBean.java 26 May 2004 03:22:21 -0000 1.15
@@ -29,11 +29,9 @@
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
-import javax.management.InvalidAttributeValueException;
import javax.management.JMException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
-import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
@@ -53,8 +51,6 @@
import org.apache.geronimo.kernel.jmx.MBeanOperationSignature;
import org.apache.geronimo.kernel.management.NotificationType;
-import net.sf.cglib.reflect.FastClass;
-
/**
* A GBeanMBean is a J2EE Management Managed Object, and is standard base for Geronimo services.
* This wraps one or more target POJOs and exposes the attributes and operations according to a supplied
@@ -64,7 +60,11 @@
* @version $Revision$ $Date$
*/
public class GBeanMBean extends AbstractManagedObject implements DynamicMBean {
- public static final FastClass fastClass = FastClass.create(GBeanMBean.class);
+ /**
+ * Method name used to retrieve the RawInvoker for the GBean
+ */
+ static final String RAW_INVOKER = "$$RAW_INVOKER$$";
+
private static final Log log = LogFactory.getLog(GBeanMBean.class);
/**
@@ -80,19 +80,34 @@
}
/**
+ * Attributes lookup table
+ */
+ private final GBeanMBeanAttribute[] attributes;
+
+ /**
* Attributes supported by this GBeanMBean by (String) name.
*/
- private final Map attributeMap = new HashMap();
+ private final Map attributeIndex = new HashMap();
+
+ /**
+ * References lookup table
+ */
+ private final GBeanMBeanReference[] references;
/**
* References supported by this GBeanMBean by (String) name.
*/
- private final Map referenceMap = new HashMap();
+ private final Map referenceIndex = new HashMap();
+
+ /**
+ * Operations lookup table
+ */
+ private final GBeanMBeanOperation[] operations;
/**
* Operations supported by this GBeanMBean by (MBeanOperationSignature) name.
*/
- private final Map operationMap = new HashMap();
+ private final Map operationIndex = new HashMap();
/**
* Notifications (MBeanNotificationInfo) fired by this mbean.
@@ -104,14 +119,41 @@
*/
private final ClassLoader classLoader;
+ /**
+ * Metadata describing the attributes, operations and references of this GBean
+ */
private final GBeanInfo gbeanInfo;
+
+ /**
+ * JMX sped mbeanInfo for this gbean (translation of the above gbeanInfo
+ */
private final MBeanInfo mbeanInfo;
+
+ /**
+ * Our name
+ */
private final String name;
+
+ /**
+ * Java type of the wrapped GBean class
+ */
private final Class type;
+ /**
+ * Is this gbean off line?
+ */
private boolean offline = true;
+
+ /**
+ * Target instance of this GBean wrapper
+ */
private Object target;
+ /**
+ * A fast index based raw invoker for this GBean.
+ */
+ private RawInvoker rawInvoker;
+
public GBeanMBean(GBeanInfo beanInfo, ClassLoader classLoader) throws InvalidConfigurationException {
this.gbeanInfo = beanInfo;
this.classLoader = classLoader;
@@ -124,49 +166,67 @@
name = beanInfo.getName();
- // attributes
Map constructorTypes = gbeanInfo.getConstructor().getAttributeTypeMap();
+
+ // attributes
+ Set attributesSet = new HashSet();
for (Iterator iterator = beanInfo.getAttributes().iterator(); iterator.hasNext();) {
GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next();
- addAttribute(new GBeanMBeanAttribute(this, attributeInfo, (Class) constructorTypes.get(attributeInfo.getName())));
+ attributesSet.add(new GBeanMBeanAttribute(this, attributeInfo, (Class) constructorTypes.get(attributeInfo.getName())));
+ }
+ addManagedObjectAttributes(attributesSet);
+ attributes = (GBeanMBeanAttribute[]) attributesSet.toArray(new GBeanMBeanAttribute[attributesSet.size()]);
+ for (int i = 0; i < attributes.length; i++) {
+ attributeIndex.put(attributes[i].getName(), new Integer(i));
}
// references
+ Set referencesSet = new HashSet();
for (Iterator iterator = beanInfo.getReferences().iterator(); iterator.hasNext();) {
GReferenceInfo referenceInfo = (GReferenceInfo) iterator.next();
- addReference(new GBeanMBeanReference(this, referenceInfo, (Class) constructorTypes.get(referenceInfo.getName())));
+ referencesSet.add(new GBeanMBeanReference(this, referenceInfo, (Class) constructorTypes.get(referenceInfo.getName())));
+ }
+ references = (GBeanMBeanReference[]) referencesSet.toArray(new GBeanMBeanReference[beanInfo.getReferences().size()]);
+ for (int i = 0; i < references.length; i++) {
+ referenceIndex.put(references[i].getName(), new Integer(i));
}
// operations
+ Set operationsSet = new HashSet();
for (Iterator iterator = beanInfo.getOperations().iterator(); iterator.hasNext();) {
GOperationInfo operationInfo = (GOperationInfo) iterator.next();
- addOperation(new GBeanMBeanOperation(this, operationInfo));
+ operationsSet.add(new GBeanMBeanOperation(this, operationInfo));
+ }
+ addManagedObjectOperations(operationsSet);
+ operations = (GBeanMBeanOperation[]) operationsSet.toArray(new GBeanMBeanOperation[beanInfo.getOperations().size()]);
+ for (int i = 0; i < operations.length; i++) {
+ GBeanMBeanOperation operation = operations[i];
+ MBeanOperationSignature signature = new MBeanOperationSignature(operation.getName(), operation.getParameterTypes());
+ operationIndex.put(signature, new Integer(i));
}
- // add all attributes and operations from the ManagedObject interface
- addManagedObjectInterface();
+ // add notification type from the ManagedObject interface
+ notifications.add(new MBeanNotificationInfo(
+ NotificationType.TYPES,
+ "javax.management.Notification",
+ "J2EE Notifications"));
- int idx;
- idx = 0;
- MBeanAttributeInfo[] mbeanAttrs = new MBeanAttributeInfo[attributeMap.size()];
- for (Iterator i = attributeMap.values().iterator(); i.hasNext();) {
- GBeanMBeanAttribute attr = (GBeanMBeanAttribute) i.next();
- mbeanAttrs[idx++] = attr.getMBeanAttributeInfo();
+ MBeanAttributeInfo[] mbeanAttributes = new MBeanAttributeInfo[attributes.length];
+ for (int i = 0; i < attributes.length; i++) {
+ mbeanAttributes[i] = attributes[i].getMBeanAttributeInfo();
}
- idx = 0;
- MBeanOperationInfo[] mbeanOps = new MBeanOperationInfo[operationMap.size()];
- for (Iterator i = operationMap.values().iterator(); i.hasNext();) {
- GBeanMBeanOperation op = (GBeanMBeanOperation) i.next();
- mbeanOps[idx++] = op.getMbeanOperationInfo();
+ MBeanOperationInfo[] mbeanOperations = new MBeanOperationInfo[operations.length];
+ for (int i = 0; i < operations.length; i++) {
+ mbeanOperations[i] = operations[i].getMbeanOperationInfo();
}
mbeanInfo = new MBeanInfo(
beanInfo.getClassName(),
null,
- mbeanAttrs,
+ mbeanAttributes,
new MBeanConstructorInfo[0],
- mbeanOps,
+ mbeanOperations,
// Is there any way to add notifications before an instance of the class is created?
(MBeanNotificationInfo[]) notifications.toArray(new MBeanNotificationInfo[notifications.size()]));
}
@@ -218,10 +278,25 @@
return target;
}
+ public Map getAttributeIndex() {
+ return Collections.unmodifiableMap(new HashMap(attributeIndex));
+ }
+
+ public Map getOperationIndex() {
+ return Collections.unmodifiableMap(new HashMap(operationIndex));
+ }
+
+ public GBeanInfo getGBeanInfo() {
+ return gbeanInfo;
+ }
+
+ public MBeanInfo getMBeanInfo() {
+ return mbeanInfo;
+ }
+
public synchronized ObjectName preRegister(MBeanServer server, ObjectName objectName) throws Exception {
ObjectName returnValue = super.preRegister(server, objectName);
-
// get the constructor
GConstructorInfo constructorInfo = gbeanInfo.getConstructor();
Class[] parameterTypes = (Class[]) constructorInfo.getTypes().toArray(new Class[constructorInfo.getTypes().size()]);
@@ -233,10 +308,10 @@
Iterator assertedTypes = constructorInfo.getTypes().iterator();
for (int i = 0; i < parameters.length; i++) {
String name = (String) names.next();
- if (attributeMap.containsKey(name)) {
+ if (attributeIndex.containsKey(name)) {
parameters[i] = getAttribute(name);
- } else if (referenceMap.containsKey(name)) {
- GBeanMBeanReference reference = (GBeanMBeanReference) referenceMap.get(name);
+ } else if (referenceIndex.containsKey(name)) {
+ GBeanMBeanReference reference = getReferenceByName(name);
reference.online();
parameters[i] = reference.getProxy();
} else {
@@ -264,20 +339,23 @@
}
// bring all of the attributes online
- for (Iterator iterator = attributeMap.values().iterator(); iterator.hasNext();) {
- GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) iterator.next();
- attribute.online();
+ for (int i = 0; i < attributes.length; i++) {
+ attributes[i].online();
}
// bring any reference not used in the constructor online
// @todo this code sucks, but works
- for (Iterator iterator = referenceMap.values().iterator(); iterator.hasNext();) {
- GBeanMBeanReference reference = (GBeanMBeanReference) iterator.next();
+ for (int i = 0; i < references.length; i++) {
+ GBeanMBeanReference reference = references[i];
if (!constructorInfo.getAttributeNames().contains(reference.getName())) {
reference.online();
}
}
+ // create the raw invoker for this gbean.... this MUST be closed
+ // when the gbean goes offline or we will get a memory leak
+ rawInvoker = new RawInvoker(this);
+
return returnValue;
}
@@ -293,9 +371,14 @@
offline = false;
} else {
// we need to bring the reference back off line
- for (Iterator iterator = referenceMap.values().iterator(); iterator.hasNext();) {
- GBeanMBeanReference reference = (GBeanMBeanReference) iterator.next();
- reference.offline();
+ for (int i = 0; i < references.length; i++) {
+ references[i].offline();
+ }
+
+ // clean up the raw invoker... this holds a reference to this gbean (a possible memory leak)
+ if (rawInvoker != null) {
+ rawInvoker.close();
+ rawInvoker = null;
}
// well that didn't work, ditch the instance
@@ -305,15 +388,13 @@
public void postDeregister() {
// take all of the attributes offline
- for (Iterator iterator = attributeMap.values().iterator(); iterator.hasNext();) {
- GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) iterator.next();
- attribute.offline();
+ for (int i = 0; i < attributes.length; i++) {
+ attributes[i].offline();
}
// take all of the reference offline
- for (Iterator iterator = referenceMap.values().iterator(); iterator.hasNext();) {
- GBeanMBeanReference reference = (GBeanMBeanReference) iterator.next();
- reference.offline();
+ for (int i = 0; i < references.length; i++) {
+ references[i].offline();
}
if (target instanceof GBean) {
@@ -321,25 +402,22 @@
gbean.setGBeanContext(null);
}
+ // clean up the raw invoker... this holds a reference to this gbean (a possible memory leak)
+ if (rawInvoker != null) {
+ rawInvoker.close();
+ rawInvoker = null;
+ }
+
offline = true;
target = null;
super.postDeregister();
}
- public GBeanInfo getGBeanInfo() {
- return gbeanInfo;
- }
-
- public MBeanInfo getMBeanInfo() {
- return mbeanInfo;
- }
-
protected void doStart() throws Exception {
// start all of the references
- for (Iterator iterator = referenceMap.values().iterator(); iterator.hasNext();) {
- GBeanMBeanReference reference = (GBeanMBeanReference) iterator.next();
- reference.start();
+ for (int i = 0; i < references.length; i++) {
+ references[i].start();
}
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
@@ -365,9 +443,8 @@
}
// stop all of the references
- for (Iterator iterator = referenceMap.values().iterator(); iterator.hasNext();) {
- GBeanMBeanReference reference = (GBeanMBeanReference) iterator.next();
- reference.stop();
+ for (int i = 0; i < references.length; i++) {
+ references[i].stop();
}
}
@@ -383,39 +460,39 @@
}
// stop all of the references
- for (Iterator iterator = referenceMap.values().iterator(); iterator.hasNext();) {
- GBeanMBeanReference reference = (GBeanMBeanReference) iterator.next();
- reference.stop();
+ for (int i = 0; i < references.length; i++) {
+ references[i].stop();
}
}
- public Object getAttribute(String attributeName) throws AttributeNotFoundException, MBeanException, ReflectionException {
- GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) attributeMap.get(attributeName);
- if (attribute == null) {
- throw new AttributeNotFoundException("Unknown attribute " + attributeName);
- }
-
+ public Object getAttribute(int index) throws ReflectionException {
+ GBeanMBeanAttribute attribute = attributes[index];
return attribute.getValue();
}
- public void setAttribute(Attribute attributeValue) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
- GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) attributeMap.get(attributeValue.getName());
- if (attribute == null) {
- throw new AttributeNotFoundException("Unknown attribute " + attributeValue.getName());
+ public Object getAttribute(String attributeName) throws ReflectionException, AttributeNotFoundException {
+ GBeanMBeanAttribute attribute = getAttributeByName(attributeName);
+ if (attribute == null && attributeName.equals(RAW_INVOKER)) {
+ return rawInvoker;
}
-
- attribute.setValue(attributeValue.getValue());
+ return attribute.getValue();
}
- public void setAttribute(String name, Object value) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
- GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) attributeMap.get(name);
- if (attribute == null) {
- throw new AttributeNotFoundException("Unknown attribute " + name);
- }
+ public void setAttribute(int index, Object value) throws ReflectionException, AttributeNotFoundException {
+ GBeanMBeanAttribute attribute = attributes[index];
+ attribute.setValue(value);
+ }
+ public void setAttribute(String name, Object value) throws ReflectionException, AttributeNotFoundException {
+ GBeanMBeanAttribute attribute = getAttributeByName(name);
attribute.setValue(value);
}
+ public void setAttribute(Attribute attributeValue) throws ReflectionException, AttributeNotFoundException {
+ GBeanMBeanAttribute attribute = getAttributeByName(attributeValue.getName());
+ attribute.setValue(attributeValue.getValue());
+ }
+
public AttributeList getAttributes(String[] attributes) {
AttributeList results = new AttributeList(attributes.length);
for (int i = 0; i < attributes.length; i++) {
@@ -444,68 +521,59 @@
return results;
}
- public Object invoke(String methodName, Object[] arguments, String[] types) throws MBeanException, ReflectionException {
- MBeanOperationSignature key = new MBeanOperationSignature(methodName, types);
- Object operation = operationMap.get(key);
- if (operation == null) {
- throw new ReflectionException(new NoSuchMethodException("Unknown operation " + key));
- }
-
-
- // If this is an attribute accessor get call the getAttibute or setAttribute method
- if (operation instanceof GBeanMBeanAttribute) {
- if (arguments == null || arguments.length == 0) {
- return ((GBeanMBeanAttribute) operation).getValue();
- } else {
- ((GBeanMBeanAttribute) operation).setValue(arguments[0]);
+ private GBeanMBeanAttribute getAttributeByName(String name) throws AttributeNotFoundException {
+ Integer index = (Integer) attributeIndex.get(name);
+ if (index == null) {
+ // if this is a request for the raw invoker we need to return null
+ // todo switch this to an attribute when fixing the ManagedObject interface attributes
+ if (name.equals(RAW_INVOKER)) {
return null;
}
+ throw new AttributeNotFoundException("Unknown attribute " + name);
}
-
- return ((GBeanMBeanOperation) operation).invoke(arguments);
+ GBeanMBeanAttribute attribute = attributes[index.intValue()];
+ return attribute;
}
- public Set getReferencePatterns(String name) {
- GBeanMBeanReference reference = (GBeanMBeanReference) referenceMap.get(name);
- if (reference == null) {
- throw new IllegalArgumentException("Unknown reference " + name);
- }
- return reference.getPatterns();
+ public Object invoke(int index, Object[] arguments) throws ReflectionException {
+ GBeanMBeanOperation operation = operations[index];
+ return operation.invoke(arguments);
}
- public void setReferencePatterns(String name, Set patterns) {
- GBeanMBeanReference reference = (GBeanMBeanReference) referenceMap.get(name);
- if (reference == null) {
- throw new IllegalArgumentException("Unknown reference " + name);
+ public Object invoke(String methodName, Object[] arguments, String[] types) throws ReflectionException {
+ MBeanOperationSignature signature = new MBeanOperationSignature(methodName, types);
+ Integer index = (Integer) operationIndex.get(signature);
+ if (index == null) {
+ throw new ReflectionException(new NoSuchMethodException("Unknown operation " + signature));
}
- reference.setPatterns(patterns);
+ GBeanMBeanOperation operation = operations[index.intValue()];
+ return operation.invoke(arguments);
}
- public MBeanNotificationInfo[] getNotificationInfo() {
- return mbeanInfo.getNotifications();
+ public Set getReferencePatterns(String name) {
+ return getReferenceByName(name).getPatterns();
}
- private void addAttribute(GBeanMBeanAttribute mbeanAttribute) {
- String attributeName = mbeanAttribute.getName();
-
- // add to attribute map
- attributeMap.put(attributeName, mbeanAttribute);
+ public void setReferencePatterns(String name, Set patterns) {
+ getReferenceByName(name).setPatterns(patterns);
}
- private void addReference(GBeanMBeanReference mbeanReference) {
- String referenceName = mbeanReference.getName();
-
- // add to reference map
- referenceMap.put(referenceName, mbeanReference);
+ private GBeanMBeanReference getReferenceByName(String name) {
+ Integer index = (Integer) referenceIndex.get(name);
+ if (index == null) {
+ throw new IllegalArgumentException("Unknown reference " + name);
+ }
+ GBeanMBeanReference reference = references[index.intValue()];
+ return reference;
}
- private void addOperation(GBeanMBeanOperation mbeanOperation) {
- MBeanOperationSignature signature = new MBeanOperationSignature(mbeanOperation.getName(), mbeanOperation.getParameterTypes());
- operationMap.put(signature, mbeanOperation);
+ public MBeanNotificationInfo[] getNotificationInfo() {
+ return mbeanInfo.getNotifications();
}
- private void addManagedObjectInterface() {
- addAttribute(new GBeanMBeanAttribute(
+ private void addManagedObjectAttributes(Set attributesSet) {
+ // todo none of these are going to be handled by the rawInvoker
+ attributesSet.add(new GBeanMBeanAttribute(
this,
"state",
Integer.TYPE,
@@ -516,7 +584,7 @@
},
null));
- addAttribute(new GBeanMBeanAttribute(
+ attributesSet.add(new GBeanMBeanAttribute(
this,
"objectName",
String.class,
@@ -527,7 +595,7 @@
},
null));
- addAttribute(new GBeanMBeanAttribute(
+ attributesSet.add(new GBeanMBeanAttribute(
this,
"startTime",
Long.TYPE,
@@ -538,7 +606,7 @@
},
null));
- addAttribute(new GBeanMBeanAttribute(
+ attributesSet.add(new GBeanMBeanAttribute(
this,
"stateManageable",
Boolean.TYPE,
@@ -549,7 +617,7 @@
},
null));
- addAttribute(new GBeanMBeanAttribute(
+ attributesSet.add(new GBeanMBeanAttribute(
this,
"statisticsProvider",
Boolean.TYPE,
@@ -561,7 +629,7 @@
null));
- addAttribute(new GBeanMBeanAttribute(
+ attributesSet.add(new GBeanMBeanAttribute(
this,
"eventProvider",
Boolean.TYPE,
@@ -571,8 +639,11 @@
}
},
null));
+ }
- addOperation(new GBeanMBeanOperation(
+ private void addManagedObjectOperations(Set operationsSet) {
+ // todo none of these are going to be handled by the rawInvoker
+ operationsSet.add(new GBeanMBeanOperation(
this,
"start",
Collections.EMPTY_LIST,
@@ -584,7 +655,7 @@
}
}));
- addOperation(new GBeanMBeanOperation(
+ operationsSet.add(new GBeanMBeanOperation(
this,
"startRecursive",
Collections.EMPTY_LIST,
@@ -596,7 +667,7 @@
}
}));
- addOperation(new GBeanMBeanOperation(
+ operationsSet.add(new GBeanMBeanOperation(
this,
"stop",
Collections.EMPTY_LIST,
@@ -607,10 +678,5 @@
return null;
}
}));
-
- notifications.add(new MBeanNotificationInfo(
- NotificationType.TYPES,
- "javax.management.Notification",
- "J2EE Notifications"));
}
}
1.9 +2 -3 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java
Index: GBeanMBeanOperation.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- GBeanMBeanOperation.java 21 Mar 2004 22:24:39 -0000 1.8
+++ GBeanMBeanOperation.java 26 May 2004 03:22:21 -0000 1.9
@@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import javax.management.MBeanException;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.ReflectionException;
@@ -142,7 +141,7 @@
return mbeanOperationInfo;
}
- public Object invoke(Object[] arguments) throws MBeanException, ReflectionException {
+ public Object invoke(Object[] arguments) throws ReflectionException {
if (gmbean.isOffline()) {
throw new IllegalStateException("Operations can not be called while offline");
}
1.10 +122 -75 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyMethodInterceptor.java
Index: ProxyMethodInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyMethodInterceptor.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ProxyMethodInterceptor.java 10 Mar 2004 09:59:01 -0000 1.9
+++ ProxyMethodInterceptor.java 26 May 2004 03:22:21 -0000 1.10
@@ -18,26 +18,22 @@
package org.apache.geronimo.gbean.jmx;
import java.lang.reflect.Method;
-import java.util.HashMap;
import java.util.Map;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
-import javax.management.MBeanOperationInfo;
+import java.util.HashMap;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-
-import org.apache.geronimo.kernel.jmx.InvokeMBean;
-import org.apache.geronimo.kernel.jmx.MBeanOperationSignature;
+import javax.management.MBeanInfo;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanOperationInfo;
import net.sf.cglib.core.Signature;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import net.sf.cglib.reflect.FastClass;
+import org.apache.geronimo.kernel.jmx.MBeanOperationSignature;
import org.objectweb.asm.Type;
/**
- *
- *
* @version $Revision$ $Date$
*/
public final class ProxyMethodInterceptor implements MethodInterceptor {
@@ -47,19 +43,14 @@
private final Class proxyType;
/**
- * The MBeanServer we are using.
- */
- private MBeanServer server;
-
- /**
* The object name to which we are connected.
*/
private ObjectName objectName;
/**
- * Map from interface method ids to InvokeMBean objects.
+ * GBeanInvokers keyed on the proxy interface method index
*/
- private InvokeMBean[] methodTable;
+ private GBeanInvoker[] gbeanInvokers;
/**
* Is this proxy currently stoped. If it is invocations will not be allowed.
@@ -78,22 +69,20 @@
public synchronized void connect(MBeanServer server, ObjectName objectName, boolean stopped) {
assert server != null && objectName != null;
- this.server = server;
this.objectName = objectName;
this.stopped = stopped;
- this.methodTable = ProxyMethodInterceptor.createMethodTable(server, objectName, proxyType);
+ gbeanInvokers = createGBeanInvokers(server, objectName, proxyType);
}
public synchronized void disconnect() {
stopped = true;
- this.server = null;
- this.objectName = null;
- this.methodTable = null;
+ objectName = null;
+ gbeanInvokers = null;
}
public synchronized void start() {
- if (server == null || objectName == null) {
- throw new IllegalStateException("Server or objectName is null");
+ if (gbeanInvokers == null) {
+ throw new IllegalStateException("Proxy is not connected");
}
this.stopped = false;
}
@@ -102,30 +91,95 @@
this.stopped = true;
}
- /**
- * Handles an invocation on a proxy
- * @param object the proxy instance
- * @param method java method that was invoked
- * @param args arguments to the mentod
- * @param proxy a CGLib method proxy of the method invoked
- * @return the result of the invocation
- * @throws java.lang.Throwable if any exceptions are thrown by the implementation method
- */
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) throws Throwable {
+ GBeanInvoker gbeanInvoker;
+
+ int interfaceIndex = proxy.getSuperIndex();
synchronized (this) {
if (stopped) {
throw new IllegalStateException("Proxy is stopped");
}
+ gbeanInvoker = gbeanInvokers[interfaceIndex];
+ }
+
+ if (gbeanInvoker == null) {
+ throw new NoSuchOperationError("No implementation method: objectName=" + objectName + ", method=" + method);
}
- InvokeMBean invoker = methodTable[proxy.getSuperIndex()];
- if (invoker == null) {
- throw new NoSuchOperationError("No implementation method:" +
- " objectName=" + objectName + ", method=" + method);
+
+ return gbeanInvoker.invoke(objectName, args);
+ }
+
+ public GBeanInvoker[] createGBeanInvokers(MBeanServer server, ObjectName objectName, Class proxyType) {
+ GBeanInvoker[] invokers;
+ try {
+ RawInvoker rawInvoker = (RawInvoker) server.getAttribute(objectName, GBeanMBean.RAW_INVOKER);
+ invokers = createRawGBeanInvokers(rawInvoker, objectName, proxyType);
+ } catch (Exception e) {
+ invokers = createJMXGBeanInvokers(server, objectName, proxyType);
+ }
+
+ // handle equals, hashCode and toString directly here
+ try {
+ invokers[getSuperIndex(proxyType, proxyType.getMethod("equals", new Class[]{Object.class}))] = new EqualsInvoke();
+ invokers[getSuperIndex(proxyType, proxyType.getMethod("hashCode", null))] = new HashCodeInvoke();
+ invokers[getSuperIndex(proxyType, proxyType.getMethod("toString", null))] = new ToStringInvoke(proxyType.getName());
+ } catch (Exception e) {
+ // this can not happen... all classes must implement equals, hashCode and toString
+ throw new AssertionError(e);
}
- return invoker.invoke(server, objectName, args);
+
+ return invokers;
}
- public static InvokeMBean[] createMethodTable(MBeanServer server, ObjectName objectName, Class proxyType) {
+ public GBeanInvoker[] createRawGBeanInvokers(RawInvoker rawInvoker, ObjectName objectName, Class proxyType) {
+ Map operations = rawInvoker.getOperationIndex();
+ Map attributes = rawInvoker.getAttributeIndex();
+
+ // build the method lookup table
+ FastClass fastClass = FastClass.create(proxyType);
+ GBeanInvoker[] invokers = new GBeanInvoker[fastClass.getMaxIndex() + 1];
+ Method[] methods = proxyType.getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ int interfaceIndex = getSuperIndex(proxyType, method);
+ if (interfaceIndex >= 0) {
+ invokers[interfaceIndex] = createRawGBeanInvoker(rawInvoker, method, operations, attributes);
+ }
+ }
+
+ return invokers;
+ }
+
+ private GBeanInvoker createRawGBeanInvoker(RawInvoker rawInvoker, Method method, Map operations, Map attributes) {
+ if (operations.containsKey(new MBeanOperationSignature(method))) {
+ int methodIndex = ((Integer) operations.get(new MBeanOperationSignature(method))).intValue();
+ return new RawGBeanInvoker(rawInvoker, methodIndex, GBeanInvoker.OPERATION);
+ }
+
+ if (method.getName().startsWith("get")) {
+ Integer methodIndex = ((Integer) attributes.get(method.getName().substring(3)));
+ if (methodIndex != null) {
+ return new RawGBeanInvoker(rawInvoker, methodIndex.intValue(), GBeanInvoker.GETTER);
+ }
+ }
+
+ if (method.getName().startsWith("is")) {
+ Integer methodIndex = ((Integer) attributes.get(method.getName().substring(2)));
+ if (methodIndex != null) {
+ return new RawGBeanInvoker(rawInvoker, methodIndex.intValue(), GBeanInvoker.GETTER);
+ }
+ }
+
+ if (method.getName().startsWith("set")) {
+ Integer methodIndex = ((Integer) attributes.get(method.getName().substring(3)));
+ if (methodIndex != null) {
+ return new RawGBeanInvoker(rawInvoker, methodIndex.intValue(), GBeanInvoker.SETTER);
+ }
+ }
+ return null;
+ }
+
+ public GBeanInvoker[] createJMXGBeanInvokers(MBeanServer server, ObjectName objectName, Class proxyType) {
MBeanInfo info = null;
try {
info = server.getMBeanInfo(objectName);
@@ -151,35 +205,36 @@
// build the method lookup table
FastClass fastClass = FastClass.create(proxyType);
- InvokeMBean[] methodTable = new InvokeMBean[fastClass.getMaxIndex() + 1];
+ GBeanInvoker[] invokers = new GBeanInvoker[fastClass.getMaxIndex() + 1];
Method[] methods = proxyType.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
- int index = getSuperIndex(proxyType, method);
- if (index >= 0) {
- if (operations.containsKey(new MBeanOperationSignature(method))) {
- methodTable[index] = new InvokeMBean(method, false, false);
- } else if (method.getName().startsWith("get") && attributes.containsKey(method.getName().substring(3))) {
- methodTable[index] = new InvokeMBean(method, true, true);
- } else if (method.getName().startsWith("is") && attributes.containsKey(method.getName().substring(2))) {
- methodTable[index] = new InvokeMBean(method, true, true);
- } else if (method.getName().startsWith("set") && attributes.containsKey(method.getName().substring(3))) {
- methodTable[index] = new InvokeMBean(method, true, false);
- }
+ int interfaceIndex = getSuperIndex(proxyType, method);
+ if (interfaceIndex >= 0) {
+ invokers[interfaceIndex] = createJMXGBeanInvoker(server, method, operations, attributes);
}
}
- // handle equals, hashCode and toString directly here
- try {
- methodTable[getSuperIndex(proxyType, proxyType.getMethod("equals", new Class[]{Object.class}))] = new EqualsInvoke();
- methodTable[getSuperIndex(proxyType, proxyType.getMethod("hashCode", null))] = new HashCodeInvoke();
- methodTable[getSuperIndex(proxyType, proxyType.getMethod("toString", null))] = new ToStringInvoke(proxyType.getName());
- } catch (Exception e) {
- // this can not happen... all classes must implement equals, hashCode and toString
- throw new AssertionError(e);
+ return invokers;
+ }
+
+ private GBeanInvoker createJMXGBeanInvoker(MBeanServer server, Method method, Map operations, Map attributes) {
+ if (operations.containsKey(new MBeanOperationSignature(method))) {
+ return new JMXGBeanInvoker(server, method, GBeanInvoker.OPERATION);
}
- return methodTable;
+ if (method.getName().startsWith("get") && attributes.containsKey(method.getName().substring(3))) {
+ return new JMXGBeanInvoker(server, method, GBeanInvoker.GETTER);
+ }
+
+ if (method.getName().startsWith("is") && attributes.containsKey(method.getName().substring(2))) {
+ return new JMXGBeanInvoker(server, method, GBeanInvoker.GETTER);
+ }
+
+ if (method.getName().startsWith("set") && attributes.containsKey(method.getName().substring(3))) {
+ return new JMXGBeanInvoker(server, method, GBeanInvoker.SETTER);
+ }
+ return null;
}
private static int getSuperIndex(Class proxyType, Method method) {
@@ -191,35 +246,27 @@
return -1;
}
- private static final class HashCodeInvoke extends InvokeMBean {
- public HashCodeInvoke() {
- super("hashCode", new String[0], new Class[0], false, false, 0);
- }
-
- public Object invoke(MBeanServer server, ObjectName objectName, Object[] arguments) throws Throwable {
+ private static final class HashCodeInvoke implements GBeanInvoker {
+ public Object invoke(ObjectName objectName, Object[] arguments) throws Throwable {
return new Integer(objectName.hashCode());
}
}
- private static final class EqualsInvoke extends InvokeMBean {
- public EqualsInvoke() {
- super("hashCode", new String[]{"java.lang.Object"}, new Class[]{Object.class}, false, false, 1);
- }
-
- public Object invoke(MBeanServer server, ObjectName objectName, Object[] arguments) throws Throwable {
+ private static final class EqualsInvoke implements GBeanInvoker {
+ public Object invoke(ObjectName objectName, Object[] arguments) throws Throwable {
+ // todo this is broken.. we need a way to extract the object name from the other proxy
return new Boolean(objectName.equals(arguments[0]));
}
}
- private static final class ToStringInvoke extends InvokeMBean {
+ private static final class ToStringInvoke implements GBeanInvoker {
private final String interfaceName;
public ToStringInvoke(String interfaceName) {
- super("toString", new String[0], new Class[0], false, false, 0);
this.interfaceName = "[" + interfaceName + ": ";
}
- public Object invoke(MBeanServer server, ObjectName objectName, Object[] arguments) throws Throwable {
+ public Object invoke(ObjectName objectName, Object[] arguments) throws Throwable {
return interfaceName + objectName + "]";
}
}
1.1 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/DependencyServiceProxy.java
Index: DependencyServiceProxy.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.gbean.jmx;
import java.util.Collection;
import java.util.Set;
import javax.management.JMException;
import javax.management.JMRuntimeException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.geronimo.kernel.Kernel;
/**
* @version $Revision: 1.1 $ $Date: 2004/05/26 03:22:21 $
*/
public final class DependencyServiceProxy implements DependencyServiceMBean {
private final MBeanServer server;
public DependencyServiceProxy(MBeanServer server) {
this.server = server;
}
public void addDependency(ObjectName child, ObjectName parent) {
invoke("addDependency",
new Object[] {child, parent},
new String[] {ObjectName.class.getName(), ObjectName.class.getName()});
}
public void removeDependency(ObjectName child, ObjectName parent) {
invoke("removeDependency",
new Object[] {child, parent},
new String[] {ObjectName.class.getName(), ObjectName.class.getName()});
}
public void removeAllDependencies(ObjectName child) {
invoke("removeAllDependencies",
new Object[] {child},
new String[] {ObjectName.class.getName()});
}
public void addDependencies(ObjectName child, Set parents) {
invoke("addDependencies",
new Object[] {child, parents},
new String[] {ObjectName.class.getName(), Set.class.getName()});
}
public Set getParents(ObjectName child) {
return (Set) invoke("getParents",
new Object[] {child},
new String[] {ObjectName.class.getName()});
}
public Set getChildren(ObjectName parent) {
return (Set) invoke("getChildren",
new Object[] {parent},
new String[] {ObjectName.class.getName()});
}
public void addStartHolds(ObjectName objectName, Collection holds) {
invoke("addStartHolds",
new Object[] {objectName, holds},
new String[] {ObjectName.class.getName(), Collection.class.getName()});
}
public void removeStartHolds(ObjectName objectName, Collection holds) {
invoke("removeStartHolds",
new Object[] {objectName, holds},
new String[] {ObjectName.class.getName(), Collection.class.getName()});
}
public void removeAllStartHolds(ObjectName objectName) {
invoke("removeAllStartHolds",
new Object[] {objectName},
new String[] {ObjectName.class.getName()});
}
public ObjectName checkBlocker(ObjectName objectName) {
return (ObjectName) invoke("checkBlocker",
new Object[] {objectName},
new String[] {ObjectName.class.getName()});
}
private Object invoke(String operationName, Object[] params, String[] signature) {
try {
return server.invoke(Kernel.DEPENDENCY_SERVICE, operationName, params, signature);
} catch (JMException e) {
Throwable cause = e;
while ((cause instanceof JMException || cause instanceof JMRuntimeException) && cause.getCause() != null) {
cause = cause.getCause();
}
if (cause instanceof Error) {
throw (Error) cause;
} else if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
throw new AssertionError(cause);
}
}
}
}
1.1 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanInvoker.java
Index: GBeanInvoker.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.gbean.jmx;
import javax.management.ObjectName;
/**
* @version $Revision: 1.1 $ $Date: 2004/05/26 03:22:21 $
*/
public interface GBeanInvoker {
int OPERATION = 1;
int GETTER = 2;
int SETTER = 3;
Object invoke(ObjectName objectName, Object[] arguments) throws Throwable;
}
1.1 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXGBeanInvoker.java
Index: JMXGBeanInvoker.java
===================================================================
/**
*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.gbean.jmx;
import java.lang.reflect.Method;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.MBeanException;
import javax.management.ReflectionException;
import javax.management.RuntimeOperationsException;
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeErrorException;
import javax.management.Attribute;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/05/26 03:22:21 $
*/
public final class JMXGBeanInvoker implements GBeanInvoker {
private final MBeanServer server;
private final int methodType;
private final String name;
private final String[] argumentTypes;
private final Class[] declaredExceptions;
public JMXGBeanInvoker(MBeanServer server, Method method, int methodType) {
this.server = server;
this.methodType = methodType;
if (methodType == GBeanInvoker.OPERATION) {
name = method.getName();
} else {
// strip off the is, get, or set from the method name
if(method.getName().startsWith("is")) {
name = method.getName().substring(2);
} else {
name = method.getName().substring(3);
}
}
// convert the parameters to a MBeanServer friendly string array
Class[] parameters = method.getParameterTypes();
argumentTypes = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
argumentTypes[i] = parameters[i].getName();
}
declaredExceptions = method.getExceptionTypes();
}
public Object invoke(ObjectName objectName, Object[] arguments) throws Throwable {
try {
switch (methodType) {
case GBeanInvoker.OPERATION:
return server.invoke(objectName, name, arguments, argumentTypes);
case GBeanInvoker.GETTER:
return server.getAttribute(objectName, name);
case GBeanInvoker.SETTER:
server.setAttribute(objectName, new Attribute(name, arguments[0]));
return null;
default:
throw new AssertionError();
}
} catch (Throwable t) {
Throwable throwable = t;
while (true) {
for (int i = 0; i < declaredExceptions.length; i++) {
Class declaredException = declaredExceptions[i];
if (declaredException.isInstance(throwable)) {
throw throwable;
}
}
// Unwrap the exceptions we understand
if (throwable instanceof MBeanException) {
throwable = (((MBeanException) throwable).getTargetException());
} else if (throwable instanceof ReflectionException) {
throwable = (((ReflectionException) throwable).getTargetException());
} else if (throwable instanceof RuntimeOperationsException) {
throwable = (((RuntimeOperationsException) throwable).getTargetException());
} else if (throwable instanceof RuntimeMBeanException) {
throwable = (((RuntimeMBeanException) throwable).getTargetException());
} else if (throwable instanceof RuntimeErrorException) {
throwable = (((RuntimeErrorException) throwable).getTargetError());
} else {
// don't know how to unwrap this, just throw it
throw throwable;
}
}
}
}
}
1.1 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawGBeanInvoker.java
Index: RawGBeanInvoker.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.gbean.jmx;
import javax.management.ObjectName;
/**
* @version $Revision: 1.1 $ $Date: 2004/05/26 03:22:21 $
*/
public class RawGBeanInvoker implements GBeanInvoker {
private final RawInvoker rawInvoker;
private final int methodType;
private final int methodIndex;
public RawGBeanInvoker(RawInvoker rawInvoker, int methodIndex, int methodType) {
this.rawInvoker = rawInvoker;
this.methodIndex = methodIndex;
this.methodType = methodType;
}
public Object invoke(ObjectName objectName, Object[] arguments) throws Throwable {
switch (methodType) {
case GBeanInvoker.OPERATION:
return rawInvoker.invoke(methodIndex, arguments);
case GBeanInvoker.GETTER:
return rawInvoker.getAttribute(methodIndex);
case GBeanInvoker.SETTER:
rawInvoker.setAttribute(methodIndex, arguments[0]);
return null;
default:
throw new AssertionError();
}
}
}
1.1 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java
Index: RawInvoker.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.gbean.jmx;
import java.util.Map;
import javax.management.ReflectionException;
import javax.management.JMException;
import javax.management.JMRuntimeException;
/**
* @version $Revision: 1.1 $ $Date: 2004/05/26 03:22:21 $
*/
public final class RawInvoker {
private GBeanMBean gbean;
private Map attributeIndex;
private Map operationIndex;
public RawInvoker(GBeanMBean gbean) {
this.gbean = gbean;
attributeIndex = gbean.getAttributeIndex();
operationIndex = gbean.getOperationIndex();
}
void close() {
synchronized (this) {
gbean = null;
}
}
public Map getAttributeIndex() {
return attributeIndex;
}
public Map getOperationIndex() {
return operationIndex;
}
public Object getAttribute(int index) throws Exception {
GBeanMBean gbean;
synchronized (this) {
gbean = this.gbean;
}
try {
return gbean.getAttribute(index);
} catch (ReflectionException e) {
Throwable cause = e;
while ((cause instanceof JMException || cause instanceof JMRuntimeException) && cause.getCause() != null) {
cause = cause.getCause();
}
if (cause instanceof Error) {
throw (Error) cause;
} else if (cause instanceof Exception) {
throw (Exception) cause;
} else {
throw new AssertionError(cause);
}
}
}
public void setAttribute(int index, Object value) throws Exception {
GBeanMBean gbean;
synchronized (this) {
gbean = this.gbean;
}
try {
gbean.setAttribute(index, value);
} catch (ReflectionException e) {
Throwable cause = e;
while ((cause instanceof JMException || cause instanceof JMRuntimeException) && cause.getCause() != null) {
cause = cause.getCause();
}
if (cause instanceof Error) {
throw (Error) cause;
} else if (cause instanceof Exception) {
throw (Exception) cause;
} else {
throw new AssertionError(cause);
}
}
}
public Object invoke(int index, Object[] args) throws Exception {
GBeanMBean gbean;
synchronized (this) {
gbean = this.gbean;
}
try {
return gbean.invoke(index, args);
} catch (ReflectionException e) {
Throwable cause = e;
while ((cause instanceof JMException || cause instanceof JMRuntimeException) && cause.getCause() != null) {
cause = cause.getCause();
}
if (cause instanceof Error) {
throw (Error) cause;
} else if (cause instanceof Exception) {
throw (Exception) cause;
} else {
throw new AssertionError(cause);
}
}
}
}
1.25 +2 -2 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
Index: Kernel.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Kernel.java 23 Apr 2004 03:02:00 -0000 1.24
+++ Kernel.java 26 May 2004 03:22:21 -0000 1.25
@@ -73,7 +73,7 @@
/**
* The JMX name of the DependencyService.
*/
- public static final ObjectName DEPENDENCY_SERVICE = JMXUtil.getObjectName("geronimo.boot:role=DependencyService2");
+ public static final ObjectName DEPENDENCY_SERVICE = JMXUtil.getObjectName("geronimo.boot:role=DependencyService");
private static final Map kernels = new Hashtable();
1.6 +1 -2 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXUtil.java
Index: JMXUtil.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXUtil.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JMXUtil.java 10 Mar 2004 09:59:01 -0000 1.5
+++ JMXUtil.java 26 May 2004 03:22:21 -0000 1.6
@@ -33,7 +33,6 @@
/** the ObjectName of the MBeanServerDelegate */
public static final ObjectName DELEGATE_NAME = getObjectName("JMImplementation:type=MBeanServerDelegate");
- public static final ObjectName DEPENDENCY_SERVICE_NAME = getObjectName("geronimo.boot:role=DependencyService");
/**
* Convert a String to an ObjectName
1.7 +2 -2 incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java
Index: ServerInfo.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServerInfo.java 10 Mar 2004 09:59:31 -0000 1.6
+++ ServerInfo.java 26 May 2004 03:22:21 -0000 1.7
@@ -99,7 +99,7 @@
return ServerConstants.getCopyright();
}
- private static final GBeanInfo GBEAN_INFO;
+ public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoFactory infoFactory = new GBeanInfoFactory(ServerInfo.class.getName());