1
2
3
4
5
6
7
8
9
10
11 package org.mule.retry.notifiers;
12
13 import org.mule.api.retry.RetryContext;
14 import org.mule.api.retry.RetryNotifier;
15 import org.mule.config.ExceptionHelper;
16 import org.mule.context.notification.ConnectionNotification;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21
22
23
24 public class ConnectNotifier implements RetryNotifier
25 {
26 protected transient final Log logger = LogFactory.getLog(ConnectNotifier.class);
27
28 public void onSuccess(RetryContext context)
29 {
30 if (logger.isDebugEnabled())
31 {
32 logger.debug("Successfully connected to " + context.getDescription());
33 }
34
35 fireConnectNotification(ConnectionNotification.CONNECTION_CONNECTED, context.getDescription(), context);
36 }
37
38 public void onFailure(RetryContext context, Throwable e)
39 {
40 fireConnectNotification(ConnectionNotification.CONNECTION_FAILED, context.getDescription(), context);
41
42 if (logger.isErrorEnabled())
43 {
44 StringBuffer msg = new StringBuffer(512);
45 msg.append("Failed to connect/reconnect: ").append(context.getDescription());
46 Throwable t = ExceptionHelper.getRootException(e);
47 msg.append(". Root Exception was: ").append(ExceptionHelper.writeException(t));
48 logger.error(msg.toString());
49 }
50 }
51
52 protected void fireConnectNotification(int action, String description, RetryContext context)
53 {
54 context.getMuleContext().fireNotification(new ConnectionNotification(null, description, action));
55 }
56 }