DConfig 
SourceForge.net Logo PHP Logo

Dynamic Configuration Toolkit

Case Studies

1. User Preferences
2. Application Logic Test - Boundary / Range Test
3. Application Logic Test - Application Mode Switching
4. A Dconfig Deployment Case

1. User Preferences      

Normally, a web page is viewed by different users or users belong to different roles. Sometimes a user may want to set customized view options at run times. For example, number of table rows per page, visible table columns, etc. How to save these values? Application developer has to write code to save them to different data storage using different mechanism. This approach often results in maintainence difficulties or performance issues.

Use DConfig, it is simple and clear.

An application can use the following method to write user preference values for a particular user:

    DConfigWriter.writeInteger("config.view.page1.xxxx", "#Rows Per Page", rowsPerPage);

Where "config.view.page1.xxxx" is key, and xxxx is the user account (login id).
"#Rows Per Page" is the attribute name
rowsPerPage is the value to write.

Please see Webdemo Preferences tab for an example.

2. Application Logic Test - Boundary / Range Test      


$cat app.properties
#define monthly goal
monthlyGoal=30

public class PerformanceLogic {

  Properties appProperties = new Properties();
  appProperties.load("app.properties");
  
  public PerformanceLogic() {
  } 

  public void testPerformance() {
    float performanceValue = getperformanceValue();
    log.info("performanceValue: " + performanceValue);
    If (performanceValue >= Float.parseFloat(appProperties.getProperty("monthlyGoal"))) { // monthlyGoal is defined in static app.properties file
      log.info("enter Performance meets monthly goal logic");
      // Logic A - Performance meets monthly goal logic
    }
    else {
      log.info("enter Performance dose not meet monthly goal logic");
      // Logic B - Performance dose not meet monthly goal logic
    }
  }
}

Where performanceValue is queried from database and computed based on various factors. The value of performanceValue is difficult to change but can be obtained through log file. Since performanceValue is unchangable, the only way to test the Performance meets monthly goal logic (Logic A) or Performance dose not meet monthly goal logic (Logic B) is to change the monthlyGoal value. To test both Logic A and Logic B, we need to change monthlyGoal to an appropriate value and restart application server twice.

Using DConfig, we don't need to restart the server at all. First let's look at the code using DConfig:

public class PerformanceLogic {
  
  public PerformanceLogic() {
  } 

  public void testPerformance() {
    float performanceValue = getperformanceValue();
    log.info("performanceValue: " + performanceValue);
    If (performanceValue >= DConfigReader.getFloat("PerformanceKey", "monthlyGoal")) {
      log.info("enter Performance meets monthly goal logic");
      // Logic A - Performance meets monthly goal logic
    }
    else {
      log.info("enter Performance dose not meet monthly goal logic");
      // Logic B - Performance dose not meet monthly goal logic
    }
  }
}

In order to test Logic A, launch DConfig GUI Editor, change monthlyGoal to a value that is less than or equal to performanceValue, save the changes to database. From web link, performs a DConfig configuration data reload. Now run the testPerformance() method, Logic A code should be executed.

Similarly, we can easily test Logic B.

This process is demostrated by similar example in Web Demo.

3. Application Logic Test - Application Mode Switching      

Code snippet that does not use DConfig

String applicationMode = propertiesReader.getString("applicationMode"); // applicationMode is defined in a static properties file
If (applicationMode.equals("Develop")) {
    // perform Develop mode initialization
}
else if (applicationMode.equals("Staging")) {
    // perform Staging mode initialization    
}
else if (applicationMode.equals("QA")) {
    // perform QA mode initialization    
}
else if (applicationMode.equals("Production")) {
    // perform Production mode initialization
} else {
    // perform default initialization
}

In order to test Develop, Staging, QA, and Production initialization code, a developer / QA engineer has to set applicationMode to the desired value, and start the application server 4 times. If for some reason, the application server startup is a slow process (may need some satrtup initialization, data caching, ect.), to test the 4 initialization code will be time consuming.

Code snippet that use DConfig

#import org.moonwave.dconfig.dao.DConfigReader;

String applicationMode = DConfigReader.getString("config.application", "applicationMode");
If (applicationMode.equals("Develop")) {
    // perform Develop mode initialization
}
else if (applicationMode.equals("Staging")) {
    // perform Staging mode initialization    
}
else if (applicationMode.equals("QA")) {
    // perform QA mode initialization    
}
else if (applicationMode.equals("Production")) {
    // perform Production mode initialization
} else
    // perform default initialization
}

and use the following jsp page to load / reload DConfig configuration data:
loadCache.jsp

After application started, using DConfig GUI Editor, locate key "config.application", attribute "applicationMode", change value to "Develop". Switch to loadCache.jsp web page, click "Load DConfig Cache" link. Now "Develop mode initialization" code can be tested. Repeat the process, change attribute applicationMode value to "Staging", "QA", or "Production" one at a time to test those initialization code without the need to restart application server.

A Dconfig Deployment Case      

This diagram shows DConfig GUI Editor package, dconfig-ui-jnlp.war, is deployed to Tomcat web server while regular web application along with dconfig-lib.jar (DConfig server side library) is deployed in another web server. Deploy dconfig-ui-jnlp.war to its own Tomcat server can cut quite a mount of packaging work, reduce the complexity without losing performance. In this case, Tomcat serves as a dedicate JNLP download server.
Dconfig Deployment Case