001    /**
002     * Copyright (c) 2000-2010 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.bean.PortalBeanLocatorUtil;
018    import com.liferay.portal.kernel.management.ManageAction;
019    
020    import java.util.concurrent.atomic.AtomicReference;
021    
022    import javax.management.MBeanServer;
023    
024    /**
025     * @author Shuyang Zhou
026     */
027    public abstract class BaseJMXManageAction implements ManageAction {
028    
029            protected MBeanServer getMBeanServer() {
030                    MBeanServer mBeanServer = _mBeanServerReference.get();
031    
032                    if (mBeanServer == null) {
033                            mBeanServer = (MBeanServer)PortalBeanLocatorUtil.locate(
034                                    "mBeanServer");
035    
036                            _mBeanServerReference.compareAndSet(null, mBeanServer);
037                    }
038    
039                    return mBeanServer;
040            }
041    
042            private static AtomicReference<MBeanServer> _mBeanServerReference =
043                    new AtomicReference<MBeanServer>();
044    
045    }