Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 42B1A11CD0 for ; Fri, 25 Apr 2014 05:35:14 +0000 (UTC) Received: (qmail 57879 invoked by uid 500); 25 Apr 2014 05:34:22 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 57374 invoked by uid 500); 25 Apr 2014 05:34:10 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 57015 invoked by uid 99); 25 Apr 2014 05:34:00 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Apr 2014 05:34:00 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4A873992C31; Fri, 25 Apr 2014 05:34:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aharui@apache.org To: commits@flex.apache.org Date: Fri, 25 Apr 2014 05:34:11 -0000 Message-Id: <17aa99d2075740538ef4a89f67d9663d@git.apache.org> In-Reply-To: <740c3ca311404cb1806d7c27ec493188@git.apache.org> References: <740c3ca311404cb1806d7c27ec493188@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/51] [partial] BlazeDS Donation from Adobe Systems Inc http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/7a58369c/modules/core/src/flex/management/jmx/MBeanOperationInfo.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/jmx/MBeanOperationInfo.java b/modules/core/src/flex/management/jmx/MBeanOperationInfo.java new file mode 100755 index 0000000..a514ba5 --- /dev/null +++ b/modules/core/src/flex/management/jmx/MBeanOperationInfo.java @@ -0,0 +1,119 @@ +/* + * 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. + * + * @author shodgson + */ +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 INFO, ACTION, ACTION_INFO, UNKNOWN. + */ + public int impact; + + /** + * Constructs an empty MBeanOperationInfo instance. + */ + public MBeanOperationInfo() + {} + + /** + * Constructs a MBeanOperationInfo instance based upon a + * javax.management.MBeanOperationInfo instance. + * + * @param mbeanOperationInfo The JMX MBeanOperationInfo 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 MBeanOperationInfo to a + * javax.management.MBeanOperationInfo instance. + * + * @return A JMX MBeanOperationInfo 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/7a58369c/modules/core/src/flex/management/jmx/MBeanParameterInfo.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/jmx/MBeanParameterInfo.java b/modules/core/src/flex/management/jmx/MBeanParameterInfo.java new file mode 100755 index 0000000..d56b941 --- /dev/null +++ b/modules/core/src/flex/management/jmx/MBeanParameterInfo.java @@ -0,0 +1,73 @@ +/* + * 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. + * + * @author shodgson + */ +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 MBeanParameterInfo instance. + */ + public MBeanParameterInfo() + {} + + /** + * Constructs a MBeanParameterInfo instance based upon a + * javax.management.MBeanParameterInfo instance. + * + * @param mbeanParameterInfo The JMX MBeanParameterInfo 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 MBeanParameterInfo to a + * javax.management.MBeanParameterInfo instance. + * + * @return A JMX MBeanParameterInfo 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/7a58369c/modules/core/src/flex/management/jmx/MBeanServerGateway.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/jmx/MBeanServerGateway.java b/modules/core/src/flex/management/jmx/MBeanServerGateway.java new file mode 100755 index 0000000..f522dec --- /dev/null +++ b/modules/core/src/flex/management/jmx/MBeanServerGateway.java @@ -0,0 +1,909 @@ +/* + * 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: + *

    + *
  • getDomains() - JMX 1.2
  • + *
  • addNotificationListener()/removeNotificationListener() - Flash objects + * cannot listen directly for MBean notifications.
  • + *
  • instantiate() - returns a reference to a Java object that is not useful + * to a remote Flash client.
  • + *
  • deserialize() - deprecated.
  • + *
  • getClassLoaderFor() - meaningless to a Flash client.
  • + *
  • getClassLoader() - meaningless to a Flash client.
  • + *
  • getClassLoaderRepository() - meaningless to a Flash client.
  • + *
+ *

+ * Modifications to the base MBeanServer API: + *

    + *
  • * 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.
  • + *
  • queryMBeans() - returns an Array of ObjectInstances rather than a java.util.Set + * and does not currently support the QueryExp argument.
  • + *
  • queryNames() returns an Array of ObjectNames rather than a java.util.Set + * and does not currently support the QueryExp argument.
  • + *
  • getAttributes() returns an Array of Attributes rather than an AttributeList.
  • + *
  • setAttributes() accepts and returns Arrays of Attributes rather than AttributeLists.
  • + *
+ *

+ * Additonal Flex-specific methods: + *

    + *
  • getFlexMBeanCount()
  • + *
  • getFlexDomains()
  • + *
  • getFlexMBeanObjectNames()
  • + *
+ *

+ * + * @author shodgson + */ +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. + *

+ * This method does not support a QueryExp argument for additional filtering of the queried set. + *

+ * + * @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. + *

+ * This method does not support a QueryExp argument for additional filtering of the queried set. + *

