User: squirest
Date: 02/01/28 19:33:21
Modified: src/main/org/jboss/mx/server StandardMBeanInvoker.java
MBeanServerImpl.java
Added: src/main/org/jboss/mx/server OLDMBeanInvoker.java
Removed: src/main/org/jboss/mx/server MBeanInvoker.java
Log:
first integration of new metadata and interceptor chain for core DynamicMBean
capabilities
Revision Changes Path
1.4 +7 -7 jmx/src/main/org/jboss/mx/server/StandardMBeanInvoker.java
Index: StandardMBeanInvoker.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/server/StandardMBeanInvoker.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StandardMBeanInvoker.java 2002/01/26 21:09:41 1.3
+++ StandardMBeanInvoker.java 2002/01/29 03:33:21 1.4
@@ -43,11 +43,11 @@
* @see org.jboss.mx.interceptor.StandardMBeanInterceptor
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.3 $
- *
+ * @version $Revision: 1.4 $
+ *
*/
public class StandardMBeanInvoker
- extends MBeanInvoker
+ extends OLDMBeanInvoker
{
// Attributes ----------------------------------------------------
@@ -60,11 +60,11 @@
Interceptor security = new SecurityInterceptor();
security.insertLast(new LogInterceptor());
- security.insertLast(new StandardMBeanInterceptor(resource, info));
+ security.insertLast(new StandardMBeanInterceptor(resource, info));
stack = security;
}
-
- // Public --------------------------------------------------------
+
+ // Public --------------------------------------------------------
public static Class getMBeanInterface(Object resource)
{
Class clazz = resource.getClass();
@@ -97,7 +97,7 @@
{
return info;
}
-
+
}
1.12 +24 -38 jmx/src/main/org/jboss/mx/server/MBeanServerImpl.java
Index: MBeanServerImpl.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/server/MBeanServerImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MBeanServerImpl.java 2002/01/28 23:36:32 1.11
+++ MBeanServerImpl.java 2002/01/29 03:33:21 1.12
@@ -50,6 +50,9 @@
import org.jboss.mx.server.registry.MBeanRegistry;
import org.jboss.mx.server.registry.MBeanEntry;
import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.capability.MBeanCapability;
+import org.jboss.mx.interceptor.MBeanTarget;
+import org.jboss.mx.interceptor.MBeanInvoker;
/**
@@ -57,20 +60,20 @@
* @see javax.management.MBeanServer
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
-public class MBeanServerImpl
+public class MBeanServerImpl
implements MBeanServer, ServerConstants
{
- // Attributes ----------------------------------------------------
+ // Attributes ----------------------------------------------------
protected long registrationNotificationSequence = 1;
protected long unregistrationNotificationSequence = 1;
protected String defaultDomain = "DefaultDomain";
protected MBeanRegistry registry = null;
protected MBeanServerDelegate delegate = null;
protected LoaderRepository loaderRepository =
LoaderRepository.getDefaultLoaderRepository();
-
+
// Constructors --------------------------------------------------
public MBeanServerImpl(String defaultDomain)
{
@@ -293,20 +296,15 @@
public ObjectInstance registerMBean(Object object, ObjectName name)
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException
{
- MBeanRegistration registrationInterface = null;
+
MBeanEntry entry = null;
boolean registrationDone = true;
-
- // basic compliance check
- if (object.getClass().getModifiers() == Modifier.ABSTRACT)
- throw new NotCompliantMBeanException("MBean class must be a concrete
class.");
- if (object.getClass().getConstructors().length == 0)
- throw new NotCompliantMBeanException("MBean class must have at least one
public constructor.");
+ MBeanCapability mbcap = MBeanCapability.of(object.getClass());
+ MBeanRegistration registrationInterface = mbcap.getMBeanRegistration(object);
- if (object instanceof MBeanRegistration)
+ if (null != registrationInterface)
{
- registrationInterface = (MBeanRegistration)object;
try
{
ObjectName mbeanName = registrationInterface.preRegister(this, name);
@@ -330,28 +328,16 @@
throw new InstanceAlreadyExistsException("MBean " + name + " already
registered.");
}
- if (getMBeanType(object) == STANDARD_MBEAN)
- {
- try
- {
- entry = new MBeanEntry(name, new StandardMBeanInvoker(object));
- }
- catch (ReflectionException e)
- {
- throw new MBeanRegistrationException(e.getTargetException(),
"Registration of MBean '" + name + "' failed: " + e.getTargetException().toString());
- }
- }
+ MBeanTarget target = new MBeanTarget(mbcap.getMBean(object));
+ MBeanInvoker invoker = new MBeanInvoker(target);
- else if (object instanceof DynamicMBean)
- entry = new MBeanEntry(name, (DynamicMBean)object);
- else
- throw new NotCompliantMBeanException(object + " is not compliant MBean
(does not implement Standard or Dynamic MBean interface).");
+ entry = new MBeanEntry(name, invoker, object);
registry.add(entry);
if (object instanceof ClassLoader)
loaderRepository.addClassLoader((ClassLoader)object);
-
+
delegate.sendNotification(
new MBeanServerNotification(
MBeanServerNotification.REGISTRATION_NOTIFICATION,
@@ -373,13 +359,13 @@
public void unregisterMBean(ObjectName name) throws InstanceNotFoundException,
MBeanRegistrationException
{
// FIXME: security for unregister (mbean delegate)
- Object mbean = registry.get(name).getResourceInstance();
+ Object resource = registry.get(name).getResourceInstance();
MBeanRegistration registrationInterface = null;
boolean unregisterSuccessful = true;
- if (mbean instanceof MBeanRegistration)
+ if (resource instanceof MBeanRegistration)
{
- registrationInterface = (MBeanRegistration)mbean;
+ registrationInterface = (MBeanRegistration) resource;
try
{
registrationInterface.preDeregister();
@@ -438,35 +424,35 @@
public Object getAttribute(ObjectName name, String attribute)
throws MBeanException, AttributeNotFoundException, InstanceNotFoundException,
ReflectionException
{
- DynamicMBean mbean = registry.get(name).getInvocationInterface();
+ DynamicMBean mbean = registry.get(name).getMBean();
return mbean.getAttribute(attribute);
}
public AttributeList getAttributes(ObjectName name, String[] attributes)
throws InstanceNotFoundException, ReflectionException
{
- DynamicMBean mbean = registry.get(name).getInvocationInterface();
+ DynamicMBean mbean = registry.get(name).getMBean();
return mbean.getAttributes(attributes);
}
public void setAttribute(ObjectName name, Attribute attribute)
throws InstanceNotFoundException, AttributeNotFoundException,
InvalidAttributeValueException, MBeanException, ReflectionException
{
- DynamicMBean mbean = registry.get(name).getInvocationInterface();
+ DynamicMBean mbean = registry.get(name).getMBean();
mbean.setAttribute(attribute);
}
public AttributeList setAttributes(ObjectName name, AttributeList attributes)
throws InstanceNotFoundException, ReflectionException
{
- DynamicMBean mbean = registry.get(name).getInvocationInterface();
+ DynamicMBean mbean = registry.get(name).getMBean();
return mbean.setAttributes(attributes);
}
public Object invoke(ObjectName name, String operationName, Object[] params,
String[] signature)
throws InstanceNotFoundException, MBeanException, ReflectionException
{
- DynamicMBean mbean = registry.get(name).getInvocationInterface();
+ DynamicMBean mbean = registry.get(name).getMBean();
return mbean.invoke(operationName, params, signature);
}
@@ -535,7 +521,7 @@
public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException,
IntrospectionException, ReflectionException
{
- return registry.get(name).getInvocationInterface().getMBeanInfo();
+ return registry.get(name).getMBean().getMBeanInfo();
}
public boolean isInstanceOf(ObjectName name, String className)
1.1 jmx/src/main/org/jboss/mx/server/OLDMBeanInvoker.java
Index: OLDMBeanInvoker.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.server;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import javax.management.DynamicMBean;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.Descriptor;
import javax.management.JMException;
import javax.management.NotCompliantMBeanException;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
import javax.management.MBeanException;
import javax.management.AttributeNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.loading.DefaultLoaderRepository;
import org.jboss.mx.metadata.StandardMetaData;
import org.jboss.mx.interceptor.Interceptor;
import org.jboss.mx.interceptor.Invocation;
import org.jboss.mx.interceptor.StandardMBeanInterceptor;
import org.jboss.mx.interceptor.LogInterceptor;
import org.jboss.mx.interceptor.SecurityInterceptor;
import org.jboss.mx.interceptor.InvocationException;
/**
*
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
* @version $Revision: 1.1 $
*
*/
public abstract class OLDMBeanInvoker
implements DynamicMBean
{
// Attributes ----------------------------------------------------
protected Interceptor stack = null;
protected Object resource = null;
protected Descriptor[] descriptors = null;
protected MBeanInfo info = null;
// Public --------------------------------------------------------
public Object getResource()
{
return resource;
}
// DynamicMBean implementation -----------------------------------
public Object invoke(String operationName, Object[] args, String[] signature)
throws MBeanException, ReflectionException
{
try
{
Invocation invocation = new Invocation(
operationName,
Invocation.OPERATION,
0, args, signature, descriptors
);
return stack.invoke(invocation);
}
catch (InvocationException e)
{
if (e.getTargetException() instanceof MBeanException)
throw (MBeanException)e.getTargetException();
else if (e.getTargetException() instanceof ReflectionException)
throw (ReflectionException)e.getTargetException();
else
throw (RuntimeException)e.getTargetException();
}
catch (Throwable t)
{
// this indicates an error in the server
// FIXME: log
System.out.println("SERVER ERROR: " + t.getMessage());
t.printStackTrace();
throw new Error(t.toString());
}
}
public Object getAttribute(String attribute) throws AttributeNotFoundException,
MBeanException, ReflectionException
{
try
{
Invocation invocation = new Invocation(
attribute,
Invocation.ATTRIBUTE,
Invocation.READ,
null, null, descriptors
);
return stack.invoke(invocation);
}
catch (InvocationException e)
{
if (e.getTargetException() instanceof AttributeNotFoundException)
throw (AttributeNotFoundException)e.getTargetException();
else if (e.getTargetException() instanceof MBeanException)
throw (MBeanException)e.getTargetException();
else if (e.getTargetException() instanceof ReflectionException)
throw (ReflectionException)e.getTargetException();
else
throw (RuntimeException)e.getTargetException();
}
catch (Throwable t)
{
// this indicates an error in the server
// FIXME: log
System.out.println("SERVER ERROR: " + t.getMessage());
t.printStackTrace();
throw new Error(t.toString());
}
}
public void setAttribute(Attribute attribute) throws AttributeNotFoundException,
InvalidAttributeValueException, MBeanException, ReflectionException
{
// REVIEW: This NEEDS to be optimized
// Get the real signature of the attribute
String attributeClassName = null;
String attributeName = attribute.getName();
MBeanAttributeInfo[] attInfos = info.getAttributes();
for (int i = 0; i < attInfos.length; i++)
{
if (attInfos[i].getName().equals(attributeName))
{
attributeClassName = attInfos[i].getType();
break;
}
}
if (attributeClassName == null)
{
throw new AttributeNotFoundException(attributeName);
}
// Set the value
try
{
Invocation invocation = new Invocation(
attributeName,
Invocation.ATTRIBUTE,
Invocation.WRITE,
new Object[] { attribute.getValue() },
new String[] { attributeClassName },
descriptors
);
stack.invoke(invocation);
}
catch (InvocationException e)
{
// FIXME: InvalidAttributeValueException!
if (e.getTargetException() instanceof AttributeNotFoundException)
throw (AttributeNotFoundException)e.getTargetException();
else if (e.getTargetException() instanceof MBeanException)
throw (MBeanException)e.getTargetException();
else if (e.getTargetException() instanceof ReflectionException)
throw (ReflectionException)e.getTargetException();
else
throw (RuntimeException)e.getTargetException();
}
catch (Throwable t)
{
// this indicates an error in the server
// FIXME: log
System.out.println("SERVER ERROR: " + t.getMessage());
t.printStackTrace();
throw new Error(t.toString());
}
}
public AttributeList getAttributes(java.lang.String[] attributes)
{
if (attributes == null) // FIXME: runtimeoperationsexception?
throw new IllegalArgumentException("null array");
AttributeList list = new AttributeList();
for (int i = 0; i < attributes.length; ++i)
{
try
{
list.add(new Attribute(attributes[i], getAttribute(attributes[i])));
}
catch (JMException ignored)
{
// if the attribute could not be retrieved, skip it
}
}
return list;
}
public AttributeList setAttributes(AttributeList attributes)
{
if (attributes == null) // FIXME: runtimeoperationsexception?
throw new IllegalArgumentException("null list");
AttributeList results = new AttributeList();
Iterator it = attributes.iterator();
while (it.hasNext())
{
try
{
Attribute attr = (Attribute)it.next();
setAttribute(attr);
results.add(attr);
}
catch (JMException ignored)
{
// if unable to set the attribute, skip it
}
}
return results;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development