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 garbageCollectionWait = 100;
025  
026  private boolean skipCollectionOnShutdown;
027
028  public AutoTuneConfig() {
029  }
030
031  /**
032   * Return the name of the file that holds the query tuning information.
033   */
034  public String getQueryTuningFile() {
035    return queryTuningFile;
036  }
037
038  /**
039   * Set the name of the file that holds the query tuning information.
040   */
041  public void setQueryTuningFile(String queryTuningFile) {
042    this.queryTuningFile = queryTuningFile;
043  }
044
045  /**
046   * Return the name of the file that profiling information is written to.
047   */
048  public String getProfilingFile() {
049    return profilingFile;
050  }
051
052  /**
053   * Set the name of the file that profiling information is written to.
054   */
055  public void setProfilingFile(String profilingFile) {
056    this.profilingFile = profilingFile;
057  }
058
059  /**
060   * Return the mode used when autoTune has not been explicit defined on a
061   * query.
062   */
063  public AutoTuneMode getMode() {
064    return mode;
065  }
066
067  /**
068   * Set the mode used when autoTune has not been explicit defined on a query.
069   */
070  public void setMode(AutoTuneMode mode) {
071    this.mode = mode;
072  }
073
074  /**
075   * Return true if the queries are being tuned.
076   */
077  public boolean isQueryTuning() {
078    return queryTuning;
079  }
080
081  /**
082   * Set to true if the queries should be tuned by autoTune.
083   */
084  public void setQueryTuning(boolean queryTuning) {
085    this.queryTuning = queryTuning;
086  }
087
088  /**
089   * Return true if the version property should be added when the query is
090   * tuned.
091   * <p>
092   * If this is false then the version property will be added when profiling
093   * detects that the bean is possibly going to be modified.
094   * </p>
095   */
096  public boolean isQueryTuningAddVersion() {
097    return queryTuningAddVersion;
098  }
099
100  /**
101   * Set to true to force the version property to be always added by the query
102   * tuning.
103   * <p>
104   * If this is false then the version property will be added when profiling
105   * detects that the bean is possibly going to be modified.
106   * </p>
107   * <p>
108   * Generally this is not expected to be turned on.
109   * </p>
110   */
111  public void setQueryTuningAddVersion(boolean queryTuningAddVersion) {
112    this.queryTuningAddVersion = queryTuningAddVersion;
113  }
114
115  /**
116   * Return true if profiling information should be collected.
117   */
118  public boolean isProfiling() {
119    return profiling;
120  }
121
122  /**
123   * Set to true if profiling information should be collected.
124   * <p>
125   * The profiling information is collected and then used to generate the tuned
126   * queries for autoTune.
127   * </p>
128   */
129  public void setProfiling(boolean profiling) {
130    this.profiling = profiling;
131  }
132
133  /**
134   * Return the base number of queries to profile before changing to profile
135   * only a percentage of following queries (profileRate).
136   */
137  public int getProfilingBase() {
138    return profilingBase;
139  }
140
141  /**
142   * Set the based number of queries to profile.
143   */
144  public void setProfilingBase(int profilingBase) {
145    this.profilingBase = profilingBase;
146  }
147
148  /**
149   * Return the rate (%) of queries to be profiled after the 'base' amount of
150   * profiling.
151   */
152  public double getProfilingRate() {
153    return profilingRate;
154  }
155
156  /**
157   * Set the rate (%) of queries to be profiled after the 'base' amount of
158   * profiling.
159   */
160  public void setProfilingRate(double profilingRate) {
161    this.profilingRate = profilingRate;
162  }
163
164  /**
165   * Return the time in millis to wait after a system gc to collect profiling
166   * information.
167   * <p>
168   * The profiling information is collected on object finalise. As such we
169   * generally don't want to trigger GC (let the JVM do its thing) but on
170   * shutdown the autoTune manager will trigger System.gc() and then wait
171   * (default 100 millis) to hopefully collect profiling information -
172   * especially for short run unit tests.
173   * </p>
174   */
175  public int getGarbageCollectionWait() {
176    return garbageCollectionWait;
177  }
178
179  /**
180   * Set the time in millis to wait after a System.gc() to collect profiling information.
181   */
182  public void setGarbageCollectionWait(int garbageCollectionWait) {
183    this.garbageCollectionWait = garbageCollectionWait;
184  }
185
186  /**
187   * Return true if profiling collection should be skipped on shutdown.
188   */
189  public boolean isSkipCollectionOnShutdown() {
190    return skipCollectionOnShutdown;
191  }
192
193  /**
194   * Set to true if profiling collection should be skipped on shutdown.
195   */
196  public void setSkipCollectionOnShutdown(boolean skipCollectionOnShutdown) {
197    this.skipCollectionOnShutdown = skipCollectionOnShutdown;
198  }
199
200  /**
201   * Load the settings from the properties file.
202   */
203  public void loadSettings(PropertiesWrapper p) {
204
205    queryTuning = p.getBoolean("autoTune.queryTuning", queryTuning);
206    queryTuningAddVersion = p.getBoolean("autoTune.queryTuningAddVersion", queryTuningAddVersion);
207    queryTuningFile = p.get("autoTune.queryTuningFile", queryTuningFile);
208
209    skipCollectionOnShutdown = p.getBoolean("autoTune.skipCollectionOnShutdown", skipCollectionOnShutdown);
210    
211    mode = p.getEnum(AutoTuneMode.class, "autoTune.mode", mode);
212
213    profiling = p.getBoolean("autoTune.profiling", profiling);
214    profilingBase = p.getInt("autoTune.profilingBase", profilingBase);
215    profilingRate = p.getDouble("autoTune.profilingRate", profilingRate);
216    profilingFile = p.get("autoTune.profilingFile", profilingFile);
217  }
218}