Coverage Report - org.mule.impl.internal.admin.EndpointNotificationLoggerAgent
 
Classes in this File Line Coverage Branch Coverage Complexity
EndpointNotificationLoggerAgent
0%
0/26
0%
0/3
2.4
 
 1  
 /*
 2  
  * $Id: EndpointNotificationLoggerAgent.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.impl.internal.admin;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.impl.MuleEvent;
 15  
 import org.mule.impl.MuleMessage;
 16  
 import org.mule.impl.MuleSession;
 17  
 import org.mule.impl.NullSessionHandler;
 18  
 import org.mule.impl.endpoint.MuleEndpoint;
 19  
 import org.mule.providers.NullPayload;
 20  
 import org.mule.umo.UMOEvent;
 21  
 import org.mule.umo.UMOMessage;
 22  
 import org.mule.umo.UMOSession;
 23  
 import org.mule.umo.endpoint.UMOEndpoint;
 24  
 import org.mule.umo.lifecycle.InitialisationException;
 25  
 import org.mule.umo.manager.UMOServerNotification;
 26  
 
 27  
 import java.util.Map;
 28  
 
 29  
 /**
 30  
  * <code>EndpointAbstractEventLoggerAgent</code> will forward server notifications
 31  
  * to a configurered endpoint uri.
 32  
  */
 33  0
 public class EndpointNotificationLoggerAgent extends AbstractNotificationLoggerAgent
 34  
 {
 35  
 
 36  
     private String endpointAddress;
 37  0
     private UMOEndpoint logEndpoint = null;
 38  
     private UMOSession session;
 39  
 
 40  
     protected void doInitialise() throws InitialisationException
 41  
     {
 42  
         // first see if we're logging notifications to an endpoint
 43  
         try
 44  
         {
 45  0
             if (endpointAddress != null)
 46  
             {
 47  0
                 logEndpoint = MuleEndpoint.getOrCreateEndpointForUri(endpointAddress,
 48  
                     UMOEndpoint.ENDPOINT_TYPE_SENDER);
 49  
             }
 50  
             else
 51  
             {
 52  0
                 throw new InitialisationException(
 53  
                     CoreMessages.propertiesNotSet("endpointAddress"), this);
 54  
             }
 55  
             // Create a session for sending notifications
 56  0
             session = new MuleSession(new MuleMessage(NullPayload.getInstance(), (Map) null), new NullSessionHandler());
 57  
         }
 58  0
         catch (Exception e)
 59  
         {
 60  0
             throw new InitialisationException(e, this);
 61  0
         }
 62  0
     }
 63  
 
 64  
     protected void logEvent(UMOServerNotification e)
 65  
     {
 66  0
         if (logEndpoint != null)
 67  
         {
 68  
             try
 69  
             {
 70  0
                 UMOMessage msg = new MuleMessage(e.toString(), (Map) null);
 71  0
                 UMOEvent event = new MuleEvent(msg, logEndpoint, session, false);
 72  0
                 logEndpoint.dispatch(event);
 73  
             }
 74  0
             catch (Exception e1)
 75  
             {
 76  
                 // TODO MULE-863: If this is an error, do something better than this
 77  0
                 logger.error("Failed to dispatch event: " + e.toString() + " over endpoint: " + logEndpoint
 78  
                              + ". Error is: " + e1.getMessage(), e1);
 79  0
             }
 80  
         }
 81  0
     }
 82  
 
 83  
     /**
 84  
      * Should be a 1 line description of the agent
 85  
      * 
 86  
      * @return
 87  
      */
 88  
     public String getDescription()
 89  
     {
 90  0
         StringBuffer buf = new StringBuffer();
 91  0
         buf.append(getName()).append(": ");
 92  0
         if (endpointAddress != null)
 93  
         {
 94  0
             buf.append("Forwarding notifications to: " + endpointAddress);
 95  
         }
 96  0
         return buf.toString();
 97  
     }
 98  
 
 99  
     public String getEndpointAddress()
 100  
     {
 101  0
         return endpointAddress;
 102  
     }
 103  
 
 104  
     public void setEndpointAddress(String endpointAddress)
 105  
     {
 106  0
         this.endpointAddress = endpointAddress;
 107  0
     }
 108  
 }