[Design of Messaging on JBoss (Messaging/JBoss)] - Re: Justification for
by adrian@jboss.org
"timfox" wrote : That make sense, although I don't see how that applies to the particular methods that have been declared as throws Throwable in messaging core.
Because if everything delcares Throwable,
you can propogate the Throwable throughout your
internal api without wrapping it at every level.
e.g. for JMS you would wrap the Throwable in a JMSException
in the facade.
You probably aren't aware of the problems we had
due to the stupid jmx exception wrapping. :-)
anonymous wrote :
| This is mentioned in Bloch's effective Java "Strive for failure atomicity"
|
Not everything can be atomic.
e.g. in the example above, it could be JMS (outside a transaction)
step1 == write the message to a persistent store
step2 == do the processing to add to the queue
a failure in step2 requires
reverseStep1 == remove from the persistent store
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961346#3961346
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961346
17 years, 10 months
[Design of Messaging on JBoss (Messaging/JBoss)] - Re: Justification for
by timfox
Wouldn't it be better if the method is written to always guarantee to leave the object in a well defined state?
If the object is not left in a well defined state then even if you catch Throwable, then there's not much you can do since you don't know if the underlying resource (or whatever) was actually allocated.
E.g.
| Connection getConnection() throws Throwable
| {
|
| log.info("before allocation");
|
| Connection conn = ......
|
| log.info("after allocation");
|
| return conn;
| }
|
In the above, both calls to log.info can throw a RuntimeException. If it's thrown from the first log.info line then the connection hasn't been allocated, but if it's thrown from the second one then the connection has been allocated.
If you do something like:
| Connection getConnection()
| {
| Connection conn = null;
|
| try
| {
|
| log.info("before allocation");
|
| conn = ......
|
| log.info("after allocation");
| }
| catch (Throwable t)
| {
| if (conn != null) conn.close();
|
| throw new IllegalStateException();
| }
|
| return conn;
| }
|
|
Then your're not leaving anything to chance and you can avoid throws Throwable.
This is mentioned in Bloch's effective Java "Strive for failure atomicity"
What am I missing?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961343#3961343
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961343
17 years, 10 months