http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/build.xml ---------------------------------------------------------------------- diff --git a/core/build.xml b/core/build.xml new file mode 100755 index 0000000..7183f84 --- /dev/null +++ b/core/build.xml @@ -0,0 +1,158 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<project name="modules/core/build.xml" default="main" basedir="../.."> + + <!-- properties --> + <property file="${basedir}/build.properties"/> + <property name="lib.dir" value="${basedir}/lib"/> + + <property name="module.dir" value="${basedir}/modules/core"/> + <property name="module.lib.dir" location="${module.dir}/lib"/> + <property name="tomcat.lib.dir" location="${basedir}/servers/apache-tomcat-6.0.29/lib" /> + <property name="module.src" value="${module.dir}/src"/> + <property name="module.classes" value="${module.dir}/classes"/> + <property name="module.jar" value="${lib.dir}/flex-messaging-core.jar"/> + <property name="module.dist.dir" value="${basedir}/dist/source"/> + + <property name="common.src" value="${basedir}/modules/common/src"/> + <property name="remoting.src" value="${basedir}/modules/remoting/src"/> + <property name="proxy.src" value="${basedir}/modules/proxy/src"/> + <property name="opt.src" value="${basedir}/modules/opt/src"/> + + <property name="build.number" value=""/> + + <!-- j2ee apis required to compile --> + <path id="classpath"> + <fileset dir="${lib.dir}" erroronmissingdir="false" includes="**/*.jar"/> + <fileset dir="${module.lib.dir}" erroronmissingdir="false" includes="**/*.jar"/> + <fileset dir="${tomcat.lib.dir}" erroronmissingdir="false" includes="**/*.jar"/> + </path> + + <target name="main" depends="clean,prepare,run-depend,jar" description="cleans and runs the full build"/> + <target name="dev" depends="prepare,run-depend,jar" description="runs src.depend build for development"/> + + <target name="prepare"> + <mkdir dir="${lib.dir}"/> + <mkdir dir="${module.classes}"/> + </target> + + <target name="run-depend" if="src.depend"> + <echo message="Removing class files that changed and dependent class files."/> + <depend cache="${module.classes}" srcdir="${module.src}" destdir="${module.classes}"/> + </target> + + <target name="compile" depends="prepare" description="compile"> + <javac debug="${src.debug}" destdir="${module.classes}" + srcdir="${module.src}" classpathref="classpath" > + <include name="**/*.java" /> + <exclude name="flex/messaging/cluster/JGroupsCluster.java" /> + <exclude name="flex/messaging/cluster/ClusterNode.java" /> + <exclude name="flex/messaging/cluster/ClusterMembershipListener.java" /> + </javac> + <echo file="${module.classes}/flex/messaging/version.properties" append="false">build=${build.number}</echo> + <copy todir="${module.classes}/flex/messaging" overwrite="true"> + <fileset dir="${module.src}/flex/messaging" includes="*.properties"/> + </copy> + <copy toDir="${module.classes}" file="${module.dir}/AdobeInfo.xml" /> + </target> + + <!-- only compile jgroups code if jgroups present --> + <condition property="jgroups.available"> + <available classname="org.jgroups.Channel" classpathref="classpath"/> + </condition> + + <target name="compile-jgroups" depends="prepare" if="jgroups.available"> + <echo >-== Found JGroups, compiling JGroups cluster implementation ==-</echo> + <javac debug="${src.debug}" destdir="${module.classes}" srcdir="${module.src}" + classpathref="classpath" > + <include name= "flex/messaging/cluster/JGroupsCluster.java" /> + <include name= "flex/messaging/cluster/ClusterNode.java" /> + <include name= "flex/messaging/cluster/ClusterMembershipListener.java" /> + </javac> + </target> + + <!-- jar containing messaging core infrastructure --> + <target name="jar" depends="compile,compile-jgroups"> + <jar destfile="${module.jar}" basedir="${module.classes}"> + <include name="AdobeInfo.xml"/> + <include name="flex/management/**"/> + <include name="flex/messaging/**"/> + <include name="flex/core/**"/> + <exclude name=".dependency-info/**"/> + <manifest> + <attribute name="Sealed" value="${manifest.sealed}"/> + <attribute name="Implementation-Title" value="${manifest.Implementation-Title} - Community Edition"/> + <attribute name="Implementation-Version" value="${manifest.Implementation-Version}.${build.number}"/> + <attribute name="Implementation-Vendor" value="${manifest.Implementation-Vendor}"/> + </manifest> + </jar> + <delete failonerror="false"> + <fileset dir="${module.classes}/flex/messaging" includes="*.properties"/> + </delete> + </target> + + <target name="clean" description="clean"> + <delete file="${module.jar}" failonerror="false"/> + <delete failonerror="false" includeEmptyDirs="true"> + <fileset dir="${module.classes}"> + <include name="**/*"/> + <exclude name="dependencies.txt"/> + <exclude name=".dependency-info/**"/> + </fileset> + </delete> + <delete dir="${module.classes}" failonerror="false" includeEmptyDirs="true"/> + <echo>modules/core clean</echo> + </target> + + <target name="javadoc"> + <path id="javadoc.classpath"> + <path refid="classpath"/> + <fileset dir="${basedir}/modules/opt/lib" includes="*.jar" excludes="catalina-708.jar"/> + </path> + <mkdir dir="${basedir}/docs"/> + <mkdir dir="${basedir}/docs/api"/> + <javadoc + access="public" + destdir="${basedir}/docs/api" + doclet="ExcludeDoclet" + docletpathref="javadoc.classpath" + author="false" + version="true" + use="true" + sourcePath="${common.src};${module.src};${remoting.src};${proxy.src};${opt.src}/jrun;${opt.src}/oracle;${opt.src}/tomcat;${opt.src}/weblogic;${opt.src}/websphere" + classpathref="javadoc.classpath" + packageNames="flex.*" + failonerror="true" + windowtitle="${manifest.Implementation-Title} - Public APIs"> + + <doctitle><![CDATA[<h1>${manifest.Implementation-Title} - Public APIs</h1><h2>Build: ${manifest.Implementation-Version}.${build.number}</h2>]]></doctitle> + <bottom><![CDATA[<i>Copyright © 2008 Adobe Systems Inc. All Rights Reserved.</i>]]></bottom> + <group title="Messaging APIs" packages="flex.messaging:flex.messaging.services"/> + <group title="AMF Serialization APIs" packages="flex.messaging.io.amf"/> + <group title="Logging and Debugging APIs" packages="flex.messaging.log"/> + <group title="Configuration APIs" packages="flex.messaging.config:flex.messaging.security"/> + <group title="Management APIs" packages="flex.management, flex.management.jmx, flex.management.runtime.*"/> + <link offline="false" href="http://java.sun.com/j2se/1.5.0/docs/api/" packagelistLoc="C:\tmp"/> + </javadoc> + <zip destfile="${basedir}/docs/javadoc.zip" basedir="${basedir}/docs/api" /> + </target> + +</project> +
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml new file mode 100755 index 0000000..0293d62 --- /dev/null +++ b/core/pom.xml @@ -0,0 +1,94 @@ +<!-- + +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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.blazeds</groupId> + <artifactId>blazeds</artifactId> + <version>4.7.3-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>flex-messaging-core</artifactId> + + <dependencies> + <dependency> + <groupId>org.apache.flex.blazeds</groupId> + <artifactId>flex-messaging-common</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>activemq-core</artifactId> + <version>5.7.0</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>jgroups</groupId> + <artifactId>jgroups</artifactId> + <version>2.9.0.GA</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>javax.jms</groupId> + <artifactId>jms-api</artifactId> + <version>1.1-rev-1</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <sourceDirectory>src</sourceDirectory> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>javacc-maven-plugin</artifactId> + <version>2.5</version> + <executions> + <execution> + <phase>generate-sources</phase> + <id>javacc</id> + <goals> + <goal>javacc</goal> + </goals> + <configuration> + <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <outputDirectory>${project.build.sourceDirectory}</outputDirectory> + <!-- + it will generate the source in the same folder, the generated + files need to be added to .svn:ignore + --> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/BaseControl.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/BaseControl.java b/core/src/flex/management/BaseControl.java new file mode 100644 index 0000000..a66a104 --- /dev/null +++ b/core/src/flex/management/BaseControl.java @@ -0,0 +1,514 @@ +/* + * 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; + +import flex.management.runtime.AdminConsoleDisplayRegistrar; +import flex.messaging.FlexContext; + +import java.util.Date; +import java.util.List; +import java.util.ArrayList; +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.MalformedObjectNameException; +import javax.management.MBeanRegistration; +import javax.management.MBeanRegistrationException; +import javax.management.MBeanServer; +import javax.management.NotCompliantMBeanException; +import javax.management.ObjectName; +import javax.servlet.ServletConfig; + +/** + * The implementation of the <code>BaseControlMBean</code> interface. This + * abstract class provides the core functionality that all Flex control MBeans + * require. + * <p> + * Defining concrete implementations of <code>getId()</code> and + * <code>getType()</code> are left to subclasses, but this base class does + * provide access to the parent MBean for each instance. This class also + * implements the <code>MBeanRegistration</code> interface, and it + * automatically stores a reference to the MBean server in each instance upon + * registration. Subclasses may choose to override none, any, or all of the + * methods defined by the <code>MBeanRegistration</code> interface, but any + * overrides should be sure to invoke the overridden method with a call to their + * superclass. + * </p><p> + * The <code>register()</code> method provides a simple and consistent way to + * register instances with the MBean server, and the + * <code>getObjectName()</code> method gaurantees consistent, well-formed + * <code>ObjectName</code>s for all MBean instances.</p> + */ +public abstract class BaseControl implements BaseControlMBean, + MBeanRegistration +{ + /** + * The prefix used for the domain part of control MBean names. + */ + public static final String DOMAIN_PREFIX = "flex.runtime"; + private static final int MALFORMED_OBJECTNAME = 10400; + private static final int UNREG_EXCEPTION = 10401; + private static final int UNREG_NOTFOUND = 10402; + private static final int REG_EXCEPTION = 10403; + private static final int REG_ALREADYEXISTS = 10404; + private static final int REG_NOTCOMPLIANT = 10405; + private static final int DISABLE_MANAGEMENT = 10426; + + protected Date startTimestamp; + private BaseControl parent; + private ObjectName objectName; + private ObjectName registeredObjectName; + private MBeanServer server; + private boolean registered = false; + + private AdminConsoleDisplayRegistrar registrar; + + // Implements flex.management.BaseControlMBean.getId; inherits javadoc + // specification. + public abstract String getId(); + + // Implements flex.management.BaseControlMBean.getType; inherits javadoc + // specification. + public abstract String getType(); + + // Implements flex.management.BaseControlMBean.getParent; inherits javadoc + // specification. + public final ObjectName getParent() + { + return (parent != null) ? parent.getObjectName() : null; + } + + /** + * Returns an identifier for the application that hosts the component that + * this control manages. + * + * @return An identifier for the application that hosts the component this + * control manages. + */ + public String getApplicationId() + { + String id = null; + // Our base implementation attempts to use the current servlet context + // name as our application identifier. + ServletConfig config = FlexContext.getServletConfig(); + if (config != null) + { + id = config.getServletContext().getServletContextName(); + } + return (id != null) ? id.replace(":", "") : ""; + } + + /** + * Set the register object. + * @param registrar the registrar to set + */ + protected void setRegistrar(AdminConsoleDisplayRegistrar registrar) + { + this.registrar = registrar; + } + + /** + * Return the registar object. + * @return the registrar + */ + public AdminConsoleDisplayRegistrar getRegistrar() + { + if ((parent == null) && (this.registrar == null)) + { + return new AdminConsoleDisplayRegistrar(null); + } + + return (this.registrar != null) ? this.registrar : parent.getRegistrar(); + } + + /** + * Constructs a <code>BaseControl</code> instance that references its + * parent; the parent may be null for root control MBeans. + * + * @param parent The parent <code>BaseControl</code> for this instance or + * null if this instance is the root of a control hierarchy. + */ + public BaseControl(BaseControl parent) + { + this.parent = parent; + } + + /** + * Returns the parent <code>BaseControl</code> of this instance. + * + * @return The parent <code>BaseControl</code>. + */ + public final BaseControl getParentControl() + { + return parent; + } + + /** + * The <code>MBeanServer</code> that this instance is registered with. If + * this instance has not been registered this method returns + * <code>null</code>. + * + * @return The <code>MBeanServer</code> that this instance is registered + * with. + */ + public final MBeanServer getMBeanServer() + { + return server; + } + + /** + * Registers this instance with the MBean server. + * + * It may throw ManagementException If an <code>MBeanRegistrationException</code> + * or <code>InstanceAlreadyExistsException</code> is thrown while + * registering this MBean, the typed exception is wrapped in a + * runtime <code>ManagementException</code> and rethrown. + */ + public final void register() + { + if (!registered) + { + MBeanServer server = MBeanServerLocatorFactory.getMBeanServerLocator().getMBeanServer(); + ObjectName name = getObjectName(); + try + { + if (server.isRegistered(name)) + { + server.unregisterMBean(name); + } + + registeredObjectName = server.registerMBean(this, name).getObjectName(); + registered = true; + onRegistrationComplete(); + + } + catch (ManagementException me) + { + throw me; + } + catch (MBeanRegistrationException mre) + { + // Rethrow with useful message if this ever happens. + ManagementException me = new ManagementException(); + me.setMessage(REG_EXCEPTION, new Object[] {name.toString()}); + me.setRootCause(mre); + throw me; + } + catch (InstanceAlreadyExistsException iaee) + { + // If registration is not working at all, inform the user that + // they may + // work around the issue by disabling management (no MBeans will + // be registered). + if (!server.isRegistered(name)) + { + ManagementException me = new ManagementException(); + me.setMessage(DISABLE_MANAGEMENT, new Object[] {name.toString()}); + throw me; + } + else + { + // Rethrow with useful message if this ever happens. + ManagementException me = new ManagementException(); + me.setMessage(REG_ALREADYEXISTS, new Object[] {name.toString()}); + throw me; + } + } + catch (NotCompliantMBeanException ncme) + { + // Rethrow with useful message if this ever happens. + ManagementException me = new ManagementException(); + me.setMessage(REG_NOTCOMPLIANT, new Object[] {name.toString()}); + throw me; + } + catch (InstanceNotFoundException infe) + { + // Rethrow with useful message if this ever happens. + ManagementException me = new ManagementException(); + me.setMessage(UNREG_NOTFOUND, new Object[] {name.toString()}); + throw me; + } + } + } + + /** + * This method is called after the MBean has been registered and after the + * MBean server has returned the registeredObjectName. Classes that need + * access to the actual Object name should override this method rather than + * the postRegister method. + */ + protected void onRegistrationComplete() + { + + } + + /** + * Unregisters this instance from the MBean server if it has been registered + * previously. + */ + public final void unregister() + { + if (registered) + { + // This method may be called when the JVM is being unloaded, so if + // our + // external error strings are loaded as missing, fall back to + // hard-coded + // strings. + try + { + if (server.isRegistered(registeredObjectName)) + { + server.unregisterMBean(registeredObjectName); + } + + registeredObjectName = null; + registered = false; + } + catch (ManagementException me) + { + throw me; + } + catch (MBeanRegistrationException mre) + { + // Rethrow with useful message if this ever happens. + ManagementException me = new ManagementException(); + me.setMessage(UNREG_EXCEPTION, new Object[] {registeredObjectName.toString()}); + if (me.getMessage().indexOf(Integer.toString(UNREG_EXCEPTION)) != -1) + { + me.setMessage("The MBean named, '" + registeredObjectName.toString() + "', could not be unregistered because its preDeregister() method threw an exception."); + } + me.setRootCause(mre); + throw me; + } + catch (InstanceNotFoundException infe) + { + // Rethrow with useful message if this ever happens. + ManagementException me = new ManagementException(); + me.setMessage(UNREG_NOTFOUND, new Object[] {registeredObjectName.toString()}); + if (me.getMessage().indexOf(Integer.toString(UNREG_NOTFOUND)) != -1) + { + me.setMessage("The MBean named, '" + registeredObjectName.toString() + "', could not be unregistered because it is not currently registered."); + } + throw me; + } + } + } + + /** + * Returns the <code>ObjectName</code> for this instance, according to the + * following format: + * <code>{domain}[&#46;{appId}]:type={type}[&#44;{parent type}={parent id}]*[&#44;server={server}]&#63;&#44;id={id}</code>. + * <ul> + * <li><code>domain</code>: The domain specified by the DOMAIN_PREFIX + * constant followed by the application identifier if one is available.</li> + * <li><code>type</code>: The short type name of the resource managed by + * the MBean. + * - The <code>MessageBrokerControlMBean</code> manages + * the <code>flex.messaging.MessageBroker</code> so: + * <code>type=MessageBroker</code> </li> + * <li><code>id</code>: The id value for the resource managed by this + * MBean. If no name or id is available on the resource, an id will be + * fabricated according to this strategy: + * + * <em>id = {type} + N</em> (where N is a numeric increment for instances + * of this type) </li> + * <li>* optional containment keys</li> + * </ul> + * The runtime MBean model is hierarchical, with all MBeans ultimately + * contained by the root <code>MessageBrokerControlMBean</code>. The + * <code>ObjectName</code>s used for these MBeans describe this + * containment in the following fashion. First, the 'type' key for a + * contained MBean indicates the containment hierarchy for the bean. So, the + * <code>ObjectName</code> for an <code>RTMPEndpointControlMBean</code> + * would be: <code>type=MessageBroker.RTMPEndpoint</code> + * + * In addition to the hierarchical 'type' key, the full + * <code>ObjectName</code> for this <code>RTMPEndpointControlMBean</code> + * also contains a containment key: + * <code>MessageBroker=MessageBroker1</code> + * + * Optional containment keys have the format: + * <em>{parent type}={parent name}</em>. A containment key is added for + * each ancestor up to the root of the hierarchy and these keys allow the + * <code>ObjectName</code> for any MBean instance to fully describe its + * specific location in the hierarchy. To complete the example, the full + * <code>ObjectName</code> for the example + * <code>RTMPEndpointControlMBean</code> would be: + * <code>flex:type=MessageBroker.RTMPEndpoint,MessageBroker=MessageBroker1,id=RTMPEndpoint1</code> + * <p> + * If the MBean is registered with the MBean server, this method returns the + * <code>ObjectName</code> that the MBean was registered under and this + * value may contain additional key-value pairs injected by the container or + * MBean server. + * </p> + * + * @return The <code>ObjectName</code> for this instance. + */ + public final ObjectName getObjectName() + { + if (registered) + return registeredObjectName; + + if (objectName == null) + { + StringBuffer buffer = new StringBuffer(); + buffer.append(DOMAIN_PREFIX); + String appId = getApplicationId(); + if (appId != null && appId.length() > 0) + { + buffer.append('.'); + buffer.append(appId); + } + buffer.append(":type="); + // Build hierarchical type value. + List types = new ArrayList(); + List ids = new ArrayList(); + types.add(getType()); + ids.add(getId()); + BaseControl ancestor = parent; + while (ancestor != null) + { + types.add(ancestor.getType()); + ids.add(ancestor.getId()); + ancestor = ancestor.getParentControl(); + } + for (int i = types.size() - 1; i >= 0; --i) + { + buffer.append((String)types.get(i)); + if (i > 0) + { + buffer.append('.'); + } + } + buffer.append(','); + // Add containment keys. + for (int i = ids.size() - 1; i >= 1; --i) + { + buffer.append((String)types.get(i)); + buffer.append('='); + buffer.append((String)ids.get(i)); + buffer.append(','); + } + buffer.append("id="); + buffer.append(getId()); + String name = buffer.toString(); + // TODO: Seth: add server identifier key if we're running in a + // cluster? + try + { + objectName = new ObjectName(name); + } + catch (MalformedObjectNameException mone) + { + // Rethrow with useful message if this ever happens. + ManagementException me = new ManagementException(); + me.setMessage(MALFORMED_OBJECTNAME, new Object[] {name}); + throw me; + } + } + return objectName; + } + + /** + * Implements <code>javax.management.MBeanRegistration.preRegister</code>. + * Allows the MBean to perform any operations it needs before being + * registered in the MBean server. This base implementation stores a + * reference to the MBean server that may be accessed via + * <code>getMBeanServer()</code>. If subclasses override, they must call + * <code>super.preRegister()</code>. + * + * @param server The Mbean server in which the MBean will be registered. + * @param name The object name of the MBean. + * @return The name the MBean will be registered under. + * @throws Exception when the process failed + */ + public ObjectName preRegister(MBeanServer server, ObjectName name) + throws Exception + { + this.server = server; + return (name == null) ? getObjectName() : name; + } + + /** + * Implements <code>javax.management.MBeanRegistration.postRegister</code>. + * Allows the MBean to perform any operations needed after having been + * registered in the MBean server or after the registration has failed. This + * base implementation is a no-op that may be overridden. + * + * @param registrationDone Indicates whether or not the MBean was + * successfully registered in the MBean server. + */ + public void postRegister(Boolean registrationDone) + { + // No-op. + } + + /** + * Implements <code>javax.management.MBeanRegistration.preDeregister</code>. + * Allows the MBean to perform any operations needed after having been + * unregistered in the MBean server. This base implementation is a no-op + * that may be overridden. + * @throws Exception when the process failed + */ + public void preDeregister() throws Exception + { + // No-op. + } + + /** + * Implements <code>javax.management.MBeanRegistration.postDeregister</code>. + * Allows the MBean to perform any operations it needs before being + * unregistered by the MBean server. This base implementation is a no-op + * that may be overridden. + */ + public void postDeregister() + { + // No-op. + } + + /** + * Sets the start timestamp for the managed component. + * + * @param value The start timestamp for the managed component. + */ + public void setStartTimestamp(Date value) + { + startTimestamp = value; + } + + /** + * Returns the difference between a start and end timestamps in + * minutes. Differences of less than one minute are rounded up to + * one minute to avoid frequency calculations reporting infinite + * message frequencies. + * @param startTime The start timestamp in milliseconds. + * @param endTime The end timestamp in milliseconds. + * @return The difference between a start and end timestamps in minutes. + */ + protected double differenceInMinutes(long startTime, long endTime) + { + double minutes = (endTime - startTime) / 60000d; + if (minutes > 1d) + { + return minutes; + } + else + { + return 1d; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/BaseControlMBean.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/BaseControlMBean.java b/core/src/flex/management/BaseControlMBean.java new file mode 100644 index 0000000..d1c4246 --- /dev/null +++ b/core/src/flex/management/BaseControlMBean.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; + +import java.io.IOException; +import javax.management.ObjectName; + +/** + * The base MBean interface for management beans that control aspects of + * Flex behavior on the server. + */ +public interface BaseControlMBean +{ + /** + * Returns the id for this MBean. This is the value that is set for the + * <code>id</code> key in the <code>ObjectName</code> for this MBean. + * + * @return The MBean instance id. + * @throws IOException Throws IOException. + */ + String getId() throws IOException; + + /** + * Returns the type for this MBean. This is the value that is set for the + * <code>type</code> key in the <code>ObjectName</code> for this MBean. + * + * @return The MBean instance type. + * @throws IOException Throws IOException. + */ + String getType() throws IOException; + + /** + * Returns the parent for this MBean. The value is the <code>ObjectName</code> + * for the parent MBean that conceptually contains this MBean instance. If no + * parent exists, this method returns <code>null</code>. + * + * @return The <code>ObjectName</code> for the parent of this MBean instance. + * @throws IOException Throws IOException. + */ + ObjectName getParent() throws IOException; +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/MBeanLifecycleManager.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/MBeanLifecycleManager.java b/core/src/flex/management/MBeanLifecycleManager.java new file mode 100644 index 0000000..60f1f10 --- /dev/null +++ b/core/src/flex/management/MBeanLifecycleManager.java @@ -0,0 +1,63 @@ +/* + * 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; + +import flex.messaging.MessageBroker; + +import java.util.Iterator; +import java.util.Set; + +import javax.management.MBeanServer; +import javax.management.ObjectName; + +/** + * Helper class for managing MBean lifecycles externally from the core server + * components where necessary. + */ +public class MBeanLifecycleManager +{ + /** + * Unregisters all runtime MBeans that are registered in the same domain as the + * MessageBrokerControl for the target MessageBroker. + * + * @param broker The MessageBroker component that has been stopped. + */ + public static void unregisterRuntimeMBeans(MessageBroker broker) + { + MBeanServer server = MBeanServerLocatorFactory.getMBeanServerLocator().getMBeanServer(); + ObjectName brokerMBean = broker.getControl().getObjectName(); + String domain = brokerMBean.getDomain(); + try + { + ObjectName pattern = new ObjectName(domain + ":*"); + Set names = server.queryNames(pattern, null); + Iterator iter = names.iterator(); + while (iter.hasNext()) + { + ObjectName on = (ObjectName)iter.next(); + server.unregisterMBean(on); + } + } + catch (Exception e) + { + // We're generally unregistering these during shutdown (possibly JVM shutdown) + // so there's nothing to really do here because we aren't guaranteed access to + // resources like system log files, localized messaging, etc. + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/MBeanServerLocator.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/MBeanServerLocator.java b/core/src/flex/management/MBeanServerLocator.java new file mode 100644 index 0000000..2a08e29 --- /dev/null +++ b/core/src/flex/management/MBeanServerLocator.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; + +import javax.management.MBeanServer; + +/** + * Interface for classes that locate MBeanServers to register MBeans with. + */ +public interface MBeanServerLocator +{ + /** + * Returns the MBeanServer to register our management MBeans with. + * + * @return The MBeanServer to register our management MBeans with. + */ + MBeanServer getMBeanServer(); + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/MBeanServerLocatorFactory.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/MBeanServerLocatorFactory.java b/core/src/flex/management/MBeanServerLocatorFactory.java new file mode 100644 index 0000000..29eb1b3 --- /dev/null +++ b/core/src/flex/management/MBeanServerLocatorFactory.java @@ -0,0 +1,123 @@ +/* + * 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; + +import flex.messaging.log.Log; +import flex.messaging.log.LogCategories; +import flex.messaging.util.ClassUtil; + +/** + * Factory to get a <code>MBeanServerLocator</code>. + */ +public class MBeanServerLocatorFactory +{ + //-------------------------------------------------------------------------- + // + // Private Static Variables + // + //-------------------------------------------------------------------------- + + /** + * The MBeanServerLocator impl to use; lazily init'ed on first access. + */ + private static MBeanServerLocator locator; + + //-------------------------------------------------------------------------- + // + // Public Static Methods + // + //-------------------------------------------------------------------------- + + /** + * Returns a <code>MBeanServerLocator</code> that exposes the <code>MBeanServer</code> to register MBeans with. + * + * @return The <code>MBeanServerLocator</code> that exposes the <code>MBeanServer</code> to register MBeans with. + */ + public static synchronized MBeanServerLocator getMBeanServerLocator() + { + if (locator == null) + { + // Try app-server specific locators. + // WebSphere provides access to its MBeanServer via a custom admin API. + instantiateLocator("flex.management.WebSphereMBeanServerLocator", new String[] {"com.ibm.websphere.management.AdminServiceFactory"}); + + // Sun JRE 1.5 based implementation + if (locator == null) + locator = new PlatformMBeanServerLocator(); + + if (Log.isDebug()) + Log.getLogger(LogCategories.MANAGEMENT_GENERAL).debug("Using MBeanServerLocator: " + locator.getClass().getName()); + } + return locator; + } + + /** + * Release static MBeanServerLocator + * Called on MessageBroker shutdown. + */ + public static void clear() + { + locator = null; + } + + //-------------------------------------------------------------------------- + // + // Private Static Methods + // + //-------------------------------------------------------------------------- + + /** + * Helper method that attempts to load a specific MBeanServerLocator. + * + * @param locatorClassName The classname of the desired MBeanServerLocator. + * @param dependencyClassNames Any additional dependent classnames that the desired locator depends upon + * that should also be tested for availability. + */ + private static void instantiateLocator(String locatorClassName, String[] dependencyClassNames) + { + try + { + if (dependencyClassNames != null) + { + for (int i = 0; i < dependencyClassNames.length; i++) + ClassUtil.createClass(dependencyClassNames[i]); + } + + Class locatorClass = ClassUtil.createClass(locatorClassName); + locator = (MBeanServerLocator)locatorClass.newInstance(); + } + catch (Throwable t) + { + if (Log.isDebug()) + Log.getLogger(LogCategories.MANAGEMENT_MBEANSERVER).debug("Not using MBeanServerLocator: " + locatorClassName + ". Reason: " + t.getMessage()); + } + } + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Direct instantiation is not allowed. + * Use <code>getMBeanServerLocator()</code> to obtain a <code>MBeanServerLocator</code> + * instance to lookup the proper MBean server to use. + */ + private MBeanServerLocatorFactory() {} + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/Manageable.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/Manageable.java b/core/src/flex/management/Manageable.java new file mode 100644 index 0000000..be7eb4a --- /dev/null +++ b/core/src/flex/management/Manageable.java @@ -0,0 +1,53 @@ +/* + * 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; + +/** + * Manageability of a class is enabled by implementing this interface. The + * specific level of manageability is defined by the relationship between + * a manageable component and its corresponding control. + */ +public interface Manageable +{ + /** + * Returns <code>true</code> if the component is enabled for management. + * + * @return <code>true</code> if the component is enabled for management. + */ + boolean isManaged(); + + /** + * Enables or disables management for the component. + * + * @param enableManagement <code>true</code> to enable management, <code>false</code> to disable management. + */ + void setManaged(boolean enableManagement); + + /** + * Returns the control MBean used to manage the component. + * + * @return The control MBean used to manage the component. + */ + BaseControl getControl(); + + /** + * Set the control MBean used to manage the component. + * + * @param control The <code>BaseControl</code> MBean used to manage the component. + */ + void setControl(BaseControl control); +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/ManageableComponent.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/ManageableComponent.java b/core/src/flex/management/ManageableComponent.java new file mode 100644 index 0000000..02cccfc --- /dev/null +++ b/core/src/flex/management/ManageableComponent.java @@ -0,0 +1,421 @@ +/* + * 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; + +import java.util.Date; + +import flex.messaging.FlexComponent; +import flex.messaging.config.ConfigMap; +import flex.messaging.config.ConfigurationException; +import flex.messaging.log.Log; + +/** + * An abstract base class that implements the <code>Manageable</code> and <code>FlexComponent</code> interfaces. + * This is an excellent starting point for a server component that may be instantiated, initialized, started and + * stopped, as well as exposing an optional management interface via a peer MBean. + * <p>Support for changing component properties while the component is + * started should be determined on a per-property basis, and the started property is volatile to ensure consistent + * reads of the start state of the component across threads. This class performs no synchronization and is not safe for modification by multiple concurrent threads + * in the absence of external synchronization. + * </p> + */ +public abstract class ManageableComponent implements Manageable, FlexComponent +{ + //-------------------------------------------------------------------------- + // + // Protected Static Constants + // + //-------------------------------------------------------------------------- + + /** + * Error code for attempting to change a property after starting. + */ + protected static final int PROPERTY_CHANGE_AFTER_STARTUP = 11115; + + /** + * Error code to alert the user that a required component property is null. + */ + protected static final int NULL_COMPONENT_PROPERTY = 11116; + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructs a <code>ManageableComponent</code> instance, specifying + * whether to enable management. + * Enabling management will trigger the creation of a peer MBean that exposes the + * management interface for this component. + * + * @param enableManagement <code>true</code> to enable management, <code>false</code> to disable + * management. + */ + public ManageableComponent(boolean enableManagement) + { + setManaged(enableManagement); + } + + //-------------------------------------------------------------------------- + // + // Public Properties + // + //-------------------------------------------------------------------------- + + //---------------------------------- + // control + //---------------------------------- + + /** + * The peer MBean of the <code>ManageableComponent</code> that exposes a management interface. + */ + protected BaseControl control; + + /** + * (non-JavaDoc) + * @see Manageable#getControl() + */ + public BaseControl getControl() + { + return control; + } + + /** + * (non-JavaDoc) + * @see Manageable#setControl(BaseControl) + */ + public void setControl(BaseControl control) + { + this.control = control; + } + + //---------------------------------- + // id + //---------------------------------- + + /** + * The internal id value of the <code>ManageableComponent</code>. + */ + protected String id; + + /** + * Returns the id of the <code>ManageableComponent</code>. + * + * @return The id of the <code>ManageableComponent</code>. + */ + public String getId() + { + return id; + } + + /** + * Sets the id of the <code>ManageableComponent</code>. The id cannot be + * null and it cannot be changed after startup. + * + * @param id The id of the <code>ManageableComponent</code>. + */ + public void setId(String id) + { + if (isStarted()) + { + blockAssignmentWhileStarted("id"); + } + if (id == null) + { + // Id of a component cannot be null. + blockNullAssignment("id"); + } + this.id = id; + } + + //---------------------------------- + // managed + //---------------------------------- + + /** + * The internal managed flag of the <code>ManageableComponent</code>. + */ + protected volatile boolean managed; + + /** + * (non-JavaDoc) + * @see Manageable#isManaged() + */ + public boolean isManaged() + { + return managed; + } + + /** + * Enables or disables management for the component. Management cannot be + * changed once the component is started and management cannot be + * <code>true</code> if the parent of the component is not managed. + * + * @param enableManagement <code>true</code> to enable management, <code>false</code> to disable management. + */ + public void setManaged(boolean enableManagement) + { + if (isStarted() && control != null) + { + blockAssignmentWhileStarted("managed"); + } + if (enableManagement && parent != null && !parent.isManaged()) + { + if (Log.isWarn()) + { + Log.getLogger(getLogCategory()).warn("Component: '" + id + "' cannot be managed" + + " since its parent is unmanaged."); + } + return; + } + managed = enableManagement; + } + + //---------------------------------- + // parent + //---------------------------------- + + /** + * The internal reference to the parent component (if any) of the <code>ManageableComponent</code>. + */ + protected Manageable parent; + + /** + * Returns the parent of the component. + * + * @return The parent of the component. + */ + public Manageable getParent() + { + return parent; + } + + /** + * Sets the parent of the component. The parent cannot be changed + * after component startup and it cannot be null. + * + * @param parent The parent of the component. + */ + public void setParent(Manageable parent) + { + if (isStarted()) + { + blockAssignmentWhileStarted("parent"); + } + if (parent == null) + { + // Parent of a component cannot be null. + blockNullAssignment("parent"); + } + if (!parent.isManaged() && isManaged()) + { + if (Log.isWarn()) + { + Log.getLogger(getLogCategory()).warn("Component: '" + id + "' cannot be managed" + + " since its parent is unmanaged."); + } + setManaged(false); + } + this.parent = parent; + } + + //---------------------------------- + // started + //---------------------------------- + + /** + * The internal started flag of the <code>ManageableComponent</code>. + */ + protected volatile boolean started; + + /** + * Returns if the component is started or not. + * + * @return <code>true</code> if the component is started. + */ + public boolean isStarted() + { + return started; + } + + /** + * Sets if the component is started. + * + * @param started true if the component is started. + */ + protected void setStarted(boolean started) + { + if (this.started != started) + { + this.started = started; + if (started && control != null) + { + control.setStartTimestamp(new Date()); + } + } + } + + //---------------------------------- + // valid + //---------------------------------- + + /** + * The internal valid flag of the <code>ManageableComponent</code>. + */ + protected boolean valid; + + /** + * Returns if the component is valid. + * + * @return <code>true</code> if the component is valid. + */ + public boolean isValid() + { + return valid; + } + + /** + * Sets if the component is valid. + * + * @param valid true if the comoponent is valid. + */ + protected void setValid(boolean valid) + { + this.valid = valid; + } + + //---------------------------------- + // logCategory + //---------------------------------- + + /** + * Returns the log category of the component. Subclasses must provide an + * implementation that returns their desired log category. + * + * @return The log category of the component. + */ + protected abstract String getLogCategory(); + + //-------------------------------------------------------------------------- + // + // Public Methods + // + //-------------------------------------------------------------------------- + + /** + * Invoked to initialize the <code>ManageableComponent</code>. + * This base implementation calls <code>setId()</code> passing the provided + * id and ignores the properties map argument. + * Subclasses should call <code>super.initialize()</code>. + * + * @param id Id of the <code>ManageableComponent</code>. + * @param properties Properties for the <code>ManageableComponent</code>. + */ + public void initialize(String id, ConfigMap properties) + { + setId(id); + } + + /** + * Validates and starts the component. + * + * Subclasses should call <code>super.start()</code>. + */ + public void start() + { + validate(); + setStarted(true); + } + + /** + * Invalidates and stops the component. + * + * Subclasses should call <code>super.stop()</code>. + */ + public void stop() + { + invalidate(); + setStarted(false); + } + + //-------------------------------------------------------------------------- + // + // Protocted Methods + // + //-------------------------------------------------------------------------- + + /** + * Convenience method that may be used to generate and throw an Exception for an attempt to set the specified property if the + * component is started. + * + * @param propertyName The name of the property being incorrectly assigned; included in the Exception message. + */ + protected void blockAssignmentWhileStarted(String propertyName) + { + ConfigurationException ce = new ConfigurationException(); + ce.setMessage(PROPERTY_CHANGE_AFTER_STARTUP, new Object[]{propertyName}); + throw ce; + } + + /** + * Convenience method that may be used to generate and throw an Exception for an attempt to assign a null value to a property that + * requires non-null values. + * + * @param propertyName The name of the property being incorrectly assigned. + */ + protected void blockNullAssignment(String propertyName) + { + ConfigurationException ce = new ConfigurationException(); + ce.setMessage(NULL_COMPONENT_PROPERTY, new Object[]{propertyName}); + throw ce; + } + + /** + * Invoked from within the <code>stop()</code> method to invalidate the component as part of shutdown. + * This base implementation sets the valid property to false. + * Subclasses should call <code>super.invalidate()</code>. + */ + protected void invalidate() + { + setValid(false); + } + + /** + * Hook method invoked from within the <code>start()</code> method to validate that the component is in a + * startable state. + * This base implementation validates the component by ensuring it has an id and a parent and then sets + * the valid property to true. + * If the component is not in a valid, startable state an Exception is thrown. + * Subclasses should call <code>super.validate()</code>. + */ + protected void validate() + { + if (getId() == null) + { + // Id of a component cannot be null. + blockNullAssignment("id"); + } + if (getParent() == null) + { + // Parent of a component cannot be null. + blockNullAssignment("parent"); + } + setValid(true); + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/ManagementException.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/ManagementException.java b/core/src/flex/management/ManagementException.java new file mode 100644 index 0000000..593b7f2 --- /dev/null +++ b/core/src/flex/management/ManagementException.java @@ -0,0 +1,30 @@ +/* + * 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; + +import flex.messaging.MessageException; + +/** + * This exception type is thrown when errors occur generating + * <code>ObjectName</code>s for MBeans, or when registering them or + * accessing them via the MBean server. + */ +public class ManagementException extends MessageException +{ + // Inherits all functionality from MessageException. + static final long serialVersionUID = 1296149563830613956L; +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/PlatformMBeanServerLocator.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/PlatformMBeanServerLocator.java b/core/src/flex/management/PlatformMBeanServerLocator.java new file mode 100644 index 0000000..c00fe42 --- /dev/null +++ b/core/src/flex/management/PlatformMBeanServerLocator.java @@ -0,0 +1,37 @@ +/* + * 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; + +import java.lang.management.ManagementFactory; +import javax.management.MBeanServer; + +import flex.messaging.log.Log; +import flex.messaging.log.LogCategories; + +/** + * The platform implementation of an MBeanServerLocator for Java 1.5+. + * This locator exposes the platform MBeanServer. + */ +public class PlatformMBeanServerLocator implements MBeanServerLocator +{ + /** {@inheritDoc} */ + public synchronized MBeanServer getMBeanServer() + { + return ManagementFactory.getPlatformMBeanServer(); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/jmx/Attribute.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/jmx/Attribute.java b/core/src/flex/management/jmx/Attribute.java new file mode 100644 index 0000000..54fe08b --- /dev/null +++ b/core/src/flex/management/jmx/Attribute.java @@ -0,0 +1,61 @@ +/* + * 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>Attribute</code> class that complies with Flash serialization requirements. + */ +public class Attribute +{ + /** + * The name of the attribute. + */ + public String name; + + /** + * The value of the attribute. + */ + public Object value; + + /** + * Constructs an empty <code>Attribute</code> instance. + * + */ + public Attribute() + {} + + /** + * Constructs an <code>Attribute</code> instance based upon a <code>javax.management.Attribute</code> instance. + * + * @param attribute The JMX <code>Attribute</code> to base this instance on. + */ + public Attribute(javax.management.Attribute attribute) + { + name = attribute.getName(); + value = attribute.getValue(); + } + + /** + * Utility method to convert this <code>Attribute</code> instance to a <code>javax.management.Attribute</code> instance. + * + * @return A JMX <code>Attribute</code> based upon this instance. + */ + public javax.management.Attribute toAttribute() + { + return new javax.management.Attribute(name, value); + } +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/jmx/MBeanAttributeInfo.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/jmx/MBeanAttributeInfo.java b/core/src/flex/management/jmx/MBeanAttributeInfo.java new file mode 100644 index 0000000..d9c6ba4 --- /dev/null +++ b/core/src/flex/management/jmx/MBeanAttributeInfo.java @@ -0,0 +1,94 @@ +/* + * 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>MBeanAttributeInfo</code> class that complies with Flash serialization requirements. + * The <code>isIs</code> property is not named <code>is</code> because <code>is</code> is + * an ActionScript keyword. + */ +public class MBeanAttributeInfo +{ + /** + * The name of the attribute. + */ + public String name; + + /** + * The class name of the attribute. + */ + public String type; + + /** + * The description of the attribute. + */ + public String description; + + /** + * Whether the attribute can be read. + */ + public boolean readable; + + /** + * Whether the attribute can be written. + */ + public boolean writable; + + /** + * Whether the attribute has an "is" getter. + */ + public boolean isIs; + + /** + * Constructs an empty <code>MBeanAttributeInfo</code> instance. + */ + public MBeanAttributeInfo() + {} + + /** + * Constructs a <code>MBeanAttributeInfo</code> instance based upon a + * <code>javax.management.MBeanAttributeInfo</code> instance. + * + * @param mbeanAttributeInfo The JMX <code>MBeanAttributeInfo</code> instance to base this instance on. + */ + public MBeanAttributeInfo(javax.management.MBeanAttributeInfo mbeanAttributeInfo) + { + name = mbeanAttributeInfo.getName(); + type = mbeanAttributeInfo.getType(); + description = mbeanAttributeInfo.getDescription(); + readable = mbeanAttributeInfo.isReadable(); + writable = mbeanAttributeInfo.isWritable(); + isIs = mbeanAttributeInfo.isIs(); + } + + /** + * Utility method to convert this <code>MBeanAttributeInfo</code> to a + * <code>javax.management.MBeanAttributeInfo</code> instance. + * + * @return A JMX <code>MBeanAttributeInfo</code> based upon this instance. + */ + public javax.management.MBeanAttributeInfo toMBeanAttributeInfo() + { + return new javax.management.MBeanAttributeInfo(name, + type, + description, + readable, + writable, + isIs); + } + +} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/bf2e1dc9/core/src/flex/management/jmx/MBeanConstructorInfo.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/jmx/MBeanConstructorInfo.java b/core/src/flex/management/jmx/MBeanConstructorInfo.java new file mode 100644 index 0000000..95a2474 --- /dev/null +++ b/core/src/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/bf2e1dc9/core/src/flex/management/jmx/MBeanInfo.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/jmx/MBeanInfo.java b/core/src/flex/management/jmx/MBeanInfo.java new file mode 100644 index 0000000..d44e507 --- /dev/null +++ b/core/src/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/bf2e1dc9/core/src/flex/management/jmx/MBeanOperationInfo.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/jmx/MBeanOperationInfo.java b/core/src/flex/management/jmx/MBeanOperationInfo.java new file mode 100644 index 0000000..c6c6c45 --- /dev/null +++ b/core/src/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/bf2e1dc9/core/src/flex/management/jmx/MBeanParameterInfo.java ---------------------------------------------------------------------- diff --git a/core/src/flex/management/jmx/MBeanParameterInfo.java b/core/src/flex/management/jmx/MBeanParameterInfo.java new file mode 100644 index 0000000..e0fd4fe --- /dev/null +++ b/core/src/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); + } + +}
