The JBoss AOP Deployer


JBoss AOP applications are supported in the standard and all configurations in JBoss AS 4.0.0 (the default and all configurations in JBoss AS 4.0.1). The jboss-aop.deployer service in the deploy directory deploys AOP applications inside the JBoss application server. The structure of the jboss-aop.deployer directory is shown in Figure 14.1. Notice that the jboss-aop.deployer service archive in JBoss AS 4.0.0 is a zip file instead of a directory. It includes the following components:

  • Java libraries for the JBoss AOP framework, including utilities to instrument AOP classes at load time.

  • A prepackaged set of aspects, which are available in all applications deployed on the server. Those prepackaged aspects handle cross-cutting concerns, such as security, transactions, and spawning of asynchronous threads, for applications.

  • A default aspect binding configuration file base-aop.xml that binds prepackaged aspects to certain annotations and method signature patterns. So, in your applications, you can just use those predefined annotations and method signatures to take advantage of the prepackaged aspects.

Figure 14.1. The directory structure of the JBoss AOP deployer in JBoss AS.


Installing the Latest jboss-aop.deployer Service

Because JBoss AOP is a fast-evolving technology, it is probably a good idea to keep your jboss-aop.deployer service up-to-date with the latest JBoss AOP release. After you unzip the JBoss AOP release file, the jboss-40-install directory contains the jboss-aop. deployer archive for the JDK 1.4 and JDK 5.0 environments. You can just copy those files to your JBoss server's deploy directory to replace the JBoss AOP service that shipped with the application server.

Configuring the AOP Service

By default, the jboss-aop.deployer service disables load-time bytecode instrumentation. You have to instrument your code offline with the aopc utility. You should enable load-time instrumentation by editing the META-INF/jboss-service.xml file in the jboss-aop.deployer directory. You can just change the EnableTransformer attribute value to true, as follows:

 <mbean code="org.jboss.aop.deployment.AspectManagerService"        name="jboss.aop:service=AspectManager">   <attribute name="EnableTransformer">false</attribute>   <!-- only relevant when EnableTransformer is true -->   <attribute name="SuppressTransformationErrors">true</attribute>   <!-- only relevant when Enabletransformer is true.        Optimization is optional        only just in case there is a bug in it -->   <attribute name="Optimized">true</attribute>   <attribute name="Verbose">false</attribute> </mbean> <mbean code="org.jboss.aop.deployment.AspectDeployer"        name="jboss.aop:service=AspectDeployer"> </mbean> 

Other attributes in this MBean control the behavior of the JBoss AOP deployer. Those attributes are manageable via the JBoss JMX Console when the server is running.

The Prepackaged Aspects Library

The key value proposition of AOP is to promote code reuse. For example, you can reuse common aspects across different object trees in different applications:

  • Transactions JBoss AOP allows you to declare transaction requirements and properties on any POJO method. You can inject the current transaction manager anywhere in the code via annotation and save the trouble of writing lookup code.

  • Security You can declare EJB-style security constraints on any POJO method to limit the access to them. You'll see a security aspect example later in this chapter.

  • Observers You can transparently add observers to any POJO via annotation. For example, the observer could log all the call invocations against methods in the object. The previously mentioned trace() example shows the observer in action. This aspect can be used outside the JBoss AS in standalone applications.

  • Asynchronous method invocation You can annotate a method to specify that it should be executed in a separate background thread. This aspect can be used outside the JBoss AS in standalone applications. It is especially useful in Swing or SWT UI applications.

  • Thread-based Any field value tagged with the annotation defined by this aspect would behave as though its value were stored in java.lang.ThreadLocal. This aspect can be used outside the JBoss AS in standalone applications.

  • Read/write lock You can use this annotation to define a read/write lock at the method level. The implementation is based on the concurrent package from Doug Lea. This aspect can be used outside the JBoss AS in standalone applications.

The prepackaged aspect library in JBoss AOP is still under development. For the most up-to-date documentation on the currently available aspects, refer to the docs/aspect-library/index.html document.



JBoss 4. 0(c) The Official Guide
JBoss 4.0 - The Official Guide
ISBN: B003D7JU58
EAN: N/A
Year: 2006
Pages: 137

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net