1 10 11 package org.mule.management.mbeans; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.config.i18n.Message; 16 import org.mule.config.i18n.Messages; 17 import org.mule.umo.endpoint.UMOEndpoint; 18 import org.mule.umo.provider.UMOMessageReceiver; 19 import org.mule.util.ObjectNameHelper; 20 21 28 public class EndpointService implements EndpointServiceMBean 29 { 30 33 protected transient Log logger = LogFactory.getLog(getClass()); 34 35 private UMOEndpoint endpoint; 36 private UMOMessageReceiver receiver; 37 private String name; 38 private String componentName; 39 40 public EndpointService(UMOEndpoint endpoint) 41 { 42 this.endpoint = endpoint; 43 init(); 44 } 45 46 public EndpointService(UMOMessageReceiver receiver) 47 { 48 if (receiver == null) 49 { 50 throw new NullPointerException (new Message(Messages.X_IS_NULL, "Receiver").getMessage()); 51 } 52 this.endpoint = receiver.getEndpoint(); 53 this.receiver = receiver; 54 this.componentName = receiver.getComponent().getDescriptor().getName(); 55 init(); 56 } 57 58 private void init() 59 { 60 if (endpoint == null) 61 { 62 throw new NullPointerException (new Message(Messages.X_IS_NULL, "Endpoint").getMessage()); 63 } 64 if (receiver == null && !UMOEndpoint.ENDPOINT_TYPE_RECEIVER.equals(endpoint.getType())) 65 { 66 throw new IllegalArgumentException ( 67 "Recevier is null for Endpoint MBean but the endpoint itself is a receiving endpoint"); 68 } 69 70 name = ObjectNameHelper.getEndpointName(endpoint); 71 72 } 73 74 public String getAddress() 75 { 76 return endpoint.getEndpointURI().getAddress(); 77 } 78 79 public String getName() 80 { 81 return name; 82 } 83 84 public boolean isConnected() 85 { 86 return receiver == null || receiver.isConnected(); 87 } 88 89 public void connect() throws Exception 90 { 91 if (receiver != null && !receiver.isConnected()) 92 { 93 receiver.connect(); 94 } 95 else if (logger.isDebugEnabled()) 96 { 97 logger.debug("Endpoint is already connected"); 98 } 99 } 100 101 public void disconnect() throws Exception 102 { 103 if (receiver != null && receiver.isConnected()) 104 { 105 receiver.disconnect(); 106 } 107 else if (logger.isDebugEnabled()) 108 { 109 logger.debug("Endpoint is already disconnected"); 110 } 111 } 112 113 public boolean isSynchronous() 114 { 115 return endpoint.isSynchronous(); 116 } 117 118 public String getType() 119 { 120 return endpoint.getType(); 121 } 122 123 public String getComponentName() 124 { 125 return componentName; 126 } 127 128 public void setComponentName(String componentName) 129 { 130 this.componentName = componentName; 131 } 132 133 } 134 | Popular Tags |