001    /**
002     * Copyright (c) 2000-2012 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.event.CacheManagerEventListenerRegistry;
024    import net.sf.ehcache.management.ManagementService;
025    
026    /**
027     * @author Shuyang Zhou
028     */
029    public class MBeanRegisteringPortalLifecycle extends BasePortalLifecycle {
030    
031            public MBeanRegisteringPortalLifecycle(CacheManager cacheManager) {
032                    _cacheManager = cacheManager;
033            }
034    
035            @Override
036            protected void doPortalDestroy() {
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                    CacheManagerEventListenerRegistry cacheManagerEventListenerRegistry =
050                            _cacheManager.getCacheManagerEventListenerRegistry();
051    
052                    cacheManagerEventListenerRegistry.unregisterListener(
053                            _managementService);
054            }
055    
056            private static final String _MBEAN_SERVER_BEAN_NAME =
057                    "registryAwareMBeanServer";
058    
059            private CacheManager _cacheManager;
060            private ManagementService _managementService;
061    
062    }