Skip to content

Commit

Permalink
MONDRIAN: Fix MONDRIAN-978, "Performance improvement", by statically
Browse files Browse the repository at this point in the history
    initializing MondrianProperties.instance, to save a synchronized method
    call. Contributed by Andreas Voss, but adapted because MondrianProperties
    is now generated.

[git-p4: depot-paths = "//open/mondrian/": change = 14538]
  • Loading branch information
julianhyde committed Aug 10, 2011
1 parent a2188d5 commit 3fc43c3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
25 changes: 3 additions & 22 deletions src/main/mondrian/olap/MondrianPropertiesBase.java
Expand Up @@ -61,29 +61,10 @@ public abstract class MondrianPropertiesBase extends TriggerableProperties {
private static final Logger LOGGER =
Logger.getLogger(MondrianProperties.class);

/**
* Properties, drawn from {@link System#getProperties}, plus the contents
* of "mondrian.properties" if it exists. A singleton.
*/
private static MondrianProperties instance;
private static final String mondrianDotProperties = "mondrian.properties";

/**
* Returns the singleton.
*
* @return Singleton instance
*/
public static synchronized MondrianProperties instance() {
if (instance == null) {
instance = new MondrianProperties();
instance.populate();
}
return instance;
}
protected static final String mondrianDotProperties = "mondrian.properties";

MondrianPropertiesBase() {
this.propertySource =
new FilePropertySource(new File(mondrianDotProperties));
protected MondrianPropertiesBase(PropertySource propertySource) {
this.propertySource = propertySource;
}

public boolean triggersAreEnabled() {
Expand Down
42 changes: 39 additions & 3 deletions src/main/mondrian/util/PropertyUtil.java
Expand Up @@ -37,7 +37,7 @@
*/
public class PropertyUtil {
/**
* Generates an XML file from a MondrinProperties instance.
* Generates an XML file from a MondrianProperties instance.
*
* @param args Arguments
* @throws IllegalAccessException on error
Expand Down Expand Up @@ -195,6 +195,12 @@ void doGenerate(
}
}

private static final void printLines(PrintWriter out, String[] lines) {
for (String line : lines) {
out.println(line);
}
}

enum Generator {
JAVA {
@Override
Expand All @@ -207,6 +213,7 @@ void generate(
out.println("package mondrian.olap;");
out.println();
out.println("import org.eigenbase.util.property.*;");
out.println("import java.io.File;");
out.println();

printJavadoc(
Expand All @@ -218,8 +225,37 @@ void generate(
+ "<code>mondrian.properties</code> file. Although it is possible to retrieve\n"
+ "properties using the inherited {@link java.util.Properties#getProperty(String)}\n"
+ "method, we recommend that you use methods in this class.</p>\n");
out.println(
"public class MondrianProperties extends MondrianPropertiesBase {");
String[] lines = {
"public class MondrianProperties extends MondrianPropertiesBase {",
" /**",
" * Properties, drawn from {@link System#getProperties},",
" * plus the contents of \"mondrian.properties\" if it",
" * exists. A singleton.",
" */",
" private static final MondrianProperties instance =",
" new MondrianProperties();",
"",
" private MondrianProperties() {",
" super(",
" new FilePropertySource(",
" new File(mondrianDotProperties)));",
" populate();",
" }",
"",
" /**",
" * Returns the singleton.",
" *",
" * @return Singleton instance",
" */",
" public static MondrianProperties instance() {",
" // NOTE: We used to instantiate on demand, but",
" // synchronization overhead was significant. See",
" // MONDRIAN-978.",
" return instance;",
" }",
"",
};
printLines(out, lines);
for (PropertyDef def : propertyDefinitionMap.values()) {
if (!def.core) {
continue;
Expand Down

0 comments on commit 3fc43c3

Please sign in to comment.