001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 * Nuxeo - initial API and implementation
018 */
019
020package org.nuxeo.ecm.core.transientstore.api;
021
022import org.nuxeo.common.xmap.XMap;
023import org.nuxeo.common.xmap.annotation.XNode;
024import org.nuxeo.common.xmap.annotation.XObject;
025import org.nuxeo.ecm.core.api.NuxeoException;
026import org.nuxeo.ecm.core.transientstore.SimpleTransientStore;
027
028/**
029 * {@link XMap} descriptor for representing the Configuration of a {@link TransientStore}
030 *
031 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
032 * @since 7.2
033 */
034@XObject("store")
035public class TransientStoreConfig {
036
037    @XNode("@name")
038    protected String name;
039
040    @XNode("@path")
041    protected String path;
042
043    // target size that ideally should never be exceeded
044    @XNode("targetMaxSizeMB")
045    protected int targetMaxSizeMB = -1;
046
047    // size that must never be exceeded
048    @XNode("absoluteMaxSizeMB")
049    protected int absoluteMaxSizeMB = -1;
050
051    @XNode("firstLevelTTL")
052    protected int firstLevelTTL = 60 * 2;
053
054    @XNode("secondLevelTTL")
055    protected int secondLevelTTL = 10;
056
057    @XNode("minimalRetention")
058    protected int minimalRetention = 10;
059
060    @XNode("@class")
061    protected Class<? extends TransientStore> implClass = SimpleTransientStore.class;
062
063    protected TransientStore store;
064
065    public TransientStoreConfig() {
066    }
067
068    public TransientStoreConfig(String name) {
069        this.name = name;
070    }
071
072    public String getName() {
073        return name;
074    }
075
076    public int getTargetMaxSizeMB() {
077        return targetMaxSizeMB;
078    }
079
080    public void setTargetMaxSizeMB(int targetMaxSizeMB) {
081        this.targetMaxSizeMB = targetMaxSizeMB;
082    }
083
084    public int getAbsoluteMaxSizeMB() {
085        return absoluteMaxSizeMB;
086    }
087
088    public void setAbsoluteMaxSizeMB(int absoluteMaxSizeMB) {
089        this.absoluteMaxSizeMB = absoluteMaxSizeMB;
090    }
091
092    public int getFirstLevelTTL() {
093        return firstLevelTTL;
094    }
095
096    public void setFirstLevelTTL(int firstLevelTTL) {
097        this.firstLevelTTL = firstLevelTTL;
098    }
099
100    public int getSecondLevelTTL() {
101        return secondLevelTTL;
102    }
103
104    public void setSecondLevelTTL(int secondLevelTTL) {
105        this.secondLevelTTL = secondLevelTTL;
106    }
107
108    public TransientStore getStore() {
109        if (store == null) {
110            try {
111                store = implClass.newInstance();
112                store.init(this);
113            } catch (InstantiationException | IllegalAccessException e) {
114                throw new NuxeoException(e);
115            }
116        }
117        return store;
118    }
119
120    /**
121     * Returns the directory where blobs will be stored.
122     *
123     * @since 9.1
124     */
125    public String getDataDir() {
126        return path;
127    }
128
129}