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.db;
029
030/**
031 * The settings of the OpenCms memory monitor.<p>
032 *
033 * @since 6.0.0
034 */
035public class CmsCacheSettings {
036
037    /** The size of the memory monitor's cache for ACLs. */
038    private int m_aclCacheSize;
039
040    /** The name of the class to generate cache keys. */
041    private String m_cacheKeyGenerator;
042
043    /** The size of the memory monitor's cache for groups. */
044    private int m_groupCacheSize;
045
046    /** The size of the memory monitor's cache for organizational units. */
047    private int m_orgUnitCacheSize = -1; // this configuration entry is optional
048
049    /** The size of the memory monitor's cache for permission checks. */
050    private int m_permissionCacheSize;
051
052    /** The size of the memory monitor's cache for projects. */
053    private int m_projectCacheSize;
054
055    /** The size of the memory monitor's cache for project resources. */
056    private int m_projectResourcesCacheSize = -1; // this configuration entry is optional
057
058    /** The size of the memory monitor's cache for properties. */
059    private int m_propertyCacheSize;
060
061    /** The size of the memory monitor's cache for property lists. */
062    private int m_propertyListsCacheSize = -1; // this configuration entry is optional
063
064    /** The size of the memory monitor's cache for resources. */
065    private int m_resourceCacheSize;
066
067    /** The size of the memory monitor's cache for lists of resources. */
068    private int m_resourcelistCacheSize;
069
070    /** The size of the memory monitor's cache for roles. */
071    private int m_rolesCacheSize = -1; // this configuration entry is optional
072
073    /** The size of the memory monitor's cache for users. */
074    private int m_userCacheSize;
075
076    /** The size of the memory monitor's cache for user/group relations. */
077    private int m_userGroupsCacheSize;
078
079    /**
080     * Default constructor.<p>
081     */
082    public CmsCacheSettings() {
083
084        super();
085    }
086
087    /**
088     * Returns the size of the memory monitor's cache for ACLs.<p>
089     *
090     * @return the size of the memory monitor's cache for ACLs
091     */
092    public int getAclCacheSize() {
093
094        return m_aclCacheSize;
095    }
096
097    /**
098     * Returns the name of the class to generate cache keys.<p>
099     *
100     * @return the name of the class to generate cache keys
101     */
102    public String getCacheKeyGenerator() {
103
104        return m_cacheKeyGenerator;
105    }
106
107    /**
108     * Returns the size of the memory monitor's cache for organizational units.<p>
109     *
110     * Might be <code>-1</code> if configuration entry is missing.<p>
111     *
112     * @return the size of the memory monitor's cache for organizational units
113     */
114    public int getConfiguredOrgUnitCacheSize() {
115
116        return m_orgUnitCacheSize;
117    }
118
119    /**
120     * Returns the size of the memory monitor's cache for project resources.<p>
121     *
122     * Might be <code>-1</code> if configuration entry is missing.<p>
123     *
124     * @return the size of the memory monitor's cache for project resources
125     */
126    public int getConfiguredProjectResourcesCacheSize() {
127
128        return m_projectResourcesCacheSize;
129    }
130
131    /**
132     * Returns the size of the memory monitor's cache for property lists.<p>
133     *
134     * Might be <code>-1</code> if configuration entry is missing.<p>
135     *
136     * @return the size of the memory monitor's cache for property lists
137     */
138    public int getConfiguredPropertyListsCacheSize() {
139
140        return m_propertyListsCacheSize;
141    }
142
143    /**
144     * Returns the size of the memory monitor's cache for roles.<p>
145     *
146     * Might be <code>-1</code> if configuration entry is missing.<p>
147     *
148     * @return the size of the memory monitor's cache for roles
149     */
150    public int getConfiguredRolesCacheSize() {
151
152        return m_rolesCacheSize;
153    }
154
155    /**
156     * Returns the size of the memory monitor's cache for groups.<p>
157     *
158     * @return the size of the memory monitor's cache for groups
159     */
160    public int getGroupCacheSize() {
161
162        return m_groupCacheSize;
163    }
164
165    /**
166     * Returns the size of the memory monitor's cache for organizational units.<p>
167     *
168     * @return the size of the memory monitor's cache for organizational units
169     */
170    public int getOrgUnitCacheSize() {
171
172        if (m_orgUnitCacheSize < 0) {
173            return getGroupCacheSize();
174        }
175        return m_orgUnitCacheSize;
176    }
177
178    /**
179     * Returns the size of the memory monitor's cache for permission checks.<p>
180     *
181     * @return the size of the memory monitor's cache for permission checks
182     */
183    public int getPermissionCacheSize() {
184
185        return m_permissionCacheSize;
186    }
187
188    /**
189     * Returns the size of the memory monitor's cache for projects.<p>
190     *
191     * @return the size of the memory monitor's cache for projects
192     */
193    public int getProjectCacheSize() {
194
195        return m_projectCacheSize;
196    }
197
198    /**
199     * Returns the size of the memory monitor's cache for project resources.<p>
200     *
201     * @return the size of the memory monitor's cache for project resources
202     */
203    public int getProjectResourcesCacheSize() {
204
205        if (m_propertyListsCacheSize < 0) {
206            return getProjectCacheSize();
207        }
208        return m_projectResourcesCacheSize;
209    }
210
211    /**
212     * Returns the size of the memory monitor's cache for properties.<p>
213     *
214     * @return the size of the memory monitor's cache for properties
215     */
216    public int getPropertyCacheSize() {
217
218        return m_propertyCacheSize;
219    }
220
221    /**
222     * Returns the size of the memory monitor's cache for property lists.<p>
223     *
224     * @return the size of the memory monitor's cache for property lists
225     */
226    public int getPropertyListsCacheSize() {
227
228        if (m_propertyListsCacheSize < 0) {
229            return getPropertyCacheSize();
230        }
231        return m_propertyListsCacheSize;
232    }
233
234    /**
235     * Returns the size of the memory monitor's cache for resources.<p>
236     *
237     * @return the size of the memory monitor's cache for resources
238     */
239    public int getResourceCacheSize() {
240
241        return m_resourceCacheSize;
242    }
243
244    /**
245     * Returns the size of the memory monitor's cache for lists of resources.<p>
246     *
247     * @return the size of the memory monitor's cache for lists of resources
248     */
249    public int getResourcelistCacheSize() {
250
251        return m_resourcelistCacheSize;
252    }
253
254    /**
255     * Returns the size of the memory monitor's cache for roles.<p>
256     *
257     * @return the size of the memory monitor's cache for roles
258     */
259    public int getRolesCacheSize() {
260
261        if (m_rolesCacheSize < 0) {
262            return getPermissionCacheSize();
263        }
264        return m_rolesCacheSize;
265    }
266
267    /**
268     * Returns the size of the memory monitor's cache for users.<p>
269     *
270     * @return the size of the memory monitor's cache for users
271     */
272    public int getUserCacheSize() {
273
274        return m_userCacheSize;
275    }
276
277    /**
278     * Returns the size of the memory monitor's cache for user/group relations.<p>
279     *
280     * @return the size of the memory monitor's cache for user/group relations
281     */
282    public int getUserGroupsCacheSize() {
283
284        return m_userGroupsCacheSize;
285    }
286
287    /**
288     * Sets the size of the memory monitor's cache for ACLs.<p>
289     *
290     * @param size the size of the memory monitor's cache for ACLs
291     */
292    public void setAclCacheSize(String size) {
293
294        m_aclCacheSize = getIntValue(size, 1024);
295    }
296
297    /**
298     * Sets the name of the class to generate cache keys.<p>
299     *
300     * @param classname the name of the class to generate cache keys
301     */
302    public void setCacheKeyGenerator(String classname) {
303
304        m_cacheKeyGenerator = classname;
305    }
306
307    /**
308     * Sets the size of the memory monitor's cache for groups.<p>
309     *
310     * @param size the size of the memory monitor's cache for groups
311     */
312    public void setGroupCacheSize(String size) {
313
314        m_groupCacheSize = getIntValue(size, 64);
315    }
316
317    /**
318     * Sets the size of the memory monitor's cache for organizational units.<p>
319     *
320     * @param size the size of the memory monitor's cache for organizational units
321     */
322    public void setOrgUnitCacheSize(String size) {
323
324        m_orgUnitCacheSize = getIntValue(size, 64);
325    }
326
327    /**
328     * Sets the size of the memory monitor's cache for permission checks.<p>
329     *
330     * @param size the size of the memory monitor's cache for permission checks
331     */
332    public void setPermissionCacheSize(String size) {
333
334        m_permissionCacheSize = getIntValue(size, 1024);
335    }
336
337    /**
338     * Sets the size of the memory monitor's cache for projects.<p>
339     *
340     * @param size the size of the memory monitor's cache for projects
341     */
342    public void setProjectCacheSize(String size) {
343
344        m_projectCacheSize = getIntValue(size, 32);
345    }
346
347    /**
348     * Sets the size of the memory monitor's cache for project resources.<p>
349     *
350     * @param size the size of the memory monitor's cache for project resources
351     */
352    public void setProjectResourcesCacheSize(String size) {
353
354        m_projectResourcesCacheSize = getIntValue(size, -1);
355    }
356
357    /**
358     * Sets the size of the memory monitor's cache for properties.<p>
359     *
360     * @param size the size of the memory monitor's cache for properties
361     */
362    public void setPropertyCacheSize(String size) {
363
364        m_propertyCacheSize = getIntValue(size, 128);
365    }
366
367    /**
368     * Sets the size of the memory monitor's cache for property lists.<p>
369     *
370     * @param size the size of the memory monitor's cache for property lists
371     */
372    public void setPropertyListsCacheSize(String size) {
373
374        m_propertyListsCacheSize = getIntValue(size, -1);
375    }
376
377    /**
378     * Sets the size of the memory monitor's cache for resources.<p>
379     *
380     * @param size the size of the memory monitor's cache for resources
381     */
382    public void setResourceCacheSize(String size) {
383
384        m_resourceCacheSize = getIntValue(size, 8192);
385    }
386
387    /**
388     * Sets the size of the memory monitor's cache for lists of resources.<p>
389     *
390     * @param size the size of the memory monitor's cache for lists of resources
391     */
392    public void setResourcelistCacheSize(String size) {
393
394        m_resourcelistCacheSize = getIntValue(size, 256);
395    }
396
397    /**
398     * Sets the size of the memory monitor's cache for roles.<p>
399     *
400     * @param size the size of the memory monitor's cache for roles
401     */
402    public void setRolesCacheSize(String size) {
403
404        m_rolesCacheSize = getIntValue(size, 8192);
405    }
406
407    /**
408     * Sets the size of the memory monitor's cache for users.<p>
409     *
410     * @param size the size of the memory monitor's cache for users
411     */
412    public void setUserCacheSize(String size) {
413
414        m_userCacheSize = getIntValue(size, 64);
415    }
416
417    /**
418     * Sets the size of the memory monitor's cache for user/group relations.<p>
419     *
420     * @param size the size of the memory monitor's cache for user/group relations
421     */
422    public void setUserGroupsCacheSize(String size) {
423
424        m_userGroupsCacheSize = getIntValue(size, 256);
425    }
426
427    /**
428     * Turns a string into an int.<p>
429     *
430     * @param str the string to be converted
431     * @param defaultValue a default value to be returned in case the string could not be parsed or the parsed int value is <= 0
432     * @return the int value of the string
433     */
434    private int getIntValue(String str, int defaultValue) {
435
436        try {
437            int intValue = Integer.parseInt(str);
438            return (intValue > 0) ? intValue : defaultValue;
439        } catch (NumberFormatException e) {
440            // intentionally left blank
441        }
442        return defaultValue;
443    }
444}