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    // target size that ideally should never be exceeded
041    @XNode("targetMaxSizeMB")
042    protected int targetMaxSizeMB = -1;
043
044    // size that must never be exceeded
045    @XNode("absoluteMaxSizeMB")
046    protected int absoluteMaxSizeMB = -1;
047
048    @XNode("firstLevelTTL")
049    protected int firstLevelTTL = 60 * 2;
050
051    @XNode("secondLevelTTL")
052    protected int secondLevelTTL = 10;
053
054    @XNode("minimalRetention")
055    protected int minimalRetention = 10;
056
057    @XNode("@class")
058    protected Class<? extends TransientStore> implClass = SimpleTransientStore.class;
059
060    protected TransientStore store;
061
062    public TransientStoreConfig() {
063    }
064
065    public TransientStoreConfig(String name) {
066        this.name = name;
067    }
068
069    public String getName() {
070        return name;
071    }
072
073    public int getTargetMaxSizeMB() {
074        return targetMaxSizeMB;
075    }
076
077    public void setTargetMaxSizeMB(int targetMaxSizeMB) {
078        this.targetMaxSizeMB = targetMaxSizeMB;
079    }
080
081    public int getAbsoluteMaxSizeMB() {
082        return absoluteMaxSizeMB;
083    }
084
085    public void setAbsoluteMaxSizeMB(int absoluteMaxSizeMB) {
086        this.absoluteMaxSizeMB = absoluteMaxSizeMB;
087    }
088
089    public int getFirstLevelTTL() {
090        return firstLevelTTL;
091    }
092
093    public void setFirstLevelTTL(int firstLevelTTL) {
094        this.firstLevelTTL = firstLevelTTL;
095    }
096
097    public int getSecondLevelTTL() {
098        return secondLevelTTL;
099    }
100
101    public void setSecondLevelTTL(int secondLevelTTL) {
102        this.secondLevelTTL = secondLevelTTL;
103    }
104
105    public TransientStore getStore() {
106        if (store == null) {
107            try {
108                store = implClass.newInstance();
109                store.init(this);
110            } catch (InstantiationException | IllegalAccessException e) {
111                throw new NuxeoException(e);
112            }
113        }
114        return store;
115    }
116
117}