Friday, April 29, 2011

Create custom Registry for Performance\Store configuration

Creating registry is a great alternate solution for things you can not cache using dynacache. Another purpose would be to store configuration data for store. If you use registry, you don't need a server restart and org admin console provides a nice interface to refresh registry. You can load the registry on server start and connect a table to the registry and if you need to add stuff dynamically, you would need a registry refresh from admin console.

Add the Registry entry into wc-server.xml

<registry
name="CustomConfigRegistry" regClassName="com.vendor.registry.CustomConfigRegistry"/>


public class CustomConfigRegistry implements Registry {
private static final String CLASSNAME = "CustomConfigRegistry";
private static CustomConfigRegistry singleton = new CustomConfigRegistry();
private Timestamp lastRefreshTimeStamp = null;
private final int INITIAL_CACHE_SIZE = 20000;

private Hashtable configCache = null;

public CustomConfigRegistry () {}

public void initialize() throws Exception {
singleton = this;
configCache = new Hashtable(INIT_CACHE_SIZE);
}


public static CustomConfigRegistry getInstance() {
return singleton;
}


public boolean enabled() {
return (singleton != null && configCache != null);
}

public void refresh() throws Exception {
if (getCacheSize() > 0) {
System.out.println(" [CustomConfigRegistry] cache size = " + getCacheSize());
}
configCache = new Hashtable(INIT_CACHE_SIZE);
lastRefreshTimeStamp = new Timestamp(System.currentTimeMillis());
PerformLogic();
}

public int getCacheSize() {
if (enabled()) {
return configCache.size();
} else {
return -1;
}
}

public void performLogic(){
}
}

Login to Admin Console->Registry->check the CustomConfigRegistry registry and update.
or
Directly refresh
http://myhostname/webapp/wcs/stores/servlet/RefreshRegistry?URL=/webapp/wcs/Admin/homepg&registryName=CustomConfigRegistry

1 comment:

  1. Wcs has concept of session bean and registry manager, which one is useful to load static table data.
    Can ejb session bean hit data base while accessing the bean. what is the maximum size can be define for registry.

    We have static table data which access using access bean, is it ok to move that to custom registry.

    ReplyDelete