views:

194

answers:

3

I am planning an application that must provide services that are very much like those of a JEE container to third party extension code. Basically, what this app does is find a set of work items (currently, the plan is to use Hibernate) and dispatch them to work item consumers.

The work item consumers load the item details, invoke third party extension code, and then if the third party code did not fail, update some state on the work item and commit all work done.

I am explicitly not writing this as a JEE application. Essentially, my application must provide many of the services of a container, however; it must provide transaction management, connection pooling and management, and a certain amount of deployment support. How do I either A) provide these directly, or B) choose a third party library to provide them. Due to a requirement of the larger project, the extension writers will be using Hibernate, if that makes any difference.

It's worth noting that, of all of the features I've mentioned, the one I know least about is transaction management. How can I provide this service to extension code running in my container?

+4  A: 

Hi I recommend using the Spring Framework. It provides a nice way to bring together a lot of the various services you are talking about.

For instance to address your specific needs:

  1. Transaction Management/Connection pooling
    • I built a spring-based stand-alone application that used Apache commons connection pooling. Also I believe spring has some kind of transaction mgmt built in.
  2. Deployment support
    • I use ant to deploy and run things as a front-loader. It works pretty well. I just fork a seperate process using ant to run my Spring stand-alone app.
  3. Threading.
    • Spring has support for Quartz which deals well with threads and thread pools
  4. DAO
    • Spring integrates nicely with Hibernate and other similar projects
  5. Configuration
    • Using its xml property definitions -- Spring is pretty good for multiple-environment configuration.
Ish
+1 - Perfect. I wish I'd seen it first.
duffymo
Good answer, but Quartz is for scheduling not threading. It uses threads of course, but its function is scheduling. Still a good answer though.
Robin
Regrettably, the aspect you glossed over -- "I believe spring has some kind of transaction mgmt built in" -- is the single hardest part of what I'm doing, and the one with which I need to come to grips before choosing a framework. I'm already considering Spring, but I'd need to know if it's capable of supporting the system I want to build.
Chris R
+1  A: 

Spring does have transaction management. You can define a DataSource in your application context using Apache DBCP (using a org.apache.commons.dbcp.BasicDataSourceorg.springframework.jdbc.datasource.DataSourceTransactionManager for the DataSource. After that, any object in your application can define its own transactions programatically if you pass it the TransactionManager, or you can use AOP interceptors on the object's definition in your application context, to define which methods need to be run inside a transaction.

Or, the easier approach nowadays with Spring is to use the @Transactional annotation in any method that needs to be run inside a transaction, and to add something like this to your application context (assuming your transactionManager is named txManager):

<tx:annotation-driven transaction-manager="txManager"/>

This way your application will easily accept new components later on, which can have transaction management simply by using the @Transactional annotation or by directly creating transactions through a PlatformTransactionManager that they will receive through a setter (so you can pass it when you define the object in your app context).

Chochos
+1  A: 

Hi,

You could try Atomikos TransactionsEssentials for Java transaction management and connection pooling (JDBC+JMS) in a J2SE environment. No need for any appservers, and it is much more fun to work with ;-)

HTH Guy

Guy Pardon
You're a bit focused, Guy :) You've answered three of my questions with just this response.Sure wish you'd been a site member when I finally had to pick a solution; Atomikos looks good, but the infrastructure has already been chosen.
Chris R