001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }