How do I create a Mailer Observer

I’m surprised how little there is in Rails’ documentation about this. Basically, ActionMailer in Rails 3 introduces the use of Interceptors (called before the message is sent) and Observers (after the message is sent). To set up an Observer, add the following to an initializer: class MailObserver def self.delivered_email(message) # Do whatever you want with … Read more

Callback/Command vs EventListener/Observer Pattern

Command, callback and observer patterns have different semantics: callback – notifies a single caller that some operation finished with some result observer – notifies zero to n interested parties that some event (for example a finished operation) happened command – encapsulates a operation call in an object thus making it transferable over a wire or … Read more

How can I update information in an Android Activity from a background Service

How can I set up my Activity to be listening to the Service? Is this the best way to approach this problem? You have three major options, as I see it: Polling. The Activity periodically asks the Service for the latest data. IMHO, this option sucks, but it’s certainly possible. Callbacks. Per jax’s answer, the … Read more

Simple way of turning off observers during rake task?

Rails 3.1 finally comes with API for this: http://api.rubyonrails.org/v3.1.0/classes/ActiveModel/ObserverArray.html#method-i-disable ORM.observers.disable :user_observer # => disables the UserObserver User.observers.disable AuditTrail # => disables the AuditTrail observer for User notifications. # Other models will still notify the AuditTrail observer. ORM.observers.disable :observer_1, :observer_2 # => disables Observer1 and Observer2 for all models. ORM.observers.disable :all # => disables all observers … Read more

How to create custom Listeners in java?

https://stackoverflow.com/a/6270150/3675925 You probably want to look into the observer pattern. Here’s some sample code to get you started: import java.util.*; // An interface to be implemented by everyone interested in “Hello” events interface HelloListener { void someoneSaidHello(); } // Someone who says “Hello” class Initiater { private List<HelloListener> listeners = new ArrayList<HelloListener>(); public void addListener(HelloListener … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)