Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Kicking the Tires on Java 5.0
Building an aspect-oriented framework based on annotations

I'm really jazzed about Java 5.0! We've been treated over the years to incremental improvements in JVM performance. JDK 1.2 brought us the collections framework as well as Swing, the thread context class loader, and improvements in RMI. JDK 1.3 and 1.4 continued in the same vain with logical improvements to libraries, JVM enhancements, and performance upgrades. Although this article doesn't intend to take trip down memory lane, it's important to understand that Java 5.0 brings a truly remarkable and rich set of new tools to our programming landscape as compared to other JDK releases.

This article will survey some of Java 5.0's new features and put them into practice through example. We'll build up a lightweight aspect-oriented system based on annotations to showcase what's new in 5.0. Some of these features you may be familiar with, some you may not. I've attempted to mix the obvious with some of the obscure. We'll examine some of the new hooks that the JVM has exposed for class loading, which makes the once dreadful work of bytecode manipulation during class loading much easier. In the "obvious" column, we'll look at generics and how they enable us to write more robust and sane programs, especially when dealing with collections. Perhaps the most notable aspect of Java 5.0 that we'll examine is the annotation framework. Annotations allow developers to inject metadata into their applications. We'll use this feature to demark classes we want manipulated at load time. To put this all in context, we'll create a lightweight framework that will manipulate classes as they are being loaded to enable logging, security, BAM (business activity monitoring), or any number of other scenarios that have yet to be dreamed up (The source code for this article can be downloaded from http://jdj.sys-con.com.)

Annotations
Annotations are nothing new. In concept we've been injecting forms of metadata into our programs for years. If you've ever used XDoclet or EJBGEN to annotate a class in preparation for EJB deployment descriptor generation, you've used a form of annotation. Although these annotation methods are primarily manipulated during compilation, frameworks do exist that allow runtime access to annotations. Those that come to mind are the Jakarta Commons Attributes project and the metadata infrastructure in the Spring framework. One important thing to note from the Spring documentation regarding the use of Java 1.5 annotations versus metadata available in the Spring framework is the following:

"JSR-175 metadata is static. It is associated with a class at compile time, and cannot be changed in a deployed environment. There is a need for hierarchical metadata, providing the ability to override certain attribute values in deployment - for example, in an XML file."

For our purposes, however, the annotations suggested by JSR-175 and implemented in Java 5.0 will be sufficient.

Anatomy of an Annotation
Generally, annotations are thought of only as artifacts useful at compile time by tool vendors to do such things as generating deployment descriptors. This is what utilities such as XDoclet and EJBGEN do. The annotations are examined at compile time, used to generate output (in the case of EJB this maybe a deployment descriptor) and in a sense are then discarded thereafter as an artifact. Annotations in Java 1.5 can behave in a similar way, but they can also be retained past the compilation stage and accessed at runtime. The developer has three retention policies to choose from. They are:

  • RententionPolicy.CLASS: Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at runtime
  • RententionPolicy.RUNTIME: Annotations are to be recorded in the class file by the compiler and retained by the VM at runtime, so they can be read reflectively.
  • RententionPolicy.SOURCE: Annotations are to be discarded by the compiler.
To declare a new annotation type, the developer must specify a retention policy for his or her annotation, what the element type is and what attributes the annotation possesses. The developer can associate an annotation with a particular element Valid element types are:
  • ElementType.Constructor: Associates an annotation with a constructor.
  • ElementType.Field: Associates an annotation with a field.
  • ElementType.LocalVariable: Associates an annotation with a local variable.
  • ElementType.Method: Associates an annotation with a method.
  • ElementType.Package: Associates an annotation with a package.
  • ElementType.Parameter: Associates an annotation with a parameter.
  • ElementType.Type: Associates an annotation with a type.
Let's look at a typical annotation declaration.

package annotations;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})

public @interface BAMAnnotation
{
String insertionPoint();
String processBean();
}

What's notable here is that the annotation declaration is strikingly similar to an interface declaration and that the metadata for this annotation is defined in terms of an annotation! This particular annotation is used on a method and its values are accessible at runtime as dictated by the retention policy. The annotations require two attributes to be defined, "insertionPoint" and "processBean. To use this annotation in a class is pretty straightforward:


import annotations.*;

public class BizComponent
{

@BAMAnnotation(processBean="nullInjector",
insertionPoint="pre")
public void execute()
{
System.out.println("Executing"+
"some biz functionality");
}
}

Here we've associated our annotation with the "execute()" method of our "BizComponent" class. When we examine this class at runtime the values of "processBean" and "insertionPoint" will be "nullInjector and "pre" respectively.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

fantastic article, very thought provoking -- kudos. Can you comment on potential performance related issues in instrumented components that have high availability requirements?

I'm sorry, but I cann't find link to sources
of this cool article on the web pages.

This article will survey some of Java 5.0's new features and put them into practice through example. We'll build up a lightweight aspect-oriented system based on annotations to showcase what's new in 5.0. Some of these features you may be familiar with, some you may not. I've attempted to mix the obvious with some of the obscure. We'll examine some of the new hooks that the JVM has exposed for class loading, which makes the once dreadful work of bytecode manipulation during class loading much easier. In the "obvious" column, we'll look at generics and how they enable us to write more robust and sane programs, especially when dealing with collections. Perhaps the most notable aspect of Java 5.0 that we'll examine is the annotation framework. Annotations allow developers to inject metadata into their applications. We'll use this feature to demark classes we want manipulated at load time. To put this all in context, we'll create a lightweight framework that will manipulate classes as they are being loaded to enable logging, security, BAM (business activity monitoring), or any number of other scenarios that have yet to be dreamed up


Your Feedback
slopzster wrote: fantastic article, very thought provoking -- kudos. Can you comment on potential performance related issues in instrumented components that have high availability requirements?
Boris wrote: I'm sorry, but I cann't find link to sources of this cool article on the web pages.
Peter Braswell wrote: This article will survey some of Java 5.0's new features and put them into practice through example. We'll build up a lightweight aspect-oriented system based on annotations to showcase what's new in 5.0. Some of these features you may be familiar with, some you may not. I've attempted to mix the obvious with some of the obscure. We'll examine some of the new hooks that the JVM has exposed for class loading, which makes the once dreadful work of bytecode manipulation during class loading much easier. In the "obvious" column, we'll look at generics and how they enable us to write more robust and sane programs, especially when dealing with collections. Perhaps the most notable aspect of Java 5.0 that we'll examine is the annotation framework. Annotations allow developers to inject metadata into their applications. We'll use this feature to demark classes we want manipulated at load time. T...
Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE