3 Replies Latest reply on Oct 12, 2005 1:01 AM by Brian Stansberry

    Sample of replSync-service.xml done through API instead?

    Joe Reger Newbie

      Instead of using an xml file to configure my cache:

      cache = new TreeCacheAop();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache, "replSync-service.xml");

      I'd like to use the API, more like this:

      cache = new TreeCacheAop(); cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");

      There are a lot more API calls to be made than are listed above. It gets tricky when I call setclusterConfig(Element) which accepts an org.w3c.dom.Element. I started to create all of the sub-Elements and attributes, but before I did this I wanted to see if anybody had a working example of the API calls to duplicate what's in replSync-service.xml to save me some time.



        • 1. Re: Sample of replSync-service.xml done through API instead?
          Jimmy Wilson Apprentice

          I guess the question is why do you want to use the programmatic API? Are you doing something that requires dynamic cache creation on the fly? If not, I might rethink part of my approach...

          Specifically, it seems to me that for the JGroups configuration (what the setClusterConfig method pertains to), you could use a XML file packaged in a JAR, so you can pass an Element created from this file without too much effort. It should not be too hard to figure out which types of JGroups configurations you need, and you could prepackage them in this manner. Regardless of whether or not you will use dynamic caches, your JGroups settings should not be that dynamic (if they are, use an XML file that is external to the JAR).

          • 2. Re: Sample of replSync-service.xml done through API instead?
            Joe Reger Newbie


            My app is downloadable. People can install into any number of enterprise or personal environments. I bundle Tomcat, MySql drivers, etc. When you start it up there's a wizard that allows you to configure your system. In this context, even things that are generally configured statically must be dynamic... database connection parameters, cache multicast ip's, upload directories, email server locations, etc.

            I certainly agree that it's a lot easier for me to ask the user to edit an XML file, but it's easier for the user to answer a set of easy on-screen questions (with recommended default values) and have me take care of the back-end config (and validating what values they choose).

            In this case, I'll likely make the following user-configurable via a UI:
            - whether or not clustered caching is on
            - multicast ip address, if on
            - max number of objects in the cache

            So, when the API's available, I opt to give the user simple control over it instead of hard-coding what works for me today. Generally saves me a lot of re-coding down the line when that one crazy user needs something special.



            • 3. Re: Sample of replSync-service.xml done through API instead?
              Brian Stansberry Master

              If creating an XML element is too big of a pain and you just want to substitute in a couple user-defined parameters into an otherwise static JGroups configuration, you might consider using an old fashioned JGroups configuration string and passing it to TreeCache.setClusterProperties(). If you look at the code for the TreeCache.getDefaultProperties() method, you'll see the format of such a string. The TreeCache.setClusterConfig() method actually just converts the passed Element into such a string anyway.