Home > Articles > Programming > Java

📄 Contents

  1. Introduction
  2. Properties Basics
  3. Designing a Component Configuration Interface (CCI)
  4. Where Are We?
  5. Resources
Like this article? We recommend

Designing a Component Configuration Interface (CCI)

When people think about code reuse, they typically picture making method or function calls into a reusable library. Such a library presents an application programming interface (API) to its clients. Java provides great feature support for creating reusable APIs: interfaces, inheritance, encapsulation, dynamic proxies, reflection, JavaBeans, and so on.

However, reconfiguring an application is also a form of reuse. When you modify a component's behavior by changing a configuration setting, you're using a component configuration interface (CCI). A CCI is not a Java interface, in the sense of the interface keyword. But it is an interface nonetheless, in that it specifies a contract between a component and a user of that component.

The CCI concept is not prominent in the Java documentation, which is a bit odd since this kind of reuse is more common than API-level reuse. To prove this to yourself, simply compare the reach of APIs and CCIs, as shown in Table 1.

Table 1 APIs Versus CCIs as Reuse Mechanisms

 

APIs

CCIs

Who?

developers

developers, admins, end users

When?

development cycle

any time

Where?

development machine

deployment machine


On every axis, configuration reaches a broader audience. So one might hope that Java would have terrific support for creating reusable CCIs, just as it does for creating APIs. Such support is indeed present, but it's fragmented and not standardized.

Application programming interfaces (APIs) are described in some language, such as Java. Similarly, component configuration interfaces (CCIs) deserve their own configuration "language." Designing such a language has much in common with designing a programming language. You need the following elements:

  • Structure. Producers and consumers of configuration information must agree on some structure for passing that information, and possibly a type system that allows structures to be validated for particular uses.

  • Lookup. There must be some way to locate the configuration information when it's needed.

  • Scope. Configuration information must bind to some specific slice of code and data. This slice could be some combination of server farm(s), machine(s), process(es), thread(s), object(s), or something more esoteric.

  • Metadata. Configuration information should expose metadata in a standard format. Tools can then process this metadata and tell users how the configuration information can be used.

At this point these elements may seem fairly abstract, so to illustrate them I'll show how they're realized in three different Java CCIs: JNDI configuration, security policy configuration, and Remote Method Invocation (RMI) configuration. As a control group, I'll also discuss how the Java API matches up against these elements. The conclusions are summarized in Table 2.

Table 2 CCI Comparison

 

Java Platform

JNDI CCI

Security CCI

RMI CCI

Structure

Java language

properties file

custom format

properties file

Lookup

classpath, custom loaders

ad hoc rules

ad hoc rules

system props only

Scope

static, instance, class loader, others

poorly specified

poorly specified

poorly specified

Metadata

binary class format, reflection

none

none

none


As the table suggests, the Java platform has a rich and flexible implementation of structure, lookup, scope, and metadata. Unfortunately, the CCIs are not similarly well-equipped. Because there are no complete standards for CCIs, each subsystem must define its own CCI contract. All the contracts are different, which imposes an unnecessary learning curve on developers.

Structure

Whereas the Java language has a rich type system, CCIs often eschew this in favor of simpler, text-based formats. For example, the reference implementation of security policy is configured using a policy file. The policy file defines its own custom serialized format, with entries that look like this:

grant codeBase "file:${java.home}/lib/ext/*" {
 permission java.security.AllPermission;
};

Using this custom format is an unnecessary burden for everyone. It necessitates having a special parser built into the standard library, plus custom tools such as policytool. (Of course, the obvious solution for complex data such as security policy entries is XML. More on this in Part 2.)

What about simple configuration scenarios that require nothing more complex than name-value pairs? Surely properties are suitable for this situation. JNDI, RMI, and Security all expose at least part of their CCI through properties. However, reality has a way of being more complex then designers originally hoped. JNDI, RMI, and Security all have configuration properties that are not simple name-value pairs. In particular, they all need the ability to express multi-valued entries. JNDI places multiple values on one line in a property file, using the colon (:) character as a delimiter:

java.naming.factory.object= \
     com.sun.jndi.ldap.AttrsToCorba:com.wiz.from.Person

The RMI CCI uses the space character as a delimiter:

java.rmi.server.codebase= \
    http://myserver.com/classes http://yourserver.com/classes

The Security CCI does it yet another way, using multiple keys that differ only by a numerical value after the last dot:

# List of providers and their preference orders (see above):
#
security.provider.1=sun.security.provider.Sun
security.provider.2=com.sun.net.ssl.internal.ssl.Provider
security.provider.3=com.sun.rsajca.Provider
security.provider.4=com.sun.crypto.provider.SunJCE
security.provider.5=sun.security.jgss.SunProvider

Again, the lack of a standard harms everyone. Subsystem developers have to design their own ad hoc type system on top of property files and then write parsers for it. The proliferation of these parsers inside the core API causes unnecessary code bloat, and the different formats and rules make learning each new subsystem more of an adventure than it needs to be.

Lookup

CCIs need to provide some lookup mechanism to load the correct configuration information. Again, a quick look at JNDI, Security, and RMI shows that all of them have different lookup rules.

JNDI settings can be read from a variety of locations:

  • JAVA_HOME/lib/jndi.properties

  • Any jndi.properties file visible to the current class loader

  • System properties, either passed on the command line or set using java.lang.System

  • Properties explicitly passed to the InitialContext constructor

  • For applets, properties set in AppletContext

  • Provider resource files (naming convention documented at 1 in the "Resources" section at the end of this article)

