1 10 11 package org.mule.impl.internal.admin; 12 13 import org.mule.config.i18n.Message; 14 import org.mule.config.i18n.Messages; 15 import org.mule.impl.MuleEvent; 16 import org.mule.impl.MuleMessage; 17 import org.mule.impl.MuleSession; 18 import org.mule.impl.NullSessionHandler; 19 import org.mule.impl.endpoint.MuleEndpoint; 20 import org.mule.providers.NullPayload; 21 import org.mule.umo.UMOEvent; 22 import org.mule.umo.UMOMessage; 23 import org.mule.umo.UMOSession; 24 import org.mule.umo.endpoint.UMOEndpoint; 25 import org.mule.umo.lifecycle.InitialisationException; 26 import org.mule.umo.manager.UMOServerNotification; 27 import org.mule.umo.provider.UMOMessageDispatcher; 28 29 import java.util.Map ; 30 31 38 public class EndpointNotificationLoggerAgent extends AbstractNotificationLoggerAgent 39 { 40 41 private String endpointAddress; 42 private UMOEndpoint logEndpoint = null; 43 private UMOSession session; 44 45 protected void doInitialise() throws InitialisationException 46 { 47 try 49 { 50 if (endpointAddress != null) 51 { 52 logEndpoint = MuleEndpoint.getOrCreateEndpointForUri(endpointAddress, 53 UMOEndpoint.ENDPOINT_TYPE_SENDER); 54 } 55 else 56 { 57 throw new InitialisationException(new Message(Messages.PROPERTIES_X_NOT_SET, 58 "endpointAddress"), this); 59 } 60 session = new MuleSession(new MuleMessage(new NullPayload(), (Map )null), new NullSessionHandler()); 62 } 63 catch (Exception e) 64 { 65 throw new InitialisationException(e, this); 66 } 67 } 68 69 protected void logEvent(UMOServerNotification e) 70 { 71 if (logEndpoint != null) 72 { 73 try 74 { 75 UMOMessageDispatcher dispatcher = logEndpoint.getConnector().getDispatcher(logEndpoint); 76 UMOMessage msg = new MuleMessage(e.toString(), (Map )null); 77 UMOEvent event = new MuleEvent(msg, logEndpoint, session, false); 78 dispatcher.dispatch(event); 79 } 80 catch (Exception e1) 81 { 82 logger.error("Failed to dispatch event: " + e.toString() + " over endpoint: " + logEndpoint 83 + ". Error is: " + e1.getMessage(), e1); 84 } 85 } 86 } 87 88 93 public String getDescription() 94 { 95 StringBuffer buf = new StringBuffer (); 96 buf.append(getName()).append(": "); 97 if (endpointAddress != null) 98 { 99 buf.append("Forwarding notifications to: " + endpointAddress); 100 } 101 return buf.toString(); 102 } 103 104 public String getEndpointAddress() 105 { 106 return endpointAddress; 107 } 108 109 public void setEndpointAddress(String endpointAddress) 110 { 111 this.endpointAddress = endpointAddress; 112 } 113 } 114 | Popular Tags |