001    /**
002     * Copyright (c) 2000-2012 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.dao.orm.hibernate.region;
016    
017    import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
018    import com.liferay.portal.kernel.util.BasePortalLifecycle;
019    
020    import javax.management.MBeanServer;
021    
022    import net.sf.ehcache.CacheManager;
023    import net.sf.ehcache.management.ManagementService;
024    
025    /**
026     * @author Shuyang Zhou
027     */
028    public class MBeanRegisteringPortalLifecycle extends BasePortalLifecycle {
029    
030            public MBeanRegisteringPortalLifecycle(CacheManager cacheManager) {
031                    _cacheManager = cacheManager;
032            }
033    
034            @Override
035            protected void doPortalDestroy() {
036                    _managementService.dispose();
037            }
038    
039            @Override
040            protected void doPortalInit() throws Exception {
041                    MBeanServer mBeanServer = (MBeanServer)PortalBeanLocatorUtil.locate(
042                            _MBEAN_SERVER_BEAN_NAME);
043    
044                    _managementService = new ManagementService(
045                            _cacheManager, mBeanServer, true, true, true, true);
046    
047                    _managementService.init();
048            }
049    
050            private static final String _MBEAN_SERVER_BEAN_NAME =
051                    "registryAwareMBeanServer";
052    
053            private CacheManager _cacheManager;
054            private ManagementService _managementService;
055    
056    }