OSGi应用开发:扩展Blueprint与拍卖应用优化
1. 拦截Blueprint
1.1 交易扩展回顾
首先回顾之前在Blueprint文档中使用的交易扩展示例:
<bean id="handler" class="manning.osgi.SimpleEventHandler" >
<tx:transaction method="handleEvent" />
</bean>
此示例告知容器 SimpleEventHandler.handleEvent()
方法需在交易上下文中运行,其运行结果等同于以下实现:
public void handleEvent(Event event) {
UserTransaction ut = getUserTransactionService();
try {
ut.begin();
try {
// User code to handle event
ut.commit();
} catch (Exception e) {
ut.rollback();
}
} catch (Exception e) {
// Handle TM exception...
}
}