Coverage Report - org.mule.retry.notifiers.ConnectNotifier
 
Classes in this File Line Coverage Branch Coverage Complexity
ConnectNotifier
0%
0/16
0%
0/4
1.667
 
 1  
 /*
 2  
  * $Id: ConnectNotifier.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 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  
  * Fires a {@link ConnectionNotification} each time a retry attempt is made.
 23  
  */
 24  0
 public class ConnectNotifier implements RetryNotifier
 25  
 {
 26  0
     protected transient final Log logger = LogFactory.getLog(ConnectNotifier.class);
 27  
 
 28  
     public void onSuccess(RetryContext context)
 29  
     {
 30  0
         if (logger.isDebugEnabled())
 31  
         {
 32  0
             logger.debug("Successfully connected to " + context.getDescription());
 33  
         }
 34  
 
 35  0
         fireConnectNotification(ConnectionNotification.CONNECTION_CONNECTED, context.getDescription(), context);
 36  0
     }
 37  
 
 38  
     public void onFailure(RetryContext context, Throwable e)
 39  
     {
 40  0
         fireConnectNotification(ConnectionNotification.CONNECTION_FAILED, context.getDescription(), context);
 41  
 
 42  0
         if (logger.isErrorEnabled())
 43  
         {
 44  0
             StringBuffer msg = new StringBuffer(512);
 45  0
             msg.append("Failed to connect/reconnect: ").append(context.getDescription());
 46  0
             Throwable t = ExceptionHelper.getRootException(e);
 47  0
             msg.append(". Root Exception was: ").append(ExceptionHelper.writeException(t));
 48  0
             logger.error(msg.toString());
 49  
         }
 50  0
     }
 51  
 
 52  
     protected void fireConnectNotification(int action, String description, RetryContext context)
 53  
     {
 54  0
         context.getMuleContext().fireNotification(new ConnectionNotification(null, description, action));
 55  0
     }
 56  
 }