001/* 002 * (C) Copyright 2015 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 */ 017 018package org.nuxeo.ecm.core.transientstore.api; 019 020import org.nuxeo.common.xmap.XMap; 021import org.nuxeo.common.xmap.annotation.XNode; 022import org.nuxeo.common.xmap.annotation.XObject; 023import org.nuxeo.ecm.core.api.NuxeoException; 024import org.nuxeo.ecm.core.transientstore.SimpleTransientStore; 025 026/** 027 * {@link XMap} descriptor for representing the Configuration of a {@link TransientStore} 028 * 029 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 030 * @since 7.2 031 */ 032@XObject("store") 033public class TransientStoreConfig { 034 035 @XNode("@name") 036 protected String name; 037 038 // target size that ideally should never be exceeded 039 @XNode("targetMaxSizeMB") 040 protected int targetMaxSizeMB = -1; 041 042 // size that must never be exceeded 043 @XNode("absoluteMaxSizeMB") 044 protected int absoluteMaxSizeMB = -1; 045 046 @XNode("firstLevelTTL") 047 protected int firstLevelTTL = 60 * 2; 048 049 @XNode("secondLevelTTL") 050 protected int secondLevelTTL = 10; 051 052 @XNode("minimalRetention") 053 protected int minimalRetention = 10; 054 055 @XNode("@class") 056 protected Class<? extends TransientStore> implClass = SimpleTransientStore.class; 057 058 protected TransientStore store; 059 060 public TransientStoreConfig() { 061 } 062 063 public TransientStoreConfig(String name) { 064 this.name = name; 065 } 066 067 public String getName() { 068 return name; 069 } 070 071 public int getTargetMaxSizeMB() { 072 return targetMaxSizeMB; 073 } 074 075 public void setTargetMaxSizeMB(int targetMaxSizeMB) { 076 this.targetMaxSizeMB = targetMaxSizeMB; 077 } 078 079 public int getAbsoluteMaxSizeMB() { 080 return absoluteMaxSizeMB; 081 } 082 083 public void setAbsoluteMaxSizeMB(int absoluteMaxSizeMB) { 084 this.absoluteMaxSizeMB = absoluteMaxSizeMB; 085 } 086 087 public int getFirstLevelTTL() { 088 return firstLevelTTL; 089 } 090 091 public void setFirstLevelTTL(int firstLevelTTL) { 092 this.firstLevelTTL = firstLevelTTL; 093 } 094 095 public int getSecondLevelTTL() { 096 return secondLevelTTL; 097 } 098 099 public void setSecondLevelTTL(int secondLevelTTL) { 100 this.secondLevelTTL = secondLevelTTL; 101 } 102 103 public TransientStore getStore() { 104 if (store == null) { 105 try { 106 store = implClass.newInstance(); 107 store.init(this); 108 } catch (InstantiationException | IllegalAccessException e) { 109 throw new NuxeoException(e); 110 } 111 } 112 return store; 113 } 114 115}