Stomp

Managing runtime prefs

 

Stomp uses a runtime.prefs file as it’s primary means of configuration.  You’ll see references to this file in many of the docs covering Stomp configuration.

 

It’s fine if you just want to use this file for Stomp specific configuration.  If you choose though, the stomp.util.Prefs utility is a handy and easy way to break out ugly hard-coded variables from your source code.

 

Using Prefs in your source code.  It’s a pretty easy concept.  Rather than hard-coding, say, the URL of the file you are going to download, you just choose a name for this variable and put the String in Prefs.  So, instead of this:

 

            URL url = new URL (“http://jstomp.sourceforge.net/index.html”);

 

you’ll write this:

 

            URL url = new URL (Prefs.singleton ().getPrefString (“myApp.url”));

 

Bam.  Now you can change the behavior of this line of code without recompiling your source code.  You can even change the value on-the-fly at runtime, should the urge strike you.  Prefs has support for Booleans, Class objects, arrays of Strings, etc.  Check out the javadoc for the full Prefs API.

 

Editing the runtime.prefs file.  Adding elements to runtime.prefs is a snap.  Just choose a “.” delimited name for your pref, then add an XML hierarchy for that String… easier done than said.  In the example above, adding a pref for “myApp.url” would look like this:

 

            <prefs>

                        <myApp>

                                    <url>

                                                http://jstomp.sourceforge.net/index.html

                                    </url>

                        </myApp>

            </prefs>

 

to add an array of Strings as a pref, just add multiple “tags” below the final node in your hierarchy.  For example, if you wanted myApp.url to represent an array of URL strings, your runtime.prefs would look like this:

 

            <prefs>

                        <myApp>

                                    <url>

                                                <value>http://jstomp.sourceforge.net/index.html</value>

                                                <value>http://jstomp.sourceforge.net/configure.html</value>

                                                <value>http://my.yahoo.com</value>

                                    </url>

                        </myApp>

            </prefs>

 

 

So… using Prefs is easy, and it makes configuring your application trivial.  There are several utilities in the stomp.util package like this which you may be able to take advantage.  They were written to support Stomp development, but provide functionality that any project may need.  Check out:

 

-        Log: a simple channel-based logger.

-        Bench: a quick way to Benchmark blocks of code for performance tuning

-        AbstractFactory: critical to making 3rd party libraries which are open to extension, closed to modification.  This class lets clients plug-in object implementations which did not exist when the library was released.

 

Etc.  Enjoy.