001package com.avaje.ebean.config; 002 003/** 004 * Defines the AutoTune behaviour for a EbeanServer. 005 */ 006public class AutoTuneConfig { 007 008 private AutoTuneMode mode = AutoTuneMode.DEFAULT_ON; 009 010 private String queryTuningFile = "ebean-autotune.xml"; 011 012 private boolean queryTuning; 013 014 private boolean queryTuningAddVersion; 015 016 private boolean profiling; 017 018 private String profilingFile = "ebean-profiling"; 019 020 private int profilingBase = 5; 021 022 private double profilingRate = 0.01; 023 024 private int profilingUpdateFrequency; 025 026 private int garbageCollectionWait = 100; 027 028 private boolean skipGarbageCollectionOnShutdown; 029 030 private boolean skipProfileReportingOnShutdown; 031 032 public AutoTuneConfig() { 033 } 034 035 /** 036 * Return the name of the file that holds the query tuning information. 037 */ 038 public String getQueryTuningFile() { 039 return queryTuningFile; 040 } 041 042 /** 043 * Set the name of the file that holds the query tuning information. 044 */ 045 public void setQueryTuningFile(String queryTuningFile) { 046 this.queryTuningFile = queryTuningFile; 047 } 048 049 /** 050 * Return the name of the file that profiling information is written to. 051 */ 052 public String getProfilingFile() { 053 return profilingFile; 054 } 055 056 /** 057 * Set the name of the file that profiling information is written to. 058 */ 059 public void setProfilingFile(String profilingFile) { 060 this.profilingFile = profilingFile; 061 } 062 063 /** 064 * Return the frequency in seconds the profiling should be collected and automatically applied to the tuning. 065 */ 066 public int getProfilingUpdateFrequency() { 067 return profilingUpdateFrequency; 068 } 069 070 /** 071 * Set the frequency in seconds the profiling should be collected and automatically applied to the tuning. 072 */ 073 public void setProfilingUpdateFrequency(int profilingUpdateFrequency) { 074 this.profilingUpdateFrequency = profilingUpdateFrequency; 075 } 076 077 /** 078 * Return the mode used when autoTune has not been explicit defined on a 079 * query. 080 */ 081 public AutoTuneMode getMode() { 082 return mode; 083 } 084 085 /** 086 * Set the mode used when autoTune has not been explicit defined on a query. 087 */ 088 public void setMode(AutoTuneMode mode) { 089 this.mode = mode; 090 } 091 092 /** 093 * Return true if the queries are being tuned. 094 */ 095 public boolean isQueryTuning() { 096 return queryTuning; 097 } 098 099 /** 100 * Set to true if the queries should be tuned by autoTune. 101 */ 102 public void setQueryTuning(boolean queryTuning) { 103 this.queryTuning = queryTuning; 104 } 105 106 /** 107 * Return true if the version property should be added when the query is 108 * tuned. 109 * <p> 110 * If this is false then the version property will be added when profiling 111 * detects that the bean is possibly going to be modified. 112 * </p> 113 */ 114 public boolean isQueryTuningAddVersion() { 115 return queryTuningAddVersion; 116 } 117 118 /** 119 * Set to true to force the version property to be always added by the query 120 * tuning. 121 * <p> 122 * If this is false then the version property will be added when profiling 123 * detects that the bean is possibly going to be modified. 124 * </p> 125 * <p> 126 * Generally this is not expected to be turned on. 127 * </p> 128 */ 129 public void setQueryTuningAddVersion(boolean queryTuningAddVersion) { 130 this.queryTuningAddVersion = queryTuningAddVersion; 131 } 132 133 /** 134 * Return true if profiling information should be collected. 135 */ 136 public boolean isProfiling() { 137 return profiling; 138 } 139 140 /** 141 * Set to true if profiling information should be collected. 142 * <p> 143 * The profiling information is collected and then used to generate the tuned 144 * queries for autoTune. 145 * </p> 146 */ 147 public void setProfiling(boolean profiling) { 148 this.profiling = profiling; 149 } 150 151 /** 152 * Return the base number of queries to profile before changing to profile 153 * only a percentage of following queries (profileRate). 154 */ 155 public int getProfilingBase() { 156 return profilingBase; 157 } 158 159 /** 160 * Set the based number of queries to profile. 161 */ 162 public void setProfilingBase(int profilingBase) { 163 this.profilingBase = profilingBase; 164 } 165 166 /** 167 * Return the rate (%) of queries to be profiled after the 'base' amount of 168 * profiling. 169 */ 170 public double getProfilingRate() { 171 return profilingRate; 172 } 173 174 /** 175 * Set the rate (%) of queries to be profiled after the 'base' amount of 176 * profiling. 177 */ 178 public void setProfilingRate(double profilingRate) { 179 this.profilingRate = profilingRate; 180 } 181 182 /** 183 * Return the time in millis to wait after a system gc to collect profiling 184 * information. 185 * <p> 186 * The profiling information is collected on object finalise. As such we 187 * generally don't want to trigger GC (let the JVM do its thing) but on 188 * shutdown the autoTune manager will trigger System.gc() and then wait 189 * (default 100 millis) to hopefully collect profiling information - 190 * especially for short run unit tests. 191 * </p> 192 */ 193 public int getGarbageCollectionWait() { 194 return garbageCollectionWait; 195 } 196 197 /** 198 * Set the time in millis to wait after a System.gc() to collect profiling information. 199 */ 200 public void setGarbageCollectionWait(int garbageCollectionWait) { 201 this.garbageCollectionWait = garbageCollectionWait; 202 } 203 204 /** 205 * Return true if triggering garbage collection should be skipped on shutdown. 206 * You might set this when System.GC() slows a application shutdown too much. 207 */ 208 public boolean isSkipGarbageCollectionOnShutdown() { 209 return skipGarbageCollectionOnShutdown; 210 } 211 212 /** 213 * Set to true if triggering garbage collection should be skipped on shutdown. 214 * You might set this when System.GC() slows a application shutdown too much. 215 */ 216 public void setSkipGarbageCollectionOnShutdown(boolean skipGarbageCollectionOnShutdown) { 217 this.skipGarbageCollectionOnShutdown = skipGarbageCollectionOnShutdown; 218 } 219 220 /** 221 * Return true if profile reporting should be skipped on shutdown. 222 */ 223 public boolean isSkipProfileReportingOnShutdown() { 224 return skipProfileReportingOnShutdown; 225 } 226 227 /** 228 * Set to true if profile reporting should be skipped on shutdown. 229 */ 230 public void setSkipProfileReportingOnShutdown(boolean skipProfileReportingOnShutdown) { 231 this.skipProfileReportingOnShutdown = skipProfileReportingOnShutdown; 232 } 233 234 /** 235 * Load the settings from the properties file. 236 */ 237 public void loadSettings(PropertiesWrapper p) { 238 239 queryTuning = p.getBoolean("autoTune.queryTuning", queryTuning); 240 queryTuningAddVersion = p.getBoolean("autoTune.queryTuningAddVersion", queryTuningAddVersion); 241 queryTuningFile = p.get("autoTune.queryTuningFile", queryTuningFile); 242 243 skipGarbageCollectionOnShutdown = p.getBoolean("autoTune.skipGarbageCollectionOnShutdown", skipGarbageCollectionOnShutdown); 244 skipProfileReportingOnShutdown = p.getBoolean("autoTune.skipProfileReportingOnShutdown", skipProfileReportingOnShutdown); 245 246 mode = p.getEnum(AutoTuneMode.class, "autoTune.mode", mode); 247 248 profiling = p.getBoolean("autoTune.profiling", profiling); 249 profilingBase = p.getInt("autoTune.profilingBase", profilingBase); 250 profilingRate = p.getDouble("autoTune.profilingRate", profilingRate); 251 profilingFile = p.get("autoTune.profilingFile", profilingFile); 252 profilingUpdateFrequency = p.getInt("autoTune.profilingUpdateFrequency", profilingUpdateFrequency); 253 } 254}