001/* 002 * (C) Copyright 2015-2017 Nuxeo (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 * Tiry 018 */ 019package org.nuxeo.ecm.core.transientstore.api; 020 021import java.util.HashMap; 022import java.util.Map; 023 024import org.nuxeo.common.xmap.XMap; 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XNodeMap; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.ecm.core.api.NuxeoException; 029import org.nuxeo.ecm.core.transientstore.SimpleTransientStore; 030 031/** 032 * {@link XMap} descriptor for representing the Configuration of a {@link TransientStore} 033 * 034 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 035 * @since 7.2 036 */ 037@XObject("store") 038public class TransientStoreConfig { 039 040 @XNode("@name") 041 protected String name; 042 043 @XNode("@path") 044 protected String path; 045 046 // target size that ideally should never be exceeded 047 @XNode("targetMaxSizeMB") 048 protected int targetMaxSizeMB = -1; 049 050 // size that must never be exceeded 051 @XNode("absoluteMaxSizeMB") 052 protected int absoluteMaxSizeMB = -1; 053 054 @XNode("firstLevelTTL") 055 protected int firstLevelTTL = 60 * 2; 056 057 @XNode("secondLevelTTL") 058 protected int secondLevelTTL = 10; 059 060 @XNode("minimalRetention") 061 protected int minimalRetention = 10; 062 063 @XNode("@class") 064 protected Class<? extends TransientStoreProvider> implClass = SimpleTransientStore.class; 065 066 protected TransientStoreProvider store; 067 068 @XNodeMap(value = "property", key = "@name", type = HashMap.class, componentType = String.class, nullByDefault = true) 069 protected Map<String, String> properties; 070 071 public TransientStoreConfig() { 072 } 073 074 public TransientStoreConfig(String name) { 075 this.name = name; 076 } 077 078 public String getName() { 079 return name; 080 } 081 082 public int getTargetMaxSizeMB() { 083 return targetMaxSizeMB; 084 } 085 086 public void setTargetMaxSizeMB(int targetMaxSizeMB) { 087 this.targetMaxSizeMB = targetMaxSizeMB; 088 } 089 090 public int getAbsoluteMaxSizeMB() { 091 return absoluteMaxSizeMB; 092 } 093 094 public void setAbsoluteMaxSizeMB(int absoluteMaxSizeMB) { 095 this.absoluteMaxSizeMB = absoluteMaxSizeMB; 096 } 097 098 public int getFirstLevelTTL() { 099 return firstLevelTTL; 100 } 101 102 public void setFirstLevelTTL(int firstLevelTTL) { 103 this.firstLevelTTL = firstLevelTTL; 104 } 105 106 public int getSecondLevelTTL() { 107 return secondLevelTTL; 108 } 109 110 public void setSecondLevelTTL(int secondLevelTTL) { 111 this.secondLevelTTL = secondLevelTTL; 112 } 113 114 public TransientStoreProvider getStore() { 115 if (store == null) { 116 try { 117 store = implClass.newInstance(); 118 store.init(this); 119 } catch (InstantiationException | IllegalAccessException e) { 120 throw new NuxeoException(e); 121 } 122 } 123 return store; 124 } 125 126 /** 127 * Flush the cached store if any 128 * 129 * @since 9.2 130 */ 131 public void flush() { 132 store = null; 133 } 134 135 /** 136 * Returns the directory where blobs will be stored. 137 * 138 * @since 9.1 139 */ 140 public String getDataDir() { 141 return path; 142 } 143 144 /** 145 * Returns properties. 146 * 147 * @since 10.1 148 */ 149 public Map<String, String> getProperties() { 150 return properties; 151 } 152 153}