http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/jmx/MBeanConstructorInfo.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/jmx/MBeanConstructorInfo.java b/core/src/main/java/flex/management/jmx/MBeanConstructorInfo.java new file mode 100644 index 0000000..95a2474 --- /dev/null +++ b/core/src/main/java/flex/management/jmx/MBeanConstructorInfo.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.jmx; + +/** + * Remotable <code>MBeanConstructorInfo</code> class that complies with Flash serialization requirements. + */ +public class MBeanConstructorInfo +{ + /** + * The name of the constructor. + */ + public String name; + + /** + * The description of the constructor. + */ + public String description; + + /** + * The constructor's parameter signature. + */ + public MBeanParameterInfo[] signature; + + /** + * Constructs an empty <code>MBeanConstructorInfo</code> instance. + * + */ + public MBeanConstructorInfo() + {} + + /** + * Constructs a <code>MBeanConstructorInfo</code> instance based upon a + * <code>javax.management.MBeanConstructorInfo</code> instance. + * + * @param mbeanConstructorInfo The <code>javax.management.MBeanConstructorInfo</code> to base this instance on. + */ + public MBeanConstructorInfo(javax.management.MBeanConstructorInfo mbeanConstructorInfo) + { + name = mbeanConstructorInfo.getName(); + description = mbeanConstructorInfo.getDescription(); + signature = convertSignature(mbeanConstructorInfo.getSignature()); + } + + /** + * Utility method to convert this <code>MBeanConstructorInfo</code> instance to a + * <code>javax.management.MBeanConstructorInfo</code> instance. + * + * @return A JMX <code>MBeanConstructorInfo</code> based upon this instance. + */ + public javax.management.MBeanConstructorInfo toMBeanConstructorInfo() + { + return new javax.management.MBeanConstructorInfo(name, + description, + convertSignature(signature)); + } + + /** + * Utility method to convert the JMX constructor signature to our Flash friendly param type. + * + * @param source The JMX constructor signature params. + * @return Flash friendly signature params. + */ + private MBeanParameterInfo[] convertSignature(javax.management.MBeanParameterInfo[] source) + { + MBeanParameterInfo[] signature = new MBeanParameterInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + signature[i] = new MBeanParameterInfo(source[i]); + } + return signature; + } + + /** + * Utility method to convert a Flash friendly construtor param signature to the JMX params. + * + * @param source The Flash friendly signature params. + * @return The JMX constructor signature params. + */ + private javax.management.MBeanParameterInfo[] convertSignature(MBeanParameterInfo[] source) + { + javax.management.MBeanParameterInfo[] signature = new javax.management.MBeanParameterInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + signature[i] = source[i].toMBeanParameterInfo(); + } + return signature; + } + +}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/jmx/MBeanInfo.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/jmx/MBeanInfo.java b/core/src/main/java/flex/management/jmx/MBeanInfo.java new file mode 100644 index 0000000..d44e507 --- /dev/null +++ b/core/src/main/java/flex/management/jmx/MBeanInfo.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.jmx; + +/** + * Remotable MBeanInfo class that complies with Flash serialization requirements. + * MBean Notifications are not currently supported. + */ +public class MBeanInfo +{ + /** + * The Java class name for the MBean object. + */ + public String className; + + /** + * The description of the MBean. + */ + public String description; + + /** + * The attributes exposed for management. + */ + public MBeanAttributeInfo[] attributes; + + /** + * The public constructors for the MBean. + */ + public MBeanConstructorInfo[] constructors; + + /** + * The operations exposed by the MBean. + */ + public MBeanOperationInfo[] operations; + + /** + * Constructs an empty <code>MBeanInfo</code> instance. + */ + public MBeanInfo() + {} + + /** + * Constructs a <code>MBeanInfo</code> instance based upon a + * <code>javax.management.MBeanInfo</code> instance. + * + * @param mbeanInfo The JMX <code>MBeanInfo</code> instance to base this instance on. + */ + public MBeanInfo(javax.management.MBeanInfo mbeanInfo) + { + className = mbeanInfo.getClassName(); + description = mbeanInfo.getDescription(); + attributes = convertAttributes(mbeanInfo.getAttributes()); + constructors = convertConstructors(mbeanInfo.getConstructors()); + operations = convertOperations(mbeanInfo.getOperations()); + } + + /** + * Utility method to convert this <code>MBeanInfo</code> to a + * <code>javax.management.MBeanInfo</code> instance. + * + * @return A JMX <code>MBeanInfo</code> based upon this instance. + */ + public javax.management.MBeanInfo toMBeanInfo() + { + return new javax.management.MBeanInfo(className, + description, + convertAttributes(attributes), + convertConstructors(constructors), + convertOperations(operations), + null); + } + + /** + * Utility method to convert JMX attribute info instances to Flash friendly instances. + * + * @param source JMX attribute info instances. + * @return Flash friendly attribute info instances. + */ + private MBeanAttributeInfo[] convertAttributes(javax.management.MBeanAttributeInfo[] source) + { + MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + attributes[i] = new MBeanAttributeInfo(source[i]); + } + return attributes; + } + + /** + * Utility method to convert Flash friendly attribute info instances to JMX attribute info instances. + * + * @param source Flash friendly attribute info instances. + * @return JMX attribute info instances. + */ + private javax.management.MBeanAttributeInfo[] convertAttributes(MBeanAttributeInfo[] source) + { + javax.management.MBeanAttributeInfo[] attributes = new javax.management.MBeanAttributeInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + attributes[i] = source[i].toMBeanAttributeInfo(); + } + return attributes; + } + + /** + * Utility method to convert JMX constructor info instances to Flash friendly constructor info + * instances. + * + * @param source JMX constructor info instances. + * @return Flash friendly constructor info instances. + */ + private MBeanConstructorInfo[] convertConstructors(javax.management.MBeanConstructorInfo[] source) + { + MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + constructors[i] = new MBeanConstructorInfo(source[i]); + } + return constructors; + } + + /** + * Utility method to convert Flash friendly constructor info instances to JMX constructor info instances. + * + * @param source Flash friendly constructor info instances. + * @return JMX constructor info instances. + */ + private javax.management.MBeanConstructorInfo[] convertConstructors(MBeanConstructorInfo[] source) + { + javax.management.MBeanConstructorInfo[] constructors = new javax.management.MBeanConstructorInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + constructors[i] = source[i].toMBeanConstructorInfo(); + } + return constructors; + } + + /** + * Utility method to convert JMX operation info instances to Flash friendly operation info instances. + * + * @param source JMX opereration info instances. + * @return Flash friendly operation info instances. + */ + private MBeanOperationInfo[] convertOperations(javax.management.MBeanOperationInfo[] source) + { + MBeanOperationInfo[] operations = new MBeanOperationInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + operations[i] = new MBeanOperationInfo(source[i]); + } + return operations; + } + + /** + * Utility method to convert Flash friendly operation info instances to JMX operation info instances. + * + * @param source Flash friendly operation info instances. + * @return JMX operation info instances. + */ + private javax.management.MBeanOperationInfo[] convertOperations(MBeanOperationInfo[] source) + { + javax.management.MBeanOperationInfo[] operations = new javax.management.MBeanOperationInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + operations[i] = source[i].toMBeanOperationInfo(); + } + return operations; + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/jmx/MBeanOperationInfo.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/jmx/MBeanOperationInfo.java b/core/src/main/java/flex/management/jmx/MBeanOperationInfo.java new file mode 100644 index 0000000..c6c6c45 --- /dev/null +++ b/core/src/main/java/flex/management/jmx/MBeanOperationInfo.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.jmx; + +/** + * Remotable MBeanOperationInfo class that complies with Flash serialization requirements. + */ +public class MBeanOperationInfo +{ + /** + * The operation name. + */ + public String name; + + /** + * The operation description. + */ + public String description; + + /** + * The operation's argument signature. + */ + public MBeanParameterInfo[] signature; + + /** + * The operation's return type. + */ + public String returnType; + + /** + * The impact of the operation; one of <code>INFO, ACTION, ACTION_INFO, UNKNOWN</code>. + */ + public int impact; + + /** + * Constructs an empty <code>MBeanOperationInfo</code> instance. + */ + public MBeanOperationInfo() + {} + + /** + * Constructs a <code>MBeanOperationInfo</code> instance based upon a + * <code>javax.management.MBeanOperationInfo</code> instance. + * + * @param mbeanOperationInfo The JMX <code>MBeanOperationInfo</code> instance to base this instance on. + */ + public MBeanOperationInfo(javax.management.MBeanOperationInfo mbeanOperationInfo) + { + name = mbeanOperationInfo.getName(); + description = mbeanOperationInfo.getDescription(); + signature = convertSignature(mbeanOperationInfo.getSignature()); + returnType = mbeanOperationInfo.getReturnType(); + impact = mbeanOperationInfo.getImpact(); + } + + /** + * Utility method to convert this <code>MBeanOperationInfo</code> to a + * <code>javax.management.MBeanOperationInfo</code> instance. + * + * @return A JMX <code>MBeanOperationInfo</code> based upon this instance. + */ + public javax.management.MBeanOperationInfo toMBeanOperationInfo() + { + return new javax.management.MBeanOperationInfo(name, + description, + convertSignature(signature), + returnType, + impact); + } + + /** + * Utility method to convert JMX parameter info instances to Flash friendly parameter info instances. + * + * @param source JMX parameter info instances. + * @return Flash friendly parameter info instances. + */ + private MBeanParameterInfo[] convertSignature(javax.management.MBeanParameterInfo[] source) + { + MBeanParameterInfo[] signature = new MBeanParameterInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + signature[i] = new MBeanParameterInfo(source[i]); + } + return signature; + } + + /** + * Utility method to convert Flash friendly parameter info instances to JMX parameter info instances. + * + * @param source Flash friendly parameter info instances. + * @return JMX parameter info instances. + */ + private javax.management.MBeanParameterInfo[] convertSignature(MBeanParameterInfo[] source) + { + javax.management.MBeanParameterInfo[] signature = new javax.management.MBeanParameterInfo[source.length]; + for (int i = 0; i < source.length; i++) + { + signature[i] = source[i].toMBeanParameterInfo(); + } + return signature; + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/jmx/MBeanParameterInfo.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/jmx/MBeanParameterInfo.java b/core/src/main/java/flex/management/jmx/MBeanParameterInfo.java new file mode 100644 index 0000000..e0fd4fe --- /dev/null +++ b/core/src/main/java/flex/management/jmx/MBeanParameterInfo.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.jmx; + +/** + * Remotable MBeanParameterInfo class that complies with Flash serialization requirements. + + */ +public class MBeanParameterInfo +{ + /** + * The name of the parameter. + */ + public String name; + + /** + * The Java type for the parameter. + */ + public String type; + + /** + * The description for the parameter. + */ + public String description; + + /** + * Constructs an empty <code>MBeanParameterInfo</code> instance. + */ + public MBeanParameterInfo() + {} + + /** + * Constructs a <code>MBeanParameterInfo</code> instance based upon a + * <code>javax.management.MBeanParameterInfo</code> instance. + * + * @param mbeanParameterInfo The JMX <code>MBeanParameterInfo</code> instance to base this instance on. + */ + public MBeanParameterInfo(javax.management.MBeanParameterInfo mbeanParameterInfo) + { + name = mbeanParameterInfo.getName(); + type = mbeanParameterInfo.getType(); + description = mbeanParameterInfo.getDescription(); + } + + /** + * Utility method to convert this <code>MBeanParameterInfo</code> to a + * <code>javax.management.MBeanParameterInfo</code> instance. + * + * @return A JMX <code>MBeanParameterInfo</code> based upon this instance. + */ + public javax.management.MBeanParameterInfo toMBeanParameterInfo() + { + return new javax.management.MBeanParameterInfo(name, + type, + description); + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/jmx/MBeanServerGateway.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/jmx/MBeanServerGateway.java b/core/src/main/java/flex/management/jmx/MBeanServerGateway.java new file mode 100644 index 0000000..f60c401 --- /dev/null +++ b/core/src/main/java/flex/management/jmx/MBeanServerGateway.java @@ -0,0 +1,906 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.jmx; + +import flex.management.BaseControl; +import flex.management.MBeanServerLocatorFactory; +import flex.management.ManagementException; + +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +import javax.management.AttributeList; +import javax.management.AttributeNotFoundException; +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.IntrospectionException; +import javax.management.InvalidAttributeValueException; +import javax.management.MalformedObjectNameException; +import javax.management.MBeanException; +import javax.management.MBeanRegistrationException; +import javax.management.MBeanServer; +import javax.management.NotCompliantMBeanException; +import javax.management.ReflectionException; +import javax.management.RuntimeOperationsException; + +/** + * Remoting gateway to the MBean server that hosts Flex MBeans. + * + * Some base javax.management.MBeanServer methods are unimplemented due to the + * fact that we're interacting with the MBean server from remote Flash clients. + * Some methods have been modified to better suite remote Flash clients. Other + * methods are additive, serving as a convenience for Flex applications. + * + * Unimplemented methods from the base MBeanServer API: + * <ul> + * <li>getDomains() - JMX 1.2</li> + * <li>addNotificationListener()/removeNotificationListener() - Flash objects + * cannot listen directly for MBean notifications.</li> + * <li>instantiate() - returns a reference to a Java object that is not useful + * to a remote Flash client.</li> + * <li>deserialize() - deprecated.</li> + * <li>getClassLoaderFor() - meaningless to a Flash client.</li> + * <li>getClassLoader() - meaningless to a Flash client.</li> + * <li>getClassLoaderRepository() - meaningless to a Flash client.</li> + * </ul> + * + * Modifications to the base MBeanServer API: + * <ul> + * <li>* All ObjectName arguments are typed as String because serialization in either + * direction doesn't support ObjectNames that are patterns. This does not effect + * ObjectNames that are not patterns that are returned to the client.</li> + * <li>queryMBeans() - returns an Array of ObjectInstances rather than a java.util.Set + * and does not currently support the QueryExp argument.</li> + * <li>queryNames() returns an Array of ObjectNames rather than a java.util.Set + * and does not currently support the QueryExp argument.</li> + * <li>getAttributes() returns an Array of Attributes rather than an AttributeList.</li> + * <li>setAttributes() accepts and returns Arrays of Attributes rather than AttributeLists.</li> + * </ul> + * + * Additonal Flex-specific methods: + * <ul> + * <li>getFlexMBeanCount()</li> + * <li>getFlexDomains()</li> + * <li>getFlexMBeanObjectNames()</li> + * </ul> + */ +public class MBeanServerGateway +{ + // Error string constants. + private static final int MALFORMED_OBJECTNAME = 10400; + private static final int GETINFO_INTROSPECTION_ERR = 10406; + private static final int MBEAN_NOTFOUND = 10407; + private static final int GETINFO_REFLECT_ERR = 10408; + private static final int ATTRIB_NOTFOUND = 10409; + private static final int GETATTRIB_EXCEPTION = 10410; + private static final int GETATTRIB_REFLECT_ERR = 10411; + private static final int GETATTRIB_NULL_ARGUMENT = 10412; + private static final int GETATTRIBS_REFLECT_ERR = 10413; + private static final int GETATTRIBS_NULL_ARGUMENT = 10414; + private static final int INVOKE_REFLECT_ERR = 10415; + private static final int INVOKE_ERR = 10416; + private static final int CREATE_ERR = 10417; + private static final int INSTANCE_EXISTS = 10418; + private static final int NOT_COMPLIANT = 10419; + private static final int MBEAN_PREREG_ERR = 10420; + private static final int MBEAN_PREDEREG_ERR = 10421; + private static final int SETATTRIB_REFLECT_ERR = 10422; + private static final int SETATTRIB_EXCEPTION = 10423; + private static final int INVALID_ATTRIB_VALUE = 10424; + private static final int SETATTRIBS_REFLECT_ERR = 10425; + + private MBeanServer server; + + /** + * Constructs a new MBeanServerGateway. The gateway exposes the MBean server + * that Flex MBean are registered with in a remoting-friendly fashion. + */ + public MBeanServerGateway() + { + server = MBeanServerLocatorFactory.getMBeanServerLocator().getMBeanServer(); + } + + ///////////////////////////////////// + // + // Core MBeanServer API + // + ///////////////////////////////////// + + /** + * Instantiates and registers an MBean with the MBean server. + * + * @param className The class name for the MBean to instantiate. + * @param objectName The object name of the MBean. + * @return An ObjectInstance containing the ObjectName and Java class name of the new MBean. + */ + public ObjectInstance createMBean(String className, String objectName) + { + javax.management.ObjectName name = null; + if (objectName != null) + name = validateObjectName(objectName); + try + { + return new ObjectInstance(server.createMBean(className, name)); + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(CREATE_ERR, new Object[] {name}); + me.setRootCause(re); + throw me; + } + catch (InstanceAlreadyExistsException iaee) + { + ManagementException me = new ManagementException(); + me.setMessage(INSTANCE_EXISTS, new Object[] {name}); + me.setRootCause(iaee); + throw me; + } + catch (MBeanException mbe) + { + ManagementException me = new ManagementException(); + me.setMessage(CREATE_ERR, new Object[] {name}); + me.setRootCause(mbe); + throw me; + } + catch (NotCompliantMBeanException ncmbe) + { + ManagementException me = new ManagementException(); + me.setMessage(NOT_COMPLIANT, new Object[] {className}); + me.setRootCause(ncmbe); + throw me; + } + } + + /** + * Instantiates and registers an MBean with the MBean server. The class loader + * to use to load the MBean class is identified by its ObjectName. + * + * @param className The class name for the MBean to instantiate. + * @param objectName The object name of the MBean. + * @param loaderName The object name of the desired class loader. + * @return An ObjectInstance containing the ObjectName and Java class name of the new MBean. + */ + public ObjectInstance createMBean(String className, String objectName, String loaderName) + { + javax.management.ObjectName name = null; + javax.management.ObjectName loader = null; + if (objectName != null) + name = validateObjectName(objectName); + if (loaderName != null) + loader = validateObjectName(loaderName); + try + { + return new ObjectInstance(server.createMBean(className, name, loader)); + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(CREATE_ERR, new Object[] {name}); + me.setRootCause(re); + throw me; + } + catch (InstanceAlreadyExistsException iaee) + { + ManagementException me = new ManagementException(); + me.setMessage(INSTANCE_EXISTS, new Object[] {name}); + me.setRootCause(iaee); + throw me; + } + catch (MBeanException mbe) + { + ManagementException me = new ManagementException(); + me.setMessage(CREATE_ERR, new Object[] {name}); + me.setRootCause(mbe); + throw me; + } + catch (NotCompliantMBeanException ncmbe) + { + ManagementException me = new ManagementException(); + me.setMessage(NOT_COMPLIANT, new Object[] {className}); + me.setRootCause(ncmbe); + throw me; + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {name}); + me.setRootCause(infe); + throw me; + } + } + + /** + * Instantiates and registers an MBean with the MBean server. + * + * @param className The class name for the MBean to instantiate. + * @param objectName The object name of the MBean. + * @param params An array of parameters to pass to the MBean constructor. + * @param signature An array containing the type signature for the constructor to invoke. + * @return An ObjectInstance containing the ObjectName and Java class name of the new MBean. + */ + public ObjectInstance createMBean(String className, String objectName, Object[] params, String[] signature) + { + javax.management.ObjectName name = null; + if (objectName != null) + name = validateObjectName(objectName); + try + { + return new ObjectInstance(server.createMBean(className, name, params, signature)); + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(CREATE_ERR, new Object[] {name}); + me.setRootCause(re); + throw me; + } + catch (InstanceAlreadyExistsException iaee) + { + ManagementException me = new ManagementException(); + me.setMessage(INSTANCE_EXISTS, new Object[] {name}); + me.setRootCause(iaee); + throw me; + } + catch (MBeanException mbe) + { + ManagementException me = new ManagementException(); + me.setMessage(CREATE_ERR, new Object[] {name}); + me.setRootCause(mbe); + throw me; + } + catch (NotCompliantMBeanException ncmbe) + { + ManagementException me = new ManagementException(); + me.setMessage(NOT_COMPLIANT, new Object[] {className}); + me.setRootCause(ncmbe); + throw me; + } + } + + /** + * Instantiates and registers an MBean with the MBean server. The class loader + * to use to load the MBean class is identified by its ObjectName. + * + * @param className The class name for the MBean to instantiate. + * @param objectName The object name of the MBean. + * @param loaderName The object name of the desired class loader. + * @param params An array of parameters to pass to the MBean constructor. + * @param signature An array containing the type signature for the constructor to invoke. + * @return An ObjectInstance containing the ObjectName and Java class name of the new MBean. + */ + public ObjectInstance createMBean(String className, String objectName, String loaderName, Object[] params, String[] signature) + { + javax.management.ObjectName name = null; + javax.management.ObjectName loader = null; + if (objectName != null) + name = validateObjectName(objectName); + if (loaderName != null) + loader = validateObjectName(loaderName); + try + { + return new ObjectInstance(server.createMBean(className, name, loader, params, signature)); + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(CREATE_ERR, new Object[] {name}); + me.setRootCause(re); + throw me; + } + catch (InstanceAlreadyExistsException iaee) + { + ManagementException me = new ManagementException(); + me.setMessage(INSTANCE_EXISTS, new Object[] {name}); + me.setRootCause(iaee); + throw me; + } + catch (MBeanException mbe) + { + ManagementException me = new ManagementException(); + me.setMessage(CREATE_ERR, new Object[] {name}); + me.setRootCause(mbe); + throw me; + } + catch (NotCompliantMBeanException ncmbe) + { + ManagementException me = new ManagementException(); + me.setMessage(NOT_COMPLIANT, new Object[] {className}); + me.setRootCause(ncmbe); + throw me; + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {name}); + me.setRootCause(infe); + throw me; + } + } + + /** + * Registers a pre-existing object as an MBean with the MBean server. + * + * @param object The object to register as an MBean. + * @param objectName The object name for the MBean. + * @return An ObjectInstance containing the ObjectName and Java class name of the new MBean. + */ + public ObjectInstance registerMBean(Object object, String objectName) + { + javax.management.ObjectName name = null; + if (objectName != null) + name = validateObjectName(objectName); + try + { + return new ObjectInstance(server.registerMBean(object, name)); + } + catch (InstanceAlreadyExistsException iaee) + { + ManagementException me = new ManagementException(); + me.setMessage(INSTANCE_EXISTS, new Object[] {name}); + me.setRootCause(iaee); + throw me; + } + catch (NotCompliantMBeanException ncmbe) + { + ManagementException me = new ManagementException(); + me.setMessage(NOT_COMPLIANT, new Object[] {object.getClass().getName()}); + me.setRootCause(ncmbe); + throw me; + } + catch (MBeanRegistrationException mbre) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_PREREG_ERR, new Object[] {name}); + me.setRootCause(mbre); + throw me; + } + } + + /** + * Unregisters an MBean from the MBean server. + * + * @param objectName The object name of the MBean to unregister. + */ + public void unregisterMBean(String objectName) + { + javax.management.ObjectName name = validateObjectName(objectName); + try + { + server.unregisterMBean(name); + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {name}); + me.setRootCause(infe); + throw me; + } + catch (MBeanRegistrationException mbre) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_PREDEREG_ERR, new Object[] {name}); + me.setRootCause(mbre); + throw me; + } + } + + /** + * Gets the ObjectInstance for the specified MBean registered with the + * MBean server. + * + * @param objectName The object name of the MBean. + * @return An ObjectInstance containing the ObjectName and Java class name of the MBean. + */ + public ObjectInstance getObjectInstance(String objectName) + { + javax.management.ObjectName name = validateObjectName(objectName); + try + { + return new ObjectInstance(server.getObjectInstance(name)); + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {name}); + me.setRootCause(infe); + throw me; + } + } + + /** + * Gets MBeans controlled by the MBean server. This method allows the following to be obtained: + * All MBeans, or a set of MBeans specified by pattern matching on the ObjectName, or a specific + * MBean. + * <p> + * This method does not support a QueryExp argument for additional filtering of the queried set. + * </p> + * + * @param objectName The object name pattern identifying the MBeans to retrieve. + * @return A set of ObjectInstances for the selected MBeans. + */ + public ObjectInstance[] queryMBeans(String objectName) + { + javax.management.ObjectName name = validateObjectName(objectName); + Set result = server.queryMBeans(name, null); + int n = result.size(); + if (n > 0) + { + ObjectInstance[] toReturn = new ObjectInstance[n]; + int i = 0; + for (Iterator iter = result.iterator(); iter.hasNext();) + { + toReturn[i++] = new ObjectInstance((javax.management.ObjectInstance)iter.next()); + } + return toReturn; + } + else + { + return new ObjectInstance[0]; + } + } + + /** + * Gets the names of MBeans controlled by the MBean server. This method allows the following to be + * obtained: The names of all MBeans, the names of the set of MBeans matching the ObjectName pattern, + * a specific MBean name. + * <p> + * This method does not support a QueryExp argument for additional filtering of the queried set. + * </p> + * + * @param objectName The object name pattern identifying the MBean names to retrieve. + * @return A set of ObjectNames for the selected MBeans. + */ + public ObjectName[] queryNames(String objectName) + { + javax.management.ObjectName name = validateObjectName(objectName); + Set result = server.queryNames(name, null); + int n = result.size(); + if (n > 0) + { + ObjectName[] toReturn = new ObjectName[n]; + int i = 0; + for (Iterator iter = result.iterator(); iter.hasNext();) + { + toReturn[i++] = new ObjectName((javax.management.ObjectName)iter.next()); + } + return toReturn; + } + else + { + return new ObjectName[0]; + } + } + + /** + * Checks whether an MBean, identified by its object name, is already registered with the MBean server. + * + * @param objectName The object name of the MBean to be checked. + * @return True if the MBean is already registered in the MBean server, false otherwise. + */ + public boolean isRegistered(String objectName) + { + javax.management.ObjectName name = validateObjectName(objectName); + return server.isRegistered(name); + } + + /** + * Returns the total number of beans registered in the MBean server. + * + * @return The number of registered MBeans. + */ + public Integer getMBeanCount() + { + return server.getMBeanCount(); + } + + /** + * Gets the value of a specific attribute of a named MBean. The MBean is identified by its object name. + * + * @param objectName The object name of the MBean from which the attribute is to be retrieved. + * @param attribute The name of the attribute to be retrieved. + * @return The value of the retrieved attribute. + */ + public Object getAttribute(String objectName, String attribute) + { + javax.management.ObjectName name = validateObjectName(objectName); + try + { + return server.getAttribute(name, attribute); + } + catch (AttributeNotFoundException anfe) + { + ManagementException me = new ManagementException(); + me.setMessage(ATTRIB_NOTFOUND, new Object[] {attribute, name}); + me.setRootCause(anfe); + throw me; + } + catch (MBeanException mbe) + { + ManagementException me = new ManagementException(); + me.setMessage(GETATTRIB_EXCEPTION, new Object[] {attribute, name}); + me.setRootCause(mbe); + throw me; + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(GETATTRIB_REFLECT_ERR, new Object[] {attribute, name}); + me.setRootCause(re); + throw me; + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {name}); + me.setRootCause(infe); + throw me; + } + catch (RuntimeOperationsException roe) + { + ManagementException me = new ManagementException(); + me.setMessage(GETATTRIB_NULL_ARGUMENT); + me.setRootCause(roe); + throw me; + } + } + + /** + * Gets the values of several attributes of a named MBean. + * + * @param objectName The object name of the MBean to get attribute values from. + * @param attributes The names of the attributes to get values for. + * @return The attributes, each containing their name and value. + */ + public Attribute[] getAttributes(String objectName, String[] attributes) + { + javax.management.ObjectName name = validateObjectName(objectName); + try + { + AttributeList result = server.getAttributes(name, attributes); + Attribute[] values = new Attribute[result.size()]; + for (int i = 0; i < result.size(); i++) + { + values[i] = new Attribute((javax.management.Attribute)result.get(i)); + } + return values; + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(GETATTRIBS_REFLECT_ERR, new Object[] {name}); + me.setRootCause(re); + throw me; + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {name}); + me.setRootCause(infe); + throw me; + } + catch (RuntimeOperationsException roe) + { + ManagementException me = new ManagementException(); + me.setMessage(GETATTRIBS_NULL_ARGUMENT); + me.setRootCause(roe); + throw me; + } + } + + /** + * Sets the value of the attribute for the specified MBean. + * + * @param objectName The name of the MBean. + * @param attribute The attribute to set. + */ + public void setAttribute(String objectName, Attribute attribute) + { + javax.management.ObjectName name = validateObjectName(objectName); + javax.management.Attribute attrib = validateAttribute(attribute); + try + { + server.setAttribute(name, attrib); + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(SETATTRIB_REFLECT_ERR, new Object[] {attrib.getName(), name}); + me.setRootCause(re); + throw me; + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {name}); + me.setRootCause(infe); + throw me; + } + catch (AttributeNotFoundException anfe) + { + ManagementException me = new ManagementException(); + me.setMessage(ATTRIB_NOTFOUND, new Object[] {attrib.getName(), name}); + me.setRootCause(anfe); + throw me; + } + catch (MBeanException mbe) + { + ManagementException me = new ManagementException(); + me.setMessage(SETATTRIB_EXCEPTION, new Object[] {attrib.getName(), name}); + me.setRootCause(mbe); + throw me; + } + catch (InvalidAttributeValueException iave) + { + ManagementException me = new ManagementException(); + me.setMessage(INVALID_ATTRIB_VALUE, new Object[] {attrib.getValue(), attrib.getName(), name}); + me.setRootCause(iave); + throw me; + } + } + + /** + * Sets the values for several attributes of the specified MBean. + * + * @param objectName The object name for the MBean. + * @param attributes The attributes to set. + * @return The attributes that were set with their new values. + */ + public Attribute[] setAttributes(String objectName, Attribute[] attributes) + { + javax.management.ObjectName name = validateObjectName(objectName); + AttributeList attribList = new AttributeList(); + for (int i = 0; i < attributes.length; i++) + { + attribList.add(attributes[i].toAttribute()); + } + try + { + AttributeList result = server.setAttributes(name, attribList); + Attribute[] values = new Attribute[result.size()]; + for (int i = 0; i < result.size(); i++) + { + values[i] = new Attribute((javax.management.Attribute)result.get(i)); + } + return values; + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {name}); + me.setRootCause(infe); + throw me; + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(SETATTRIBS_REFLECT_ERR, new Object[] {name}); + me.setRootCause(re); + throw me; + } + } + + /** + * Invokes an operation on an MBean. + * + * @param objectName The object name of the MBean to invoke the operation on. + * @param operationName The operation to invoke. + * @param params The parameters for the operation invocation. + * @param signature The parameter signature for the operation. + * @return The object returned by the operation invocation. + */ + public Object invoke(String objectName, String operationName, Object[] params, String[] signature) + { + javax.management.ObjectName name = validateObjectName(objectName); + try + { + return server.invoke(name, operationName, params, signature); + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(INVOKE_REFLECT_ERR, new Object[] {operationName, objectName}); + me.setRootCause(re); + throw me; + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {objectName}); + me.setRootCause(infe); + throw me; + } + catch (MBeanException mbe) + { + ManagementException me = new ManagementException(); + me.setMessage(INVOKE_ERR, new Object[] {operationName, objectName}); + me.setRootCause(mbe); + throw me; + } + } + + /** + * Returns the default domain used for naming MBeans. + * + * @return The default domain. + */ + public String getDefaultDomain() + { + return server.getDefaultDomain(); + } + + /** + * This method discovers the attributes and operations that an MBean exposes for management + * by a Flash client. + * + * @param objectName The name of the MBean to get metadata for. + * @return An MBeanInfo instance that describes the MBean. + */ + public flex.management.jmx.MBeanInfo getMBeanInfo(String objectName) + { + javax.management.ObjectName name = validateObjectName(objectName); + try + { + return new MBeanInfo(server.getMBeanInfo(name)); + } + catch (IntrospectionException ie) + { + ManagementException me = new ManagementException(); + me.setMessage(GETINFO_INTROSPECTION_ERR, new Object[] {objectName}); + me.setRootCause(ie); + throw me; + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {objectName}); + me.setRootCause(infe); + throw me; + } + catch (ReflectionException re) + { + ManagementException me = new ManagementException(); + me.setMessage(GETINFO_REFLECT_ERR, new Object[] {objectName}); + me.setRootCause(re); + throw me; + } + } + + + /** + * Returns true if the specified MBean is an instance of the specified class; otherwise false. + * + * @param objectName The object name of the MBean. + * @param className The name of the class. + * @return true if the specified MBean is an instance of the specified class; otherwise false. + */ + public boolean isInstanceOf(String objectName, String className) + { + javax.management.ObjectName name = validateObjectName(objectName); + try + { + return server.isInstanceOf(name, className); + } + catch (InstanceNotFoundException infe) + { + ManagementException me = new ManagementException(); + me.setMessage(MBEAN_NOTFOUND, new Object[] {objectName}); + me.setRootCause(infe); + throw me; + } + } + + //////////////////////////////// + // + // Additive Flex-specific API + // + //////////////////////////////// + + /** + * Returns all the object names for Flex related MBeans. + * + * @return The object names for all Flex related MBeans. + */ + public ObjectName[] getFlexMBeanObjectNames() + { + javax.management.ObjectName pattern = validateObjectName(BaseControl.DOMAIN_PREFIX + "*:*"); + Set result = server.queryNames(pattern, null); + ObjectName[] names = new ObjectName[result.size()]; + int i = 0; + for (Iterator iter = result.iterator(); iter.hasNext(); ) + { + names[i++] = new ObjectName((javax.management.ObjectName)iter.next()); + } + return names; + } + + /** + * Returns the number of narrowed Flex MBeans registered in the MBean server. + * + * @return The number of narrowed Flex MBeans registered in the MBean server. + */ + public Integer getFlexMBeanCount() + { + return new Integer(getFlexMBeanObjectNames().length); + } + + /** + * Returns the narrowed list of Flex domains in which any MBean is currently registered. + * The domains are returned in naturally sorted order. + * + * @return The narrowed list of Flex domains in which any MBean is currently registered. + */ + public String[] getFlexDomains() + { + ObjectName[] names = getFlexMBeanObjectNames(); + Set domains = new TreeSet(); + String name; + String domain; + if (names.length > 0) + { + for (int i = 0; i < names.length; ++i) + { + name = names[i].canonicalName; + domain = name.substring(0, name.indexOf(':')); + if (!domains.contains(domain)) + { + domains.add(domain); + } + } + } + return (String[])domains.toArray(new String[domains.size()]); + } + + /////////////////////////////// + // + // Internal helper methods + // + /////////////////////////////// + + /** + * Helper method to validate that we have a well-formed ObjectName string. + * + * @param objectName The object name to validate. + * @return The valid ObjectName. + */ + private javax.management.ObjectName validateObjectName(String objectName) + { + try + { + return new javax.management.ObjectName(objectName); + } + catch (MalformedObjectNameException mone) + { + ManagementException me = new ManagementException(); + me.setMessage(MALFORMED_OBJECTNAME, new Object[] {objectName}); + throw me; + } + } + + /** + * Helper method to validate that we have a well-formed Attribute. + * + * @param attribute The attribute to validate. + * @return The valid Attribute. + */ + private javax.management.Attribute validateAttribute(Attribute attribute) + { + return attribute.toAttribute(); + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/jmx/ObjectInstance.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/jmx/ObjectInstance.java b/core/src/main/java/flex/management/jmx/ObjectInstance.java new file mode 100644 index 0000000..8985ee0 --- /dev/null +++ b/core/src/main/java/flex/management/jmx/ObjectInstance.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.jmx; + +import javax.management.MalformedObjectNameException; + +/** + * Remotable ObjectInstance representation that complies with Flash serialization requirements. + */ +public class ObjectInstance +{ + /** + * The object name part of the <code>ObjectInstance</code>. + */ + public ObjectName objectName; + + /** + * The class name part of the <code>ObjectInstance</code>. + */ + public String className; + + /** + * Constructs an empty <code>ObjectInstance</code> instance. + * + */ + public ObjectInstance() + {} + + /** + * Constructs a <code>ObjectInstance</code> instance based upon a + * <code>javax.management.ObjectInstance</code> instance. + * + * @param objectInstance The JMX <code>ObjectInstance</code> instance to base this instance on. + */ + public ObjectInstance(javax.management.ObjectInstance objectInstance) + { + objectName = new ObjectName(objectInstance.getObjectName()); + className = objectInstance.getClassName(); + } + + /** + * Utility method to convert this <code>ObjectInstance</code> to a + * <code>javax.management.ObjectInstance</code> instance. + * + * @return A JMX <code>ObjectInstance</code> based upon this instance. + * @throws MalformedObjectNameException an exception + */ + public javax.management.ObjectInstance toObjectInstance() throws MalformedObjectNameException + { + return new javax.management.ObjectInstance(objectName.toObjectName(), className); + } +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/jmx/ObjectName.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/jmx/ObjectName.java b/core/src/main/java/flex/management/jmx/ObjectName.java new file mode 100644 index 0000000..b55ebb4 --- /dev/null +++ b/core/src/main/java/flex/management/jmx/ObjectName.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.jmx; + +import java.util.Hashtable; +import javax.management.MalformedObjectNameException; + +/** + * Remotable ObjectName representation that complies with Flash serialization requirements. + * This class is JMX 1.1 compliant. + */ +public class ObjectName +{ + /** + * String representation of the list of key properties sorted in lexical order. + */ + public String canonicalKeyPropertyListString; + + /** + * Canonical form of the name with properties sorted in lexical order. + */ + public String canonicalName; + + /** + * The domain part of the object name. + */ + public String domain; + + /** + * A Hashtable containing key-property pairs. + */ + public Hashtable keyPropertyList; + + /** + * String representation of the key properties. + */ + public String keyPropertyListString; + + /** + * Indicates whether the object name is a pattern. + */ + public boolean pattern; + + /** + * Indicates whether the object name is a pattern on key properties. + */ + public boolean propertyPattern; + + /** + * Constructs an empty <code>ObjectName</code> instance. + */ + public ObjectName() + {} + + /** + * Constructs a <code>ObjectName</code> instance based upon a + * <code>javax.management.ObjectName</code> instance. + * + * @param objectName The JMX <code>ObjectName</code> instance to base this instance on. + */ + public ObjectName(javax.management.ObjectName objectName) + { + canonicalKeyPropertyListString = objectName.getCanonicalKeyPropertyListString(); + canonicalName = objectName.getCanonicalName(); + domain = objectName.getDomain(); + keyPropertyList = objectName.getKeyPropertyList(); + keyPropertyListString = objectName.getKeyPropertyListString(); + pattern = objectName.isPattern(); + propertyPattern = objectName.isPropertyPattern(); + } + + /** + * Utility method to convert this <code>ObjectName</code> to a + * <code>javax.management.ObjectName</code> instance. + * + * @return A JMX <code>ObjectName</code> based upon this instance. + * @throws MalformedObjectNameException an exception + */ + public javax.management.ObjectName toObjectName() throws MalformedObjectNameException + { + return new javax.management.ObjectName(domain, keyPropertyList); + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/jmx/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/jmx/package-info.java b/core/src/main/java/flex/management/jmx/package-info.java new file mode 100644 index 0000000..fa47d96 --- /dev/null +++ b/core/src/main/java/flex/management/jmx/package-info.java @@ -0,0 +1,17 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.jmx; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/package-info.java b/core/src/main/java/flex/management/package-info.java new file mode 100644 index 0000000..46ac51b --- /dev/null +++ b/core/src/main/java/flex/management/package-info.java @@ -0,0 +1,17 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/runtime/AdminConsoleDisplayRegistrar.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/runtime/AdminConsoleDisplayRegistrar.java b/core/src/main/java/flex/management/runtime/AdminConsoleDisplayRegistrar.java new file mode 100644 index 0000000..f16dbce --- /dev/null +++ b/core/src/main/java/flex/management/runtime/AdminConsoleDisplayRegistrar.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.runtime; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; + +import flex.management.BaseControl; + +/** + * + */ +public class AdminConsoleDisplayRegistrar extends BaseControl implements AdminConsoleDisplayRegistrarMBean +{ + public static final String ID = "AdminConsoleDisplay"; + + private HashMap registeredExposedObjects; + + public AdminConsoleDisplayRegistrar(BaseControl parent) + { + super(parent); + registeredExposedObjects = new HashMap(); + register(); + } + + public void registerObject(int type, String beanName, String propertyName) + { + Object objects = registeredExposedObjects.get(new Integer(type)); + if (objects != null) + { + ((ArrayList)objects).add(beanName + ":" + propertyName); + } + else + { + if (type < 1) + return; + + objects = new ArrayList(); + ((ArrayList)objects).add(beanName + ":" + propertyName); + registeredExposedObjects.put(new Integer(type), objects); + } + } + + public void registerObjects(int type, String beanName, String[] propertyNames) + { + for (int i = 0; i < propertyNames.length; i++) + { + registerObject(type, beanName, propertyNames[i]); + } + } + + public void registerObjects(int[] types, String beanName, String[] propertyNames) + { + for (int j = 0; j < types.length; j++) + { + registerObjects(types[j], beanName, propertyNames); + } + } + + public Integer[] getSupportedTypes() throws IOException + { + Object[] array = registeredExposedObjects.keySet().toArray(); + Integer[] types = new Integer[array.length]; + for (int i = 0; i < array.length; i++) + { + types[i] = (Integer)array[i]; + } + return types; + } + + public String[] listForType(int type) throws IOException + { + Object list = registeredExposedObjects.get(new Integer(type)); + + return (list != null) ? (String[]) ((ArrayList)list).toArray(new String[0]) : new String[0]; + } + + public String getId() + { + return ID; + } + + public String getType() + { + return ID; + } + + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/runtime/AdminConsoleDisplayRegistrarMBean.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/runtime/AdminConsoleDisplayRegistrarMBean.java b/core/src/main/java/flex/management/runtime/AdminConsoleDisplayRegistrarMBean.java new file mode 100644 index 0000000..be7b36a --- /dev/null +++ b/core/src/main/java/flex/management/runtime/AdminConsoleDisplayRegistrarMBean.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.runtime; + +import java.io.IOException; + +import flex.management.BaseControlMBean; + +/** + * + */ +public interface AdminConsoleDisplayRegistrarMBean extends BaseControlMBean +{ + + Integer[] getSupportedTypes() throws IOException; + + String[] listForType(int type) throws IOException; + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/runtime/AdminConsoleTypes.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/runtime/AdminConsoleTypes.java b/core/src/main/java/flex/management/runtime/AdminConsoleTypes.java new file mode 100644 index 0000000..a63085d --- /dev/null +++ b/core/src/main/java/flex/management/runtime/AdminConsoleTypes.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.runtime; + +/** + * The interface defines a number of constants for admin console types. + */ +public interface AdminConsoleTypes +{ + static final int GENERAL_SERVER = 1; + static final int GENERAL_POLLABLE = 2; + static final int GENERAL_OPERATION = 3; + + static final int GRAPH_BY_POLL_INTERVAL = 50; + + static final int ENDPOINT_SCALAR = 100; + static final int ENDPOINT_POLLABLE = 101; + + static final int DESTINATION_GENERAL = 150; + static final int DESTINATION_POLLABLE = 151; +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/runtime/messaging/DestinationControl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/runtime/messaging/DestinationControl.java b/core/src/main/java/flex/management/runtime/messaging/DestinationControl.java new file mode 100644 index 0000000..2f40783 --- /dev/null +++ b/core/src/main/java/flex/management/runtime/messaging/DestinationControl.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.runtime.messaging; + +import java.util.Date; + +import flex.management.BaseControl; +import flex.management.runtime.messaging.services.ServiceControl; +import flex.messaging.Destination; +import flex.messaging.services.ServiceAdapter; + +import javax.management.ObjectName; + +/** + * The <code>DestinationControl</code> class is the MBean implementation for + * monitoring and managing a <code>Destination</code> at runtime. + */ +public abstract class DestinationControl extends BaseControl implements + DestinationControlMBean +{ + protected Destination destination; + private ObjectName adapter; + + /** + * Constructs a new <code>DestinationControl</code> instance. + * + * @param destination The <code>Destination</code> managed by this MBean. + * @param parent The parent MBean in the management hierarchy. + */ + public DestinationControl(Destination destination, BaseControl parent) + { + super(parent); + this.destination = destination; + } + + /* + * (non-Javadoc) + * @see flex.management.BaseControlMBean#getId() + */ + public String getId() + { + return destination.getId(); + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.DestinationControlMBean#getAdapter() + */ + public ObjectName getAdapter() + { + return adapter; + } + + /** + * Sets the <code>ObjectName</code> for the adapter associated with the managed destination. + * + * @param value The <code>ObjectName</code> for the adapter. + */ + public void setAdapter(ObjectName value) + { + adapter = value; + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.DestinationControlMBean#isRunning() + */ + public Boolean isRunning() + { + return Boolean.valueOf(destination.isStarted()); + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.DestinationControlMBean#getStartTimestamp() + */ + public Date getStartTimestamp() + { + return startTimestamp; + } + + /* + * (non-Javadoc) + * @see javax.management.MBeanRegistration#preDeregister() + */ + public void preDeregister() throws Exception + { + ServiceControl parent = (ServiceControl)getParentControl(); + parent.removeDestination(getObjectName()); + + // Unregister adapter of the destination + ServiceAdapter child = destination.getAdapter(); + if (child.getControl() != null) + { + child.getControl().unregister(); + child.setControl(null); + child.setManaged(false); + } + + super.preDeregister(); + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/runtime/messaging/DestinationControlMBean.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/runtime/messaging/DestinationControlMBean.java b/core/src/main/java/flex/management/runtime/messaging/DestinationControlMBean.java new file mode 100644 index 0000000..e77ac6d --- /dev/null +++ b/core/src/main/java/flex/management/runtime/messaging/DestinationControlMBean.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.runtime.messaging; + +import flex.management.BaseControlMBean; + +import java.io.IOException; +import java.util.Date; + +import javax.management.ObjectName; + +/** + * Defines the runtime monitoring and management interface for managed destinations. + */ +public interface DestinationControlMBean extends BaseControlMBean +{ + /** + * Returns the <code>ObjectName</code> for the adapter associated with this + * managed destination. + * + * @return The <code>ObjectName</code> for the adapter. + * @throws IOException Throws IOException. + */ + ObjectName getAdapter() throws IOException;; + + /** + * Returns <code>true</code> if the <code>Destination</code> is running. + * + * @return <code>true</code> if the <code>Destination</code> is running. + * @throws IOException Throws IOException. + */ + Boolean isRunning() throws IOException; + + /** + * Returns the start timestamp for the <code>Destination</code>. + * + * @return The start timestamp for the <code>Destination</code>. + * @throws IOException Throws IOException. + */ + Date getStartTimestamp() throws IOException; +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/main/java/flex/management/runtime/messaging/MessageBrokerControl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/flex/management/runtime/messaging/MessageBrokerControl.java b/core/src/main/java/flex/management/runtime/messaging/MessageBrokerControl.java new file mode 100644 index 0000000..84359c3 --- /dev/null +++ b/core/src/main/java/flex/management/runtime/messaging/MessageBrokerControl.java @@ -0,0 +1,294 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 flex.management.runtime.messaging; + +import flex.management.BaseControl; +import flex.management.runtime.AdminConsoleDisplayRegistrar; +import flex.management.runtime.AdminConsoleTypes; +import flex.messaging.MessageBroker; +import flex.messaging.endpoints.AMFEndpoint; +import flex.messaging.endpoints.AbstractEndpoint; +import flex.messaging.endpoints.Endpoint; +import flex.messaging.endpoints.HTTPEndpoint; +import flex.messaging.endpoints.StreamingAMFEndpoint; +import flex.messaging.endpoints.StreamingHTTPEndpoint; + +import java.io.IOException; +import java.util.Date; +import java.util.List; +import java.util.ArrayList; + +import javax.management.ObjectName; + +/** + * The <code>MessageBrokerControl</code> class is the MBean implemenation for monitoring + * and managing a <code>MessageBroker</code> at runtime. + */ +public class MessageBrokerControl extends BaseControl implements MessageBrokerControlMBean +{ + private static final Object classMutex = new Object(); + private static final String TYPE = "MessageBroker"; + private static int instanceCount = 0; + private String id; + private MessageBroker broker; + private List endpointNames; + private List amfEndpoints; + private List httpEndpoints; + private List enterpriseEndpoints; + private List streamingAmfEndpoints; + private List streamingHttpEndpoints; + private List services; + + /** + * Constructs a new <code>MessageBrokerControl</code> instance, assigning its + * backing <code>MessageBroker</code>. + * + * @param broker The <code>MessageBroker</code> managed by this MBean. + */ + public MessageBrokerControl(MessageBroker broker) + { + super(null); + this.broker = broker; + endpointNames = new ArrayList(); + amfEndpoints = new ArrayList(); + httpEndpoints = new ArrayList(); + enterpriseEndpoints = new ArrayList(); + streamingAmfEndpoints = new ArrayList(); + streamingHttpEndpoints = new ArrayList(); + services = new ArrayList(); + synchronized (classMutex) + { + id = TYPE + ++instanceCount; + } + + setRegistrar(new AdminConsoleDisplayRegistrar(this)); + } + + protected void onRegistrationComplete() + { + String name = this.getObjectName().getCanonicalName(); + getRegistrar().registerObject(AdminConsoleTypes.GENERAL_POLLABLE, name, "FlexSessionCount"); + getRegistrar().registerObjects(new int[] {AdminConsoleTypes.GENERAL_POLLABLE, AdminConsoleTypes.GRAPH_BY_POLL_INTERVAL }, + name, new String[] {"AMFThroughput", "HTTPThroughput", "EnterpriseThroughput"}); + + getRegistrar().registerObject(AdminConsoleTypes.GENERAL_SERVER, name, "MaxFlexSessionsInCurrentHour"); + } + + /* + * (non-Javadoc) + * @see flex.management.BaseControlMBean#getId() + */ + public String getId() + { + return id; + } + + /* + * (non-Javadoc) + * @see flex.management.BaseControlMBean#getType() + */ + public String getType() + { + return TYPE; + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.MessageBrokerControlMBean#isRunning() + */ + public Boolean isRunning() + { + return Boolean.valueOf(broker.isStarted()); + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.MessageBrokerControlMBean#getStartTimestamp() + */ + public Date getStartTimestamp() + { + return startTimestamp; + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.MessageBrokerControlMBean#getEndpoints() + */ + public ObjectName[] getEndpoints() throws IOException + { + int size = endpointNames.size(); + ObjectName[] endpointNameObjects = new ObjectName[size]; + for (int i = 0; i < size; ++i) + { + endpointNameObjects[i] = (ObjectName)endpointNames.get(i); + } + return endpointNameObjects; + } + + /** + * Adds an <code>Endpoint</code> for an endpoint registered with the backing <code>MessageBroker</code>. + * + * @param value The endpoint <code>Endpoint</code>. + */ + public void addEndpoint(Endpoint value) + { + if (value instanceof AMFEndpoint) + amfEndpoints.add(value); + else if (value instanceof HTTPEndpoint) + httpEndpoints.add(value); + else if (value instanceof StreamingAMFEndpoint) + streamingAmfEndpoints.add(value); + else if (value instanceof StreamingHTTPEndpoint) + streamingHttpEndpoints.add(value); + else + enterpriseEndpoints.add(value); + + endpointNames.add(value.getControl().getObjectName()); + } + + /** + * Removes an <code>ObjectName</code> for an endpoint registered with the backing <code>MessageBroker</code>. + * + * @param value The endpoint <code>ObjectName</code>. + */ + public void removeEndpoint(ObjectName value) + { + endpointNames.remove(value); + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.MessageBrokerControlMBean#getServices() + */ + public ObjectName[] getServices() throws IOException + { + int size = services.size(); + ObjectName[] serviceNames = new ObjectName[size]; + for (int i = 0; i < size; ++i) + { + serviceNames[i] = (ObjectName)services.get(i); + } + return serviceNames; + } + + /** + * Adds an <code>ObjectName</code> for a service registered with the backing <code>MessageBroker</code>. + * + * @param value The service <code>ObjectName</code>. + */ + public void addService(ObjectName value) + { + services.add(value); + } + + /** + * Removes an <code>ObjectName</code> for a service registered with the backing <code>MessageBroker</code>. + * + * @param value The service <code>ObjectName</code>. + */ + public void removeService(ObjectName value) + { + services.remove(value); + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.MessageBrokerControlMBean#getFlexSessionCount() + */ + public Integer getFlexSessionCount() + { + return broker.getFlexSessionManager().getFlexSessionCount(); + } + + /* + * (non-Javadoc) + * @see flex.management.runtime.MessageBrokerControlMBean#getMaxFlexSessionsInCurrentHour() + */ + public Integer getMaxFlexSessionsInCurrentHour() + { + return broker.getFlexSessionManager().getMaxFlexSessionsInCurrentHour(); + } + + /* (non-Javadoc) + * @see flex.management.runtime.messaging.MessageBrokerControlMBean#getRTMPConnectionCount() + */ + public Integer getEnterpriseConnectionCount() throws IOException + { + int connections = 0; + /* + for (int i = 0; i < rtmpEndpoints.size(); i++) + { + connections += (((RTMPEndpoint)rtmpEndpoints.get(i)).getConnectionCount()); + } + */ + return new Integer(connections); + } + + /* (non-Javadoc) + * @see flex.management.runtime.messaging.MessageBrokerControlMBean#getAMFThroughput() + */ + public Long getAMFThroughput() throws IOException + { + return new Long(calculateEndpointThroughput(amfEndpoints)); + } + + /* (non-Javadoc) + * @see flex.management.runtime.messaging.MessageBrokerControlMBean#getHTTPThroughput() + */ + public Long getHTTPThroughput() throws IOException + { + return new Long(calculateEndpointThroughput(httpEndpoints)); + } + + /* (non-Javadoc) + * @see flex.management.runtime.messaging.MessageBrokerControlMBean#getRTMPThroughput() + */ + public Long getEnterpriseThroughput() throws IOException + { + return new Long(calculateEndpointThroughput(enterpriseEndpoints)); + } + + /* (non-Javadoc) + * @see flex.management.runtime.messaging.MessageBrokerControlMBean#getStreamingAMFThroughput() + */ + public Long getStreamingAMFThroughput() throws IOException + { + return new Long(calculateEndpointThroughput(streamingAmfEndpoints)); + } + + /* (non-Javadoc) + * @see flex.management.runtime.messaging.MessageBrokerControlMBean#getStreamingHTTPThroughput() + */ + public Long getStreamingHTTPThroughput() throws IOException + { + return new Long(calculateEndpointThroughput(streamingHttpEndpoints)); + } + + private long calculateEndpointThroughput(List endpoints) + { + long throughput = 0; + + for (int i = 0; i < endpoints.size(); i++) + { + // This method shouldn't be used with Lists containing objects that are not AbstractEndpoints + if (endpoints.get(i) instanceof AbstractEndpoint) + throughput += ((AbstractEndpoint)endpoints.get(i)).getThroughput(); + } + + return throughput; + } +}