1 10 11 package org.mule.impl.internal.admin; 12 13 import org.apache.commons.lang.StringUtils; 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 import org.mule.MuleManager; 17 import org.mule.transformers.wire.WireFormat; 18 import org.mule.transformers.wire.SerializationWireFormat; 19 import org.mule.impl.AlreadyInitialisedException; 20 import org.mule.impl.endpoint.MuleEndpointURI; 21 import org.mule.providers.service.ConnectorFactory; 22 import org.mule.umo.UMODescriptor; 23 import org.mule.umo.UMOException; 24 import org.mule.umo.endpoint.UMOEndpointURI; 25 import org.mule.umo.lifecycle.InitialisationException; 26 import org.mule.umo.manager.UMOAgent; 27 import org.mule.umo.manager.UMOManager; 28 import org.mule.umo.provider.UMOConnector; 29 30 34 public class MuleAdminAgent implements UMOAgent 35 { 36 public static final String DEFAULT_MANAGER_ENDPOINT = "_muleManagerEndpoint"; 37 38 public static final String AGENT_NAME = "Mule Admin"; 39 40 43 protected static final Log logger = LogFactory.getLog(MuleAdminAgent.class); 44 45 private String serverEndpoint; 46 47 private WireFormat wireFormat; 48 49 54 public String getName() 55 { 56 return AGENT_NAME; 57 } 58 59 64 public void setName(String name) 65 { 66 } 68 69 74 public String getDescription() 75 { 76 return getName() + ": accepting connections on " + serverEndpoint; 77 } 78 79 public void start() throws UMOException 80 { 81 } 83 84 public void stop() throws UMOException 85 { 86 } 88 89 public void dispose() 90 { 91 } 93 94 public void registered() 95 { 96 } 98 99 public void unregistered() 100 { 101 } 103 104 public void initialise() throws InitialisationException 105 { 106 if (wireFormat == null) 107 { 108 wireFormat = new SerializationWireFormat(); 109 } 110 serverEndpoint = MuleManager.getConfiguration().getServerUrl(); 111 UMOManager manager = MuleManager.getInstance(); 112 113 try 114 { 115 if (StringUtils.isEmpty(serverEndpoint)) 116 { 117 logger.warn("No serverEndpointUrl specified, MuleAdminAgent will not start. E.g. use " 119 + "<mule-environment-properties serverUrl=\"tcp://example.com:60504\"/> "); 120 121 manager.unregisterAgent(this.getName()); 123 124 return; 125 } 126 127 if (manager.getModel().isComponentRegistered(MuleManagerComponent.MANAGER_COMPONENT_NAME)) 129 { 130 logger.info("Mule manager component has already been initialised, ignoring server url"); 131 } 132 else 133 { 134 if (manager.lookupConnector(DEFAULT_MANAGER_ENDPOINT) != null) 135 { 136 throw new AlreadyInitialisedException("Server Components", this); 137 } 138 139 serverEndpoint = MuleManager.getInstance().lookupEndpointIdentifier(serverEndpoint, 141 serverEndpoint); 142 UMOEndpointURI endpointUri = new MuleEndpointURI(serverEndpoint); 143 UMOConnector connector = ConnectorFactory.getOrCreateConnectorByProtocol(endpointUri); 144 if (manager.lookupConnector(connector.getName()) == null) 147 { 148 connector.setName(DEFAULT_MANAGER_ENDPOINT); 149 connector.initialise(); 150 manager.registerConnector(connector); 151 } 152 153 logger.info("Registering Admin listener on: " + serverEndpoint); 154 UMODescriptor descriptor = MuleManagerComponent.getDescriptor(connector, endpointUri, 155 wireFormat); 156 manager.getModel().registerComponent(descriptor); 157 } 158 } 159 catch (UMOException e) 160 { 161 throw new InitialisationException(e, this); 162 } 163 } 164 165 public String toString() 166 { 167 return "MuleAdminAgent{" + "serverEndpoint='" + serverEndpoint + "'" + "}"; 168 } 169 170 public WireFormat getWireFormat() 171 { 172 return wireFormat; 173 } 174 175 public void setWireFormat(WireFormat wireFormat) 176 { 177 this.wireFormat = wireFormat; 178 } 179 } 180 | Popular Tags |