Frequently Asked Questions |
Questions
-
General
- What is XBean?
- How does XBean relate to j2Xtreme?
- How does XBean relate to XWidget?
- Is XBean an application framework?
- Does XBean require explicit java interfaces or abstract classes for XBean Services?
- What libraries does j2Xtreme require at runtime?
- Is there internal logging available for XBean?
-
Technical Questions
-
Configuration Loading
- What is the priority property in xbean.properties?
- What is the loading sequence for XBean configuration?
- What is xbean.configpath?
- Does XBean do lazy loading of configuration?
- Is XBean compatible with JMX?
- Is XBean compatible with EJBs, remote RMI objects, and JNDI-resolvable resources?
- Does XBean implement a custom classloader?
- What classloader will be used to load my XBean Services?
- Where should I put j2xtreme-xbean-*.jar?
-
XBean Service Scope
- What do you mean by scope?
- When does a particular thead scope begin?
- When does thread scope end?
- How can I tell if my XBean service has gone out of scope?
- Does scope have anything to do with garbage collection?
- What is the difference between global and application scope?
-
Service Instantiation
- 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?
-
Configuration Loading
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.
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:
Name | Version | Required |
---|---|---|
Jakarta Commons BeanUtils | 1.6.1 | Required |
Jakarta Commons Collections | 3.0 | Required |
Jakarta Commons Logging | 1.0.3 | Required |
Jakarta ORO | 2.0.8 | Required |
Jakarta Commons DBCP | 1.1 | Optional |
Jakarta Commons Pool | 1.1 | Optional |
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.
2.1.2. What is the loading sequence for XBean configuration?
The loading sequence is (from highest to lowest priority):
- System Properties (i.e. -D parameters passed to jvm)
- xbean.configpath (i.e. delimited path of URLs/files pointing to properties files)
- WEB-INF/xbean.properties (when running in webapp)
- 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.
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:
- Startup tends to be a bit more deterministic, especially with regard to the webapp contexts.
- All beans can be known and validated at startup time.
- 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.
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.
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.
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:
- 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.
- 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.
- 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.