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 remoteUser, String requestURI,
038                    String requestURL) {
039    
040                    return _getDataSampleFactory().createPortalRequestDataSample(
041                            companyId, groupId, remoteUser, requestURI, requestURL);
042            }
043    
044            public static DataSample createPortletRequestDataSample(
045                    PortletRequestType requestType, PortletRequest portletRequest,
046                    PortletResponse portletResponse) {
047    
048                    return _getDataSampleFactory().createPortletRequestDataSample(
049                            requestType, portletRequest, portletResponse);
050            }
051    
052            public static DataSample createServiceRequestDataSample(
053                    MethodSignature methodSignature) {
054    
055                    return _getDataSampleFactory().createServiceRequestDataSample(
056                            methodSignature);
057            }
058    
059            private static DataSampleFactory _getDataSampleFactory() {
060                    return _instance._serviceTracker.getService();
061            }
062    
063            private DataSampleFactoryUtil() {
064                    Registry registry = RegistryUtil.getRegistry();
065    
066                    _serviceTracker = registry.trackServices(DataSampleFactory.class);
067    
068                    _serviceTracker.open();
069            }
070    
071            private static final DataSampleFactoryUtil _instance =
072                    new DataSampleFactoryUtil();
073    
074            private final ServiceTracker<DataSampleFactory, DataSampleFactory>
075                    _serviceTracker;
076    
077    }