+ * + * @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/7a58369c/modules/core/src/flex/management/jmx/ObjectInstance.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/jmx/ObjectInstance.java b/modules/core/src/flex/management/jmx/ObjectInstance.java new file mode 100755 index 0000000..03e81a0 --- /dev/null +++ b/modules/core/src/flex/management/jmx/ObjectInstance.java @@ -0,0 +1,67 @@ +/* + * 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. + * + * @author shodgson + */ +public class ObjectInstance +{ + /** + * The object name part of the ObjectInstance. + */ + public ObjectName objectName; + + /** + * The class name part of the ObjectInstance. + */ + public String className; + + /** + * Constructs an empty ObjectInstance instance. + * + */ + public ObjectInstance() + {} + + /** + * Constructs a ObjectInstance instance based upon a + * javax.management.ObjectInstance instance. + * + * @param objectInstance The JMX ObjectInstance 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 ObjectInstance to a + * javax.management.ObjectInstance instance. + * + * @return A JMX ObjectInstance based upon this instance. + */ + 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/7a58369c/modules/core/src/flex/management/jmx/ObjectName.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/jmx/ObjectName.java b/modules/core/src/flex/management/jmx/ObjectName.java new file mode 100755 index 0000000..2c3356e --- /dev/null +++ b/modules/core/src/flex/management/jmx/ObjectName.java @@ -0,0 +1,99 @@ +/* + * 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. + * + * @author shodgson + */ +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 ObjectName instance. + */ + public ObjectName() + {} + + /** + * Constructs a ObjectName instance based upon a + * javax.management.ObjectName instance. + * + * @param objectName The JMX ObjectName 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 ObjectName to a + * javax.management.ObjectName instance. + * + * @return A JMX ObjectName based upon this instance. + */ + 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/7a58369c/modules/core/src/flex/management/jmx/package-info.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/jmx/package-info.java b/modules/core/src/flex/management/jmx/package-info.java new file mode 100755 index 0000000..638bdf6 --- /dev/null +++ b/modules/core/src/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/7a58369c/modules/core/src/flex/management/package-info.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/package-info.java b/modules/core/src/flex/management/package-info.java new file mode 100755 index 0000000..814e6ef --- /dev/null +++ b/modules/core/src/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/7a58369c/modules/core/src/flex/management/runtime/AdminConsoleDisplayRegistrar.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/runtime/AdminConsoleDisplayRegistrar.java b/modules/core/src/flex/management/runtime/AdminConsoleDisplayRegistrar.java new file mode 100755 index 0000000..222aafa --- /dev/null +++ b/modules/core/src/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; + +/** + * @exclude + */ +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/7a58369c/modules/core/src/flex/management/runtime/AdminConsoleDisplayRegistrarMBean.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/runtime/AdminConsoleDisplayRegistrarMBean.java b/modules/core/src/flex/management/runtime/AdminConsoleDisplayRegistrarMBean.java new file mode 100755 index 0000000..cc12ffb --- /dev/null +++ b/modules/core/src/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; + +/** + * @exclude + */ +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/7a58369c/modules/core/src/flex/management/runtime/AdminConsoleTypes.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/runtime/AdminConsoleTypes.java b/modules/core/src/flex/management/runtime/AdminConsoleTypes.java new file mode 100755 index 0000000..a6a113a --- /dev/null +++ b/modules/core/src/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/7a58369c/modules/core/src/flex/management/runtime/messaging/DestinationControl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/runtime/messaging/DestinationControl.java b/modules/core/src/flex/management/runtime/messaging/DestinationControl.java new file mode 100755 index 0000000..a83a6f7 --- /dev/null +++ b/modules/core/src/flex/management/runtime/messaging/DestinationControl.java @@ -0,0 +1,119 @@ +/* + * 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 DestinationControl class is the MBean implementation for + * monitoring and managing a Destination at runtime. + * + * @author shodgson + */ +public abstract class DestinationControl extends BaseControl implements + DestinationControlMBean +{ + protected Destination destination; + private ObjectName adapter; + + /** + * Constructs a new DestinationControl instance. + * + * @param destination The Destination 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 ObjectName for the adapter associated with the managed destination. + * + * @param value The ObjectName 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/7a58369c/modules/core/src/flex/management/runtime/messaging/DestinationControlMBean.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/runtime/messaging/DestinationControlMBean.java b/modules/core/src/flex/management/runtime/messaging/DestinationControlMBean.java new file mode 100755 index 0000000..acc1399 --- /dev/null +++ b/modules/core/src/flex/management/runtime/messaging/DestinationControlMBean.java @@ -0,0 +1,57 @@ +/* + * 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. + * + * @author shodgson + */ +public interface DestinationControlMBean extends BaseControlMBean +{ + /** + * Returns the ObjectName for the adapter associated with this + * managed destination. + * + * @return The ObjectName for the adapter. + * @throws IOException Throws IOException. + */ + ObjectName getAdapter() throws IOException;; + + /** + * Returns true if the Destination is running. + * + * @return true if the Destination is running. + * @throws IOException Throws IOException. + */ + Boolean isRunning() throws IOException; + + /** + * Returns the start timestamp for the Destination. + * + * @return The start timestamp for the Destination. + * @throws IOException Throws IOException. + */ + Date getStartTimestamp() throws IOException; +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/7a58369c/modules/core/src/flex/management/runtime/messaging/MessageBrokerControl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/runtime/messaging/MessageBrokerControl.java b/modules/core/src/flex/management/runtime/messaging/MessageBrokerControl.java new file mode 100755 index 0000000..6b8c5a5 --- /dev/null +++ b/modules/core/src/flex/management/runtime/messaging/MessageBrokerControl.java @@ -0,0 +1,297 @@ +/* + * 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 MessageBrokerControl class is the MBean implemenation for monitoring + * and managing a MessageBroker at runtime. + * + * @author shodgson + * @author majacobs + */ +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 MessageBrokerControl instance, assigning its + * backing MessageBroker. + * + * @param broker The MessageBroker 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 Endpoint for an endpoint registered with the backing MessageBroker. + * + * @param value The endpoint Endpoint. + */ + 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 ObjectName for an endpoint registered with the backing MessageBroker. + * + * @param value The endpoint ObjectName. + */ + 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 ObjectName for a service registered with the backing MessageBroker. + * + * @param value The service ObjectName. + */ + public void addService(ObjectName value) + { + services.add(value); + } + + /** + * Removes an ObjectName for a service registered with the backing MessageBroker. + * + * @param value The service ObjectName. + */ + 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; + } +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/7a58369c/modules/core/src/flex/management/runtime/messaging/MessageBrokerControlMBean.java ---------------------------------------------------------------------- diff --git a/modules/core/src/flex/management/runtime/messaging/MessageBrokerControlMBean.java b/modules/core/src/flex/management/runtime/messaging/MessageBrokerControlMBean.java new file mode 100755 index 0000000..a209c4b --- /dev/null +++ b/modules/core/src/flex/management/runtime/messaging/MessageBrokerControlMBean.java @@ -0,0 +1,132 @@ +/* + * 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 MessageBrokers. + * + * @author shodgson + */ +public interface MessageBrokerControlMBean extends BaseControlMBean +{ + /** + * Returns true if the MessageBroker is running. + * + * @return true if the MessageBroker is running. + * @throws IOException Throws IOException. + */ + Boolean isRunning() throws IOException; + + /** + * Returns the start timestamp for the MessageBroker. + * + * @return The start timestamp for the MessageBroker. + * @throws IOException Throws IOException. + */ + Date getStartTimestamp() throws IOException; + + /** + * Returns the ObjectNames for endpoints that are registered with the + * managed MessageBroker. + * + * @return The ObjectNames for endpoints registered with the managed MessageBroker. + * @throws IOException Throws IOException. + */ + ObjectName[] getEndpoints() throws IOException; + + /** + * Returns the ObjectNames for services that are registered with the + * managed MessageBroker. + * + * @return The ObjectNames for services registered with the managed MessageBroker. + * @throws IOException Throws IOException. + */ + ObjectName[] getServices() throws IOException; + + /** + * Returns Flex session count for the MessageBroker. + * + * @return Flex session count for the MessageBroker. + * @throws IOException Throws IOException. + */ + Integer getFlexSessionCount() throws IOException; + + /** + * Returns the maximum concurrent Flex session count for the + * MessageBroker in the current hour. + * + * @return The maximum concurrent Flex session count for the + * MessageBroker over the course of the last hour. + * @throws IOException Throws IOException. + */ + Integer getMaxFlexSessionsInCurrentHour() throws IOException; + + /** + * Returns the number of Enterprise Connections across all + * Enterprise Endpoints. + * + * @return The number of Enterprise Connections + * @throws IOException Throws IOException. + */ + Integer getEnterpriseConnectionCount() throws IOException; + + /** + * Returns the total number of bytes passing through all AMF endpoints. + * + * @return The total number of bytes passing through all AMF endpoints. + * @throws IOException Throws IOException. + */ + Long getAMFThroughput() throws IOException; + + /** + * Returns the total number of bytes passing through all HTTP endpoints. + * + * @return The total number of bytes passing through all HTTP endpoints. + * @throws IOException Throws IOException. + */ + Long getHTTPThroughput() throws IOException; + + /** + * Returns the total number of bytes passing through all Enterprise endpoints. + * + * @return The total number of bytes passing through all Enterprise endpoints. + * @throws IOException Throws IOException. + */ + Long getEnterpriseThroughput() throws IOException; + + /** + * Returns the total number of bytes passing through all streaming AMF endpoints. + * + * @return The total number of bytes passing through all streaming AMF endpoints. + * @throws IOException Throws IOException. + */ + Long getStreamingAMFThroughput() throws IOException; + + /** + * Returns the total number of bytes passing through all streaming HTTP endpoints. + * + * @return The total number of bytes passing through all streaming HTTP endpoints. + * @throws IOException Throws IOException. + */ + Long getStreamingHTTPThroughput() throws IOException; +}