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