If two of the sources above give conflicting information, some kind of resolution policy is needed. A resolution policy determines whether the two conflicting settings are combined in some way, or if one setting overrides the other. The resolution policy for JNDI configuration is sparsely documented at 1.

Security settings are also found in a variety of different locations:

  • JAVA_HOME/lib/security/java.policy

  • JAVA_HOME/lib/security/java.security

  • USER_HOME/.java.policy

  • System properties

  • Other file loads triggered by system properties

  • Other file loads triggered by entries in the .policy and .security files

Again, if two of these sources give conflicting information, there is a resolution policy to determine which one wins. I can't find the entire security resolution policy documented in any one place. However, one example of its esoterica should be enough to make you grimace:

java -Djava.security.policy=my.policy SomeApplication
java -Djava.security.policy==my.policy SomeApplication

One of the commands listed above tells the virtual machine (VM) to ignore all settings in the JAVA_HOME version of java.policy in favor of my.policy. The other command tells the VM to merge the settings from both locations. Can you tell which is which?

The RMI settings must come as system properties. This is simple and easy to remember but will cause problems in a moment when we look at scope.

Scope

Closely related to lookup is the notion of scope. Once we look up some configuration settings, to what do we apply them? As I use the term here, scope means a set of objects (spatial scope) over a period of time (temporal scope). Some configuration options may have a very broad scope, affecting all the objects in a process for the entire lifetime of the process. Other options may have more limited scope, either in time or in space. The JNDI, Security, and RMI CCIs all have severe problems with anything but very coarse-grained scopes.

As described in the previous section, RMI configuration depends on the system properties collection. Therefore, there is basically one spatial scope that includes everything—and no standard way to run two different sets of RMI settings in the same VM. You might be tempted to set the relevant system properties every time you're about to make an RMI call. This plan will fall apart for two major reasons:

  • While you can control your own code, you can't control the RMI plumbing, which is doing things "behind your back."

  • The RMI documentation doesn't specify when configuration values are read, or if they're cached.

The RMI CCI documentation says nothing about temporal scope, so it's probably unsafe to make any assumptions. Properties will be read by the time they're first needed, and then after that things get pretty vague. Maybe they'll be cached. Maybe they'll be read from the file each time they're needed. You could write a set of experiments to figure out whether configuration settings were cached or reread from the file. However, any conclusions you draw from these experiments could not be considered portable—in the absence of documentation, the behavior of the reference implementation would have to be considered implementation detail.

The Security CCI provides more flexible spatial scopes than does RMI:

  • The JAVA_HOME files contain settings scoped to all users of the same VM.

  • The USER_HOME files contain settings scoped to a specific user account.

  • System properties are scoped to a specific VM instance.

NOTE

Because JAVA_HOME and USER_HOME are simply environment variables, you could modify the Security CCI scopes by changing the values of these environment variables.

Security configuration is similar to RMI configuration in that the temporal scope of most settings is undocumented.

The JNDI configuration settings are much more flexible in terms of spatial scope. This is because JNDI looks for jndi.properties files that are visible to the context class loader. The workings of the context class loader are beyond the scope of this article, but see 4 for details. Basically Java's class loader architecture allows a Java programmer to partition a Java process into subspaces based on collections of classes and other resources. The context class loader is a thread-local storage slot that you can use to specify a default class loader for use by the current thread. By tying JNDI configuration to Java's underlying class loader scoping mechanism, the JNDI CCI gives a sophisticated Java programmer excellent fine-grained control over JNDI settings.

Unfortunately the temporal scope story is not so good. The Javadoc for JNDI explicitly punts on this issue:

It is implementation-dependent when environment properties are used and/or verified for validity. For example, some of the security-related properties are used by service providers to "log in" to the directory. This login process might occur at the time the context is created, or the first time a method is invoked on the context. When, and whether this occurs at all, is implementation-dependent. When environment properties are added or removed from the context, verifying the validity of the changes is again implementation-dependent. For example, verification of some properties might occur at the time the change is made, or at the time the next operation is performed on the context, or not at all.1

To summarize, the three CCIs we've analyzed here have varying support for spatial scope, and have essentially no support for temporal scope. To make matters worse, each of the three CCIs implements scope in a totally different way. This increases the challenge for developers learning Java. To add insult to injury, many of the scope rules are poorly or incompletely documented.

Metadata

The Java binary class format stores rich metadata about class and interface types. Java tools can then use reflection to parse that metadata and provide services that make developers more productive: automatic generation of implementation class stubs, popup lists of legal method calls at a particular point in the code, and so on.

Unfortunately, there is no standard metadata for CCIs. As a result, tool support is almost nonexistent. While Java editors can show a list of available methods at any given point in your code, there is no corresponding tool that can show you a list of available configuration options. Not only is there no metadata, there isn't even a standard Javadoc location for a package's configuration information. Finding out how to configure a particular subsystem requires a manual search of the docs. The JNDI CCI is documented under the API help for the Content class 1. The RMI and security policy CCIs are each documented on their own custom pages 2, 3.

The absence of metadata and consistent documentation for CCIs is a great hindrance to developer productivity. Developers often spend hours writing some module, only to discover later that the service they implemented was already available in an existing component—if only they had known some magic CCI setting.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020