001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.management.jmx;
016    
017    import com.liferay.portal.kernel.jmx.model.MBean;
018    import com.liferay.portal.kernel.management.ManageActionException;
019    
020    import java.util.HashSet;
021    import java.util.Set;
022    
023    import javax.management.MBeanServer;
024    import javax.management.MalformedObjectNameException;
025    import javax.management.ObjectName;
026    
027    /**
028     * @author Shuyang Zhou
029     */
030    public class ListMBeansAction extends BaseJMXManageAction<Set<MBean>> {
031    
032            public ListMBeansAction(String domainName) {
033                    _domainName = domainName;
034            }
035    
036            @Override
037            public Set<MBean> action() throws ManageActionException {
038                    try {
039                            MBeanServer mBeanServer = getMBeanServer();
040    
041                            Set<ObjectName> objectNames = mBeanServer.queryNames(
042                                    null, new ObjectName(_domainName.concat(":*")));
043    
044                            Set<MBean> mBeans = new HashSet<MBean>(objectNames.size());
045    
046                            for (ObjectName objectName : objectNames) {
047                                    mBeans.add(new MBean(objectName));
048                            }
049    
050                            return mBeans;
051                    }
052                    catch (MalformedObjectNameException mone) {
053                            throw new ManageActionException(mone);
054                    }
055            }
056    
057            private String _domainName;
058    
059    }