001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.monitor;
029
030import org.opencms.util.CmsStringUtil;
031
032import java.util.ArrayList;
033import java.util.Collections;
034import java.util.List;
035
036/**
037 * Memory Monitor configuration class.<p>
038 *
039 * @since 6.0.0
040 */
041public class CmsMemoryMonitorConfiguration {
042
043    /** The memory monitor class name. */
044    private String m_className;
045
046    /** The interval to use for sending emails. */
047    private int m_emailInterval;
048
049    /** Receivers for status emails. */
050    private List<String> m_emailReceiver;
051
052    /** Sender for status emails. */
053    private String m_emailSender;
054
055    /** The interval to use for the logging. */
056    private int m_logInterval;
057
058    /** Memory limit that triggers a warning. */
059    private int m_maxUsagePercent;
060
061    /** The interval to use for warnings if status is disabled. */
062    private int m_warningInterval;
063
064    /**
065     * Constructor with default values.<p>
066     */
067    public CmsMemoryMonitorConfiguration() {
068
069        m_emailReceiver = new ArrayList<String>();
070    }
071
072    /**
073     * Sets the emailReceiver.<p>
074     *
075     * @param emailReceiver the emailReceiver to set
076     */
077    public void addEmailReceiver(String emailReceiver) {
078
079        m_emailReceiver.add(emailReceiver);
080    }
081
082    /**
083     * Returns the name of the memory monitor class.<p>
084     *
085     * @return the name of the memory monitor class
086     */
087    public String getClassName() {
088
089        return m_className;
090    }
091
092    /**
093     * Returns the intervalEmail.<p>
094     *
095     * @return the intervalEmail
096     */
097    public int getEmailInterval() {
098
099        return m_emailInterval;
100    }
101
102    /**
103     * Returns a List of receiver.<p>
104     *
105     * @return a List of receiver
106     */
107    public List<String> getEmailReceiver() {
108
109        Collections.sort(m_emailReceiver);
110        return m_emailReceiver;
111    }
112
113    /**
114     * Returns the emailSender.<p>
115     *
116     * @return the emailSender
117     */
118    public String getEmailSender() {
119
120        return m_emailSender;
121    }
122
123    /**
124     * Returns the intervalLog.<p>
125     *
126     * @return the intervalLog
127     */
128    public int getLogInterval() {
129
130        return m_logInterval;
131    }
132
133    /**
134     * Returns the maxUsagePercent.<p>
135     *
136     * @return the maxUsagePercent
137     */
138    public int getMaxUsagePercent() {
139
140        return m_maxUsagePercent;
141    }
142
143    /**
144     * Returns the intervalWarning.<p>
145     *
146     * @return the intervalWarning
147     */
148    public int getWarningInterval() {
149
150        return m_warningInterval;
151    }
152
153    /**
154     * Initializes the configuration with the required parameters.<p>
155     *
156     * @param className the name of the memory monitor class
157     * @param maxUsagePercent the max usage percent value
158     * @param logInterval the interval to log
159     * @param emailInterval the interval to send email
160     * @param warningInterval the interval to warn
161     */
162    public void initialize(
163        String className,
164        String maxUsagePercent,
165        String logInterval,
166        String emailInterval,
167        String warningInterval) {
168
169        m_className = className;
170        m_maxUsagePercent = Integer.parseInt(maxUsagePercent);
171        m_logInterval = Integer.parseInt(logInterval);
172        try {
173            m_emailInterval = Integer.parseInt(emailInterval);
174        } catch (NumberFormatException e) {
175            // throw exception, when email interval is not null, or not an empty/whitespace string
176            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(emailInterval)) {
177                throw new NumberFormatException();
178            }
179        }
180        m_warningInterval = Integer.parseInt(warningInterval);
181    }
182
183    /**
184     * Sets the emailSender.<p>
185     *
186     * @param emailSender the emailSender to set
187     */
188    public void setEmailSender(String emailSender) {
189
190        m_emailSender = emailSender;
191    }
192}