2006年12月18日星期一

MDB应用实例

Message Drive Bean据说是EJB 2.0规范里面最有好的一个特性,可惜一般应用和项目中鲜有EJB的使用,更不谈MDB了。
应用中需要将一些消息发送email到主机,为此配置服务器jms,建立消息的queue和factory(使用工具如WSAD可快速的配置,可以参考developerworks的这篇文章这篇)。创建一SLSB AlertsService,该bean作为jms的工具类bean,提供接口将消息发送到队列。该EJB有对queue和factory的resource-ref。
在EJB中建立jms监听端口(在queue, factory上),创建一MDB OutboundAlerts监听该端口,在onMessage()中处理消息:send emails to host。MDB的目标类型为Queue(只有一个消息接受者)。
这里用jms的原因是:发送email可能延误时间,必须为异步的。相对用多线程的实现异步方法,MDB提供了持久性(只有Topic才有这个功能),更稳定。
这里MDB的onMessage的事务类型为:NotSupported,一般消息的发送者和接受者分别在各自的事务中,不可能在一个事务中。

2006年12月16日星期六

jdk6 has been released!

Tonight I occasionally browsed java.sun.com, It was very surprising that J2SE 6 had been available. COOL! Well Done! It was so quickly that sun pushed the newer edition of jdk.
After going through this page, I found there are not too much exciting features in this release except script.
More detail documents can be found in DevX: Mustang Must-Haves: What's Cool in Java SE 6 and Java SE 6's New Scripting and Compiling Goodies .
You can see another cool stuff is compile API. Even there is a project gosling using compile API as a replacement for ANT. It used java as build language other than xml. Also it used some advanced feature such as annotation, compile API.
The questions for gosling are :
1) the build java file need not be compiled?
2) Is it more quickly than old ANT?
3) Why not use script as a language? Though the java maybe be a better choice than XML, it also has a more complex grammar than XML. With XSL XML can be validated easily. If the java don't be compiled in eclipse, how can I make sure my java is correct? till the run-time? How about script? maybe it is more appropriate.