-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to notify an Observer
PostPosted: Thu Nov 03, 2005 8:57 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
I have an entity that needs to notify observers when some of its properties have changed.

One particular Observer is a NotificationService. The notification service will send out an email when the entity has been changed. The problem I am having is determing when to notify the observer. It could easily be done if I notify the observer right away when the state of the entity has changed. But in the case with the Notification service, what if the changes to the entity never got persisted. An exception could occur, a network problem, or a million other reasons that would prevent the changes from making it to the db. The Notification Service would have sent out an email to notify users about changes, but the changes never actually got saved.

Any ideas about how I could solve this, some other pattern, an Interceptor, etc...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 4:11 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
I'd probably use the PostFlush method of an interceptor.

There are some good articles on how to build and use interceptors on the Hibernate wiki - see the section "Interceptors, user types, and other extensions" on this page http://www.hibernate.org/37.html

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 8:59 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Thanks Symon,
I think that is ultimately what I am going to do. My design plan is to have an Interface called IDelayedNotifier. IDelayedNotifier will have one operation called NotifyDelayedObservers or something like that. then in OnPostFlush I will call NotifyDelayedObservers for IDelayedNotifiers. Then in NotifyDelayedObservers the entity can go about notifying any observers if the correct conditions are met.

Is that something along the lines of what you were thinking?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.