001    /**
002     * Copyright (c) 2000-present 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.monitoring.statistics;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.monitoring.DataSample;
020    import com.liferay.portal.kernel.monitoring.DataSampleFactory;
021    import com.liferay.portal.kernel.monitoring.MethodSignature;
022    import com.liferay.portal.kernel.monitoring.PortletRequestType;
023    import com.liferay.registry.Registry;
024    import com.liferay.registry.RegistryUtil;
025    import com.liferay.registry.ServiceTracker;
026    
027    import javax.portlet.PortletRequest;
028    import javax.portlet.PortletResponse;
029    
030    /**
031     * @author Michael C. Han
032     */
033    @ProviderType
034    public class DataSampleFactoryUtil {
035    
036            public static DataSample createPortalRequestDataSample(
037                    long companyId, long groupId, String referer, String remoteAddr,
038                    String remoteUser, String requestURI, String requestURL,
039                    String userAgent) {
040    
041                    return _getDataSampleFactory().createPortalRequestDataSample(
042                            companyId, groupId, referer, remoteAddr, remoteUser, requestURI,
043                            requestURL, userAgent);
044            }
045    
046            public static DataSample createPortletRequestDataSample(
047                    PortletRequestType requestType, PortletRequest portletRequest,
048                    PortletResponse portletResponse) {
049    
050                    return _getDataSampleFactory().createPortletRequestDataSample(
051                            requestType, portletRequest, portletResponse);
052            }
053    
054            public static DataSample createServiceRequestDataSample(
055                    MethodSignature methodSignature) {
056    
057                    return _getDataSampleFactory().createServiceRequestDataSample(
058                            methodSignature);
059            }
060    
061            private static DataSampleFactory _getDataSampleFactory() {
062                    return _instance._serviceTracker.getService();
063            }
064    
065            private DataSampleFactoryUtil() {
066                    Registry registry = RegistryUtil.getRegistry();
067    
068                    _serviceTracker = registry.trackServices(DataSampleFactory.class);
069    
070                    _serviceTracker.open();
071            }
072    
073            private static final DataSampleFactoryUtil _instance =
074                    new DataSampleFactoryUtil();
075    
076            private final ServiceTracker<DataSampleFactory, DataSampleFactory>
077                    _serviceTracker;
078    
079    }