Developing with ATG: Part IV

18 12 2007

In this edition of Developing with ATG: Part IV we discuss layered configuration. Many component models have some method for configuring a component. As you’ve seen in previous articles one can use a property file to configure a nucleus component. This isn’t unheard of as many other component models do exactly this to satisfy the configuration requirements of the model. What makes nucleus different from many other component models is the addition of configuration layering. Configuration layering is best exhibited with an example.

Say Joe developer has just developed a component that receives data from an RSS feed. This feed is accessed using a a feed URL. His component contains a property called feedURL, amongst many others, that is used to represent the URL used to access the feed.  Joe deploys this component to his configuration layer using a property file and sets the feedURL property to http://feeds.feedburner.com/MetaTheory. Joe then publishes this component so others can use it. Joes property file looks something like the following:

# /acme/MyFeed.properties
$class=acme.rss.Feed
feedURL=http://feeds.feedburner.com/MetaTheory
dataSource=/atg/dynamo/service/jdbc/JtDataSource
transactionManager=/atg/dynamo/transaction/TransactionManager
XMLToolsFactory=/atg/dynamo/service/xml/XMLToolsFactory
scheduler=/atg/dynamo/service/Scheduler
schedule=calendar * * * 22 0

Anne finds out about the component Joe just wrote and thinks it’s really cool. Anne wants to use it for her project but wants to change the URL to access a different feed instead. Now in other systems you would need to copy the entire configuration file to your project and then change only the properties that needed to be changes. But in nucleus all Anne would need to do is create a property file with the same name as Joes component in her projects configuration layer and include only the properties she needs to override. All of the other properties are inherited from Joes configuration layer. Annes property file would look like the following:

# /acme/MyFeed.properties
feedURL=https://metatheory.wordpress.com/feed

Lets take this example one step further. Say Joe revises his RSS feed component adding a new property to control the maximum number of items returned by the feed. Joe adds a property called maxItems to his RSS Feed component and updates the property file in his configuration layer setting the value to 10. Anne is unaffected by this change Joe has made as she automatically inherits the update to this component from Joes configuration layer. If later Anne wanted to change the value of maxItems she could always override the value in here configuration layer.

So how does nucleus handle this? When nucleus starts up it constructs what is referred to as the configuration path. The configuration path is similar to the class path but works in reverse order. It contains a list of directories to search for configuration information in. Directories at the end of the list override or append to configuration in the directories at the beginning of the list. The <DYNAMO_HOME>/localconfig path is usually used the final path in the list.

When nucleus configures a component it searches all the configuration paths for any property files which make up the configuration for the component. Then it combines them into a single configuration object using the override/append rule described above. This configuration object is then used to configure the component after instantiation.

Nucleus takes the idea of configuration layering beyond just properties files. XML files can be deployed to configuration layers and similar rules are used to combine these files into a single XML document. A classic example of this is used when configuring repository definitions. See the ATG documentation for information about XML combine for more information on this.

So that was a brief introduction to configuration layering.  Its used in many different ways within ATG products from configuring hostname and port numbers to enabling/disabling debug output.  In my experience nucleus is the only component model which I’ve seen that works has this feature but if you know of any others drop me a line. I would love to hear about any others.

Advertisements

Actions

Information

One response

16 12 2011
Abdul

Thanks for these articles of developing with atg. They are really good for beginners. I am new to ATG. May you Please provide the links for all parts.

part 1
part 2
part 3
part 4
.
.
.
part x

Thanking you in Anticipation,
Abdul Basit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: