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.monitoring.jmx;
016    
017    import com.liferay.portal.kernel.monitoring.Level;
018    import com.liferay.portal.kernel.monitoring.MonitoringProcessor;
019    
020    import java.util.Set;
021    
022    /**
023     * @author Michael C. Han
024     * @author Brian Wing Shun Chan
025     */
026    public class MonitoringProcessorManager
027            implements MonitoringProcessorManagerMBean {
028    
029            @Override
030            public String getLevel(String namespace) {
031                    Level level = _monitoringProcessor.getLevel(namespace);
032    
033                    if (level == null) {
034                            level = Level.OFF;
035                    }
036    
037                    return level.toString();
038            }
039    
040            @Override
041            public String[] getNamespaces() {
042                    Set<String> namespaces = _monitoringProcessor.getNamespaces();
043    
044                    return namespaces.toArray(new String[namespaces.size()]);
045            }
046    
047            @Override
048            public void setLevel(String namespace, String levelName) {
049                    Level level = Level.valueOf(levelName);
050    
051                    _monitoringProcessor.setLevel(namespace, level);
052            }
053    
054            public void setMonitoringProcessor(
055                    MonitoringProcessor monitoringProcessor) {
056    
057                    _monitoringProcessor = monitoringProcessor;
058            }
059    
060            private MonitoringProcessor _monitoringProcessor;
061    
062    }