j2Xtreme
 
   

Frequently Asked Questions

Questions

  1. General
  2. Technical Questions

Answers

1. General

1.1. What is XBean? ^

XBean is a microkernel container for plain old java objects, and especially well suited for JavaBeans.

1.2. How does XBean relate to j2Xtreme? ^

XBean is one foundation technology that falls under the j2Xtreme umbrella.

1.3. How does XBean relate to XWidget? ^

XBean has no dependency on XWidget whatsoever. XWidget, on the other hand, uses XBean as one of its core enabling technologies.

Note
XWidget, by the way, is an ambitious attempt to create PowerBuilder-for-the-web. It is highly focused on enabling the rapid development of small- and mid-sized business applications...exactly the kind of apps for which PowerBuilder was useful back in the day.
1.4. Is XBean an application framework? ^

XBean is a microkernel container for JavaBeans. Although it does provide a few application-oriented common services, notably the JDBC integration in com.j2xtreme.xbean.sql, being an application frameowrk is not XBean's primary goal.

Depending on what happens with this project, it might make sense at some point to create an XBean Commons, containing a standard library of common services. This would be very easy to create since it would almost certainly leverage pre-existing code, and merely expose it in easy-to-use common services.

It is really very easy to put together a high-level application framework using this kind of architecture. In fact, the predecessor to XBean, BeanFactory, did exactly that. It provided an MVC dispatching mechanism along with some clever taglibs. XBean, however, is meant to be an unbundled, lightweight microkernel.

Is anyone interested in taking this up? Call it XApp? There is a lot of code available from the BeanFactory project that could be retooled here.

1.5. Does XBean require explicit java interfaces or abstract classes for XBean Services? ^

No. Any class will do, so long as it is loadable through the built-in JavaBean factory or a custom factory. For any number of reasons that are too detailed for this FAQ it may be beneficial to define interfaces for your services. However, with XBean, this is somewhat less critical because of the flexibility of the framework itself.

1.6. What libraries does j2Xtreme require at runtime? ^

In addition to the j2xtreme-xbean-*.jar, the following JARs are required in your classpath:

NameVersionRequired
Jakarta Commons BeanUtils1.6.1Required
Jakarta Commons Collections3.0Required
Jakarta Commons Logging1.0.3Required
Jakarta ORO2.0.8Required
Jakarta Commons DBCP1.1Optional
Jakarta Commons Pool1.1Optional
Note
The versions indicated are the versions that are used in development. None of the features used by these packages is particularly esoteric, so presumably previous and subsequent versions may work as well. Caveat emptor, as it were.
1.7. Is there internal logging available for XBean? ^

Absolutely. XBean uses Jakarta Commons exclusively, which means that any supported logging framework should work, including Log4J and JDK1.4 logging. Please see the respective documentation for how to configure logging for both of these.

Please note that the stem you would be interested in is com.j2xtreme.xbean. Turning logging up to the debug level or equivalent, should provide quite a bit of information.

It is also worth noting that because XBean uses BeanUtils for to configure JavaBeans, it may also be useful to turn up logging on org.apache.commons.beanutils.

2. Technical Questions

2.1. Configuration Loading^
2.1.1. What is the priority property in xbean.properties?

When launching a jvm, the CLASSPATH normally has an explicit ordering that has a behavior that is analogous to the PATH search order used by Windows and UNIX shells.

XBean depends on the fact that xbean.properties is loaded and merged from the classpath with precedence matching the classpath's ordering. Consider the CLASSPATH a.jar:b.jar and imagine that both a.jar and b.jar contain xbean.properties which defines /Foo.bar. The /Foo.bar definition in a.jar will override that in b.jar because of the explicit ordering of the classpath.

Now, webapps have no such well-defined ordering. The webapp classloader loads all the classes in WEB-INF/classes and WEB-INF/lib in an arbitrary order. How do we ensure that xbean.properties files are processed in a predictable order?

We'll in 90% of cases, we really don't care and there isn't much overriding of properties going on between JARs. However, to accommodate this 10% of cases where this ordering is imporant, XBean honors the priority attribute of xbean.properties. The priority is an integer ordinal upon which all the files are sorted, with lowest number having precendence. This makes it trivial re-order an otherwise arbitrarily ordered classpath, should this become important.

Note
Mnemonics: XBean priority is consistent with UNIX process priority, with lower numbers having higher precedence.
2.1.2. What is the loading sequence for XBean configuration?

The loading sequence is (from highest to lowest priority):

  1. System Properties (i.e. -D parameters passed to jvm)
  2. xbean.configpath (i.e. delimited path of URLs/files pointing to properties files)
  3. WEB-INF/xbean.properties (when running in webapp)
  4. classpath

This means that passing -D/Foo.bar=abc will override any /Foo.bar configuration found in the classpath, WEB-INF/xbean.properties, or the xbean.configpath.

An entry found in a file loaded through the xbean.configpath will override the same property in WEB-INF/xbean.properties and the classpath, but not one passed through System properties.

2.1.3. What is xbean.configpath?

It is a system property that may be set to tell XBean where to look to find some additional bean configuration. Specifically, it is a comma delimited list of URLs and files that XBean will try to load into its configuration database.

Let's say you start your app with:

 java -Dxbean.configpath=./abc.properties,./def.properties MyMainClass

This would cause the XBean container to try to load ./abc.properties and ./def.properties and merge them into the configuration set.

Note
xbean.configpath follows the same merging/precedence rules as xbean.properties files loaded through the classpath.
2.1.4. Does XBean do lazy loading of configuration?

No, it loads all of the configuration all at once. While there are certain advantages to lazy loading, it causes some serious complications. Non-lazy loading allows:

  1. Startup tends to be a bit more deterministic, especially with regard to the webapp contexts.
  2. All beans can be known and validated at startup time.
  3. It becomes possible to have services start when the container is loaded.
2.1.5. Is XBean compatible with JMX?

Not yet, though this on the XBean roadmap. XBeans and MBeans would be quite complementary. In fact, this is where I got the name XBean.

2.1.6. Is XBean compatible with EJBs, remote RMI objects, and JNDI-resolvable resources?

Just about anything that passes for a Java object can be exposed as an XBean service. XBean does not have built-in support for these things, though they would be trivial to implement. In keeping with the mission of developing a lightweight microkernel, integration with these things within XBean proper is not currently in the roadmap. However, that may change if/when people decide it is important.

Note
j2Xtreme tries to implement many of the more practical guidelines of XP (among other methodolgies). One of the best, in this author's mind is You Ain't Gonna Need It. You can go to the XP site to find the exact quote, but roughly paraphased it is: Design for your known requirements, not the requirements you think you need. If it turns out you need it later, then add it later when the requirements are known.
2.1.7. Does XBean implement a custom classloader?

XBean does not implement yet another classloader, quite intentionally. Implementing a custom classloader is the responsibility of the application server, not the XBean microkernel.

2.1.8. What classloader will be used to load my XBean Services?

The same classloader that is used to load XBean itself.

2.1.9. Where should I put j2xtreme-xbean-*.jar?

In an web application server context you should only put j2xtreme-xbean-*.jar in your WEB-INF/lib directory. Loading it from the system classloader or anything delegated up from the webapp classloader is likely to have some interesting consequences. Most notably, global scope will be more-global than your web application, which starts to violate the J2EE security rules for isolating web-applications.

In a standalone context, you can load it out of any classloader you please, but most likely the system classloader.

Note
No testing has (yet) been done on loading it within an EJB classloader. It is not really high on the priority list either. However, if you feel that there is a compelling need to be able to use XBean inside your EJBs, please let me know.
2.2. XBean Service Scope^
2.2.1. What do you mean by scope?

See the XBean QuickStart Guide for an explanation.

2.2.2. When does a particular thead scope begin?

Thread scope begins implicitly as soon as a thread-scoped service is requested. There is no need to demarcate the beginning of a thread's scope.

2.2.3. When does thread scope end?

Thread scope ends when either ServiceContext.unbindThread() is invoked explicity, or the method is invoked by the XBean servlet filter.

Note
In 98% of all cases of using XBean with webapps, it should not be necessary to do any kind of explicit binding and unbinding of scopes, thread or otherwise. Let the XBean Servlet Filter do this for you!!
2.2.4. How can I tell if my XBean service has gone out of scope?

Use the ServiceContext.addLostScopeListener() method. This method allows you to register interest in a particular service. When it goes out of scope, the lostScope() method of the listener that you registered will be invoked.

For convenience's sake, the XBean container will automatically register an XBean Service if it happens to implement the LostScopeListener interface.

2.2.5. Does scope have anything to do with garbage collection?

No, not really, except that an XBean service that is "in scope" is guaranteed not to be garbage collected. The converse is not necessarily true.

XBean scope is really the scope of the name-to-service-instance mapping, not the service itself.

2.2.6. What is the difference between global and application scope?

In most usage they should be quite similar. An XBean service with global scope will have the same lifecycle as a singleton java object loaded from within a web application. A bean with application scope will have the same lifecycle as an object that is stuffed in the ServletContext attribute pool.

In fact, in the current implementation, this is how each of these is stored.

So the short answer is, read the Servlet spec to understand the interaction between the webapp and classloader.

2.3. Service Instantiation^
2.3.1. I have an existing object model that I would like to expose as XBean Services, but my classes don't have public and/or no-arg constructors. What do I do?

Never fear, just about anything can be exposed as an XBean Service. In fact, the XBean container exposes HttpServletRequest and friends which aren't even managed by the XBean container!

To accomplish this (to expose Foo, which has no public no-arg constructor), you need to do a few things:

  1. Implement com.j2xtreme.xbean.ServiceFactory for the class you are intending to expose. This interface defines two rather self-explanatory methods that must be implemented. You can name it FooServiceFactory for clarity, though it doesn't matter what you name it.
  2. Expose the ServiceFactory that you defined as a named XBean Service. That means writing a service entry in xbean.properties for FooServiceFactory. We will call it /FooServiceFactory for simplicity.
  3. In the service definition for the instance of Foo that you wish to epose (call it /Foo, you set a special property, $factory and point it to the service factory. That is: /Foo.$factory=xbean:/FooServiceFactory.

Now, when you request /Foo, instead of trying to instantiate a configure a JavaBean, the XBean container will resolve your designated ServiceFactory and use it to obtain and expose the service.

Note
All the scoping rules still apply, so your XBean Service behaves just like a normal XBean. This is quite powerful...you could turn the entire J2SE/J2EE environment "inside out" as it were should you desire to do so.
Note
Please DO NOT go to all this trouble for beans/services which have public/no-arg constructors. Just use the default XBean factory.