User: squirest
Date: 02/01/28 19:33:22
Added: src/main/org/jboss/mx/interceptor MBeanTarget.java
MBeanInvoker.java MBeanInvocation.java
MBeanInterceptor.java
Log:
first integration of new metadata and interceptor chain for core DynamicMBean
capabilities
Revision Changes Path
1.1 jmx/src/main/org/jboss/mx/interceptor/MBeanTarget.java
Index: MBeanTarget.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.interceptor;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.DynamicMBean;
import javax.management.RuntimeOperationsException;
/**
* The end of the chain for MBeanInterceptors
*/
public class MBeanTarget extends MBeanInterceptor
{
private DynamicMBean target = null;
public MBeanTarget(DynamicMBean target)
{
super("MBeanTarget"); // FIXME - better name???
this.target = target;
}
public Object invoke(MBeanInvocation invocation) throws InvocationException
{
try
{
Object[] args = invocation.getArgs();
switch (invocation.getOpcode())
{
case MBeanInvocation.OPCODE_INVOKE:
return target.invoke((String) args[0], (Object[]) args[1], (String[])
args[2]);
case MBeanInvocation.OPCODE_GETATTRIBUTE:
return target.getAttribute((String) args[0]);
case MBeanInvocation.OPCODE_GETATTRIBUTES:
return target.getAttributes((String[]) args[0]);
case MBeanInvocation.OPCODE_SETATTRIBUTE:
target.setAttribute((Attribute) args[0]);
return null;
case MBeanInvocation.OPCODE_SETATTRIBUTES:
return target.setAttributes((AttributeList) args[0]);
case MBeanInvocation.OPCODE_GETMBEANINFO:
return target.getMBeanInfo();
default:
String message = "Invalid Opcode: " + invocation.getOpcode();
throw new InvocationException(new RuntimeOperationsException(new
IllegalArgumentException(message)), message);
}
}
catch (InvocationException e)
{
// just rethrow it
throw e;
}
catch (ClassCastException e)
{
// FIXME - spec doesn't explicitly mention CCE as wrappable by RuntimeOpEx
- is this ok tho?
String message = "Exception while unpacking arguments for Opcode: " +
MBeanInvocation.REVERSE_OPCODES[invocation.getOpcode()];
throw new InvocationException(new RuntimeOperationsException(e, message),
message);
}
catch (ArrayIndexOutOfBoundsException e)
{
String message = "Exception while unpacking arguments for Opcode: " +
MBeanInvocation.REVERSE_OPCODES[invocation.getOpcode()];
throw new InvocationException(new RuntimeOperationsException(e, message),
message);
}
catch (Exception e)
{
throw new InvocationException(e, "Exception caught in
MBeanTarget.invoke()");
}
catch (Error e)
{
throw new InvocationException(e, "Error caught in MBeanTarget.invoke()");
}
}
public void insert(MBeanInterceptor interceptor)
{
throw new UnsupportedOperationException("MBeanTarget must be the last
interceptor in the chain");
}
public void insertLast(MBeanInterceptor interceptor)
{
throw new UnsupportedOperationException("MBeanTarget must be the last
interceptor in the chain");
}
}
1.1 jmx/src/main/org/jboss/mx/interceptor/MBeanInvoker.java
Index: MBeanInvoker.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.interceptor;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.InvalidAttributeValueException;
import javax.management.JMRuntimeException;
import javax.management.MBeanException;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
import javax.management.RuntimeOperationsException;
import javax.management.MBeanInfo;
/**
* Head of the invocation chain for an MBean
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*
* @version $Revision: 1.1 $
*
*/
public class MBeanInvoker implements DynamicMBean
{
// Attributes ----------------------------------------------------
protected MBeanInterceptor stack = null;
public MBeanInvoker(MBeanInterceptor stack)
{
if (null == stack)
{
// FIXME - is the *really* what I should be throwing?
throw new RuntimeOperationsException(new IllegalArgumentException("error
initialising invoker: null stack"));
}
this.stack = stack;
}
// DynamicMBean implementation -----------------------------------
public Object invoke(String operationName, Object[] args, String[] signature)
throws MBeanException, ReflectionException
{
if (null == operationName)
{
throw new RuntimeOperationsException(new
IllegalArgumentException("operation name cannot be null"));
}
try
{
MBeanInvocation invocation = new
MBeanInvocation(MBeanInvocation.OPCODE_INVOKE,
new
Object[]{operationName, args, signature});
return stack.invoke(invocation);
}
catch (InvocationException e)
{
Throwable t = e.getTargetException();
if (t instanceof MBeanException)
throw (MBeanException) t;
else if (t instanceof ReflectionException)
throw (ReflectionException) t;
else if (t instanceof JMRuntimeException)
throw (JMRuntimeException) t;
else // FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
catch (Throwable t)
{
// FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
}
public Object getAttribute(String attribute)
throws AttributeNotFoundException, MBeanException, ReflectionException
{
if (null == attribute)
{
throw new RuntimeOperationsException(new
IllegalArgumentException("attribute cannot be null"));
}
try
{
MBeanInvocation invocation = new
MBeanInvocation(MBeanInvocation.OPCODE_GETATTRIBUTE, new Object[]{attribute});
return stack.invoke(invocation);
}
catch (InvocationException e)
{
Throwable t = e.getTargetException();
if (t instanceof MBeanException)
throw (MBeanException) t;
else if (t instanceof AttributeNotFoundException)
throw (AttributeNotFoundException) t;
else if (t instanceof ReflectionException)
throw (ReflectionException) t;
else if (t instanceof JMRuntimeException)
throw (JMRuntimeException) t;
else // FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
catch (Throwable t)
{
// FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
}
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException
{
if (null == attribute)
{
throw new RuntimeOperationsException(new
IllegalArgumentException("attribute cannot be null"));
}
try
{
MBeanInvocation invocation = new
MBeanInvocation(MBeanInvocation.OPCODE_SETATTRIBUTE,
new Object[]{attribute});
stack.invoke(invocation);
}
catch (InvocationException e)
{
Throwable t = e.getTargetException();
if (t instanceof MBeanException)
throw (MBeanException) t;
else if (t instanceof AttributeNotFoundException)
throw (AttributeNotFoundException) t;
else if (t instanceof InvalidAttributeValueException)
throw (InvalidAttributeValueException) t;
else if (t instanceof ReflectionException)
throw (ReflectionException) t;
else if (t instanceof JMRuntimeException)
throw (JMRuntimeException) t;
else // FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
catch (Throwable t)
{
// FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
}
public AttributeList getAttributes(String[] attributes)
{
if (null == attributes)
{
throw new RuntimeOperationsException(new
IllegalArgumentException("attributes array cannot be null"));
}
try
{
MBeanInvocation invocation = new
MBeanInvocation(MBeanInvocation.OPCODE_GETATTRIBUTES,
new Object[]{attributes});
return (AttributeList) stack.invoke(invocation);
}
catch (InvocationException e)
{
Throwable t = e.getTargetException();
if (t instanceof JMRuntimeException)
throw (JMRuntimeException) t;
else // FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
catch (Throwable t)
{
// FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
}
public AttributeList setAttributes(AttributeList attributes)
{
if (null == attributes)
{
throw new RuntimeOperationsException(new
IllegalArgumentException("attribute list cannot be null"));
}
try
{
MBeanInvocation invocation = new
MBeanInvocation(MBeanInvocation.OPCODE_SETATTRIBUTES,
new Object[]{attributes});
return (AttributeList) stack.invoke(invocation);
}
catch (InvocationException e)
{
Throwable t = e.getTargetException();
if (t instanceof JMRuntimeException)
throw (JMRuntimeException) t;
else // FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
catch (Throwable t)
{
// FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
}
public MBeanInfo getMBeanInfo()
{
try
{
MBeanInvocation invocation = new
MBeanInvocation(MBeanInvocation.OPCODE_GETMBEANINFO,
new Object[0]);
return (MBeanInfo) stack.invoke(invocation);
}
catch (InvocationException e)
{
Throwable t = e.getTargetException();
if (t instanceof JMRuntimeException)
throw (JMRuntimeException) t;
else // FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
catch (Throwable t)
{
// FIXME - LOG THIS, PERHAPS WE NEED AN INTERNALERROR CLASS?
throw new RuntimeErrorException(new Error("Unhandled Throwable in
MBeanInvoker: " + t.getMessage()));
}
}
}
1.1 jmx/src/main/org/jboss/mx/interceptor/MBeanInvocation.java
Index: MBeanInvocation.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.interceptor;
/**
* Abstraction of the invocation that travels through the interceptor
* stack.
*
* QUERY THS - I can see this needing a Context object but also,
* should this be mutable with a placeholder for the return value?
* IMHO that seems more like an invocation as used by interceptors...
*
* @see org.jboss.mx.interceptor.Interceptor
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
* @version $Revision: 1.1 $
*
*/
public class MBeanInvocation
{
// Constants -----------------------------------------------------
public final static int OPCODE_INVOKE = 1;
public final static int OPCODE_GETATTRIBUTE = 2;
public final static int OPCODE_GETATTRIBUTES = 3;
public final static int OPCODE_SETATTRIBUTE = 4;
public final static int OPCODE_SETATTRIBUTES = 5;
public final static int OPCODE_GETMBEANINFO = 6;
public final static String[] REVERSE_OPCODES = {
"OPCODE_UNKNOWN",
"OPCODE_INVOKE",
"OPCODE_GETATTRIBUTE",
"OPCODE_GETATTRIBUTES",
"OPCODE_SETATTRIBUTE",
"OPCODE_SETATTRIBUTES",
"OPCODE_GETMBEANINFO"
};
// Attributes ----------------------------------------------------
private int opcode;
private Object[] args;
// Constructors --------------------------------------------------
public MBeanInvocation(int opcode, Object[] args)
{
this.opcode = opcode;
this.args = args;
}
// Public --------------------------------------------------------
public Object[] getArgs()
{
return args;
}
public int getOpcode()
{
return opcode;
}
}
1.1 jmx/src/main/org/jboss/mx/interceptor/MBeanInterceptor.java
Index: MBeanInterceptor.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.interceptor;
/**
* Base class for MBean interceptors
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
* @version $Revision: 1.1 $
*
*/
public class MBeanInterceptor
{
// Attributes ----------------------------------------------------
protected MBeanInterceptor next = null;
protected String name = null;
// Constructors --------------------------------------------------
public MBeanInterceptor(String name)
{
this.name = name;
}
// Public --------------------------------------------------------
public Object invoke(MBeanInvocation invocation) throws InvocationException
{
return getNext().invoke(invocation);
}
public MBeanInterceptor getNext()
{
return next;
}
public void insert(MBeanInterceptor interceptor)
{
MBeanInterceptor ic = interceptor;
while (ic.getNext() != null)
ic = ic.getNext();
ic.next = next;
next = interceptor;
}
public void insertLast(MBeanInterceptor interceptor)
{
if (next == null)
{
next = interceptor;
return;
}
MBeanInterceptor ic = next;
while (ic.getNext() != null)
ic = ic.getNext();
ic.next = interceptor;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development