Trap The Spark…

December 14, 2008

Java5 Annotations

In building Gregari I’ve tried to leverage two basic concepts

  • Generate as much as I can via Xdoclet (or Castor) at build time, ideally any boilerplate code.
  • Write the rest but leverage abstract classes or Java5 Annotations/Interceptors.

Assuming one is familiar with Java Annotations… prior to the Java 5 release if you wanted to use the annotation concept you could do the following, i.e.

  • at build time use Xdoclet tags @blah.blah-blah my-attribute=”hi” within the JavaDoc section
  • at runtime use Spring AOP Annotations (amongst others) by @@MyAnnotation( my-attribute=”hi”)

But then came Java 5 with built-in annotation support and so I converted all of my Spring annotations over to the Java 5 standard.  But I still had a lot of ugly Xdoclet tags remaining in my code.   After reading Manning’s “Seam In Action”, i.e. http://www.manning.com/dallen/… I was struck on how JBOSS Seam leveraged Java5 Annotations.  So I basically got rid of my mixture of XDoclet tags (for code generation) and Java5 Annotations (for runtime)… and instead went to exclusively Java5 Annotations.  It even sped up XDOCLET2 code generation by approximately a factor of 10.  The downside is perhaps I went overboard… but not sure what else to do…

So I use Java5 Annotations for the following major concepts:

  • Taxonomies – I have two major taxonomies, i.e. to distinguish one type of objects from another (i.e. business objects from data access objects, mainly done for code generation purposes).  The other major taxonomy is for what capabilities the object supports so that any cross cutting Interceptors can act accordingly.  Essentially these taxonomy annotations are “marker interfaces”.  These taxonomy annotations are both at the class and method levels… where appropriate.
  • Metadata – In order to customize/configure/personalize enterprise applications (such as in a SAAS model where you can configure the application… you first need to know what’s possible.  By embedding the code with annotations… it should centralize code/metadata in one place.  As a part of a build process (or other) the code can be parsed and the metadata stored in configuration files, databases, etc.
  •  JEE specific annotations (EJB’s, Transactions, Entities)
  • Hibernate (ORM, Validation and Search)
  • JBOSS Seam specific annotations
  • System management – One of the issues for 24/7 Operations (DFO-Design For Operations) is that developers write the code but operations supports it (yet there’s little hand off between the two groups).  What if development annotated their code to create health models, instrumentation models, task models, etc. so that a management system could be generated to support the code being developed.  Perhaps just another way to support Extreme Programming, i.e. your code is self documenting.  Normally this is just for other developers… but operation/development engineering (i.e. developers who create software to optimize system management) is another audience.
  • Interface generation – A Java best practice is to have all concrete objects implement an interface.  Other objects reference the interface instead of the concrete object.  This allows many cool things, i.e. mock objects, etc.  Normally the interface is hand written but… if the concrete interface were the master… you could generate its supporting interface (assuming this is the first implementation of that interface).  Interface generation would be optional based on if the marker annotations were present or not.  So… this is done at the class level to signify an interface as well as the method level to signify what methods should be included in the interface.
  • Method level behavior, i.e. should encryption/decryption be implemented, caching, user-defined-fields (UDF’s), history, notes, addresses, list of values (enumerated values), security, etc.  JEE Interceptors will detect this and act accordingly.
  • Page level behavior, i.e. by leveraging the Java5 concept of package-info.java’s at the package level, I can implement component level annotations.  All sub-packages presumably are of the same “component”.  And thus my leverage component component level behavior (where applicable).  I use this at the system management level to create statistics by component.

In subsequent blog postings (to this one) I’ll give specific examples of what this looks like.

Apache Maven vs. Apache Ant

For doing software builds in the Java world… most people use either Ant or Maven.  I’ve used both…

From a requirements perspective I need a continuous integration/build process that can do the following:

  • Dependency Management – In one place identify the components and their versions that are included in this project.  Ideally the same dependency management system can deal with child dependencies automatically.
  • Support some form of reuse across the components (in terms of the build scripts, ideally there’s no large scripts that have redundant text across the commands, difficult to maintain/keep consistent)
  • Support for hierarchical projects composed of numerous components (must scale and allow complexity).
  • Allow quick builds (most perform)
  • Ideally create a project Web site (documentation)
  • At least create project reports per component.

I started in the Ant world, i.e. oodles of ANT scripts on big projects.  My main issue was the complexity of the ANT scripts after awhile and the lack of reuse when you had a multi-component.  But it was fast and it could do anything, i.e. powerful.  I experimented on/off with Maven over the years.  Finally got it working this year.  Everything as advertised except really slow when there’s an Internet connection (and just slow in general).  And needed to break large projects up and build them separately (or them crash early, i.e. PermSpace errors).  With command lines like the following:

MAVEN_OPTS “-Xms128m -Xmx640m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=640m -Xverify:none”

It didn’t crash on the mini-builds… but when trying to build everything it would just slow down and ultimately lock the machine.  I was really attracted to the Development Web site that was created with mvn site but if the system can’t perform nor scale… it’s not worth it.  Looking at Seam and Hibernate.. they appear to get by just fine.  And then there’s trying to get the JBOSS Embedded Server running in Maven…  I’ve searched alot/experimented and just not sure what I’m missing there.  Time to thrown in the towel.  So now I’m going to move back to Ant.  In the past few years… it appears as though Ivy has caught on so perhaps Dependency Management.  Appears to be some templating/reuse concepts (although that may have been there awhile and I overlooked it).  Not sure how much can be templated so will be interested to investigate.

So in retrospect… Maven is nice for small projects.  Mine appears massive (i.e. many components, a lot of code generation, etc.).  So time to go back to Apache Ant.  Also need to get a wiki like http://www.SeamFramework.org and http://in.relation.to (i.e. the documentation posted to Al Gore’s Internet).

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.