1
2
3
4
5
6
7 package org.mule.module.client.remoting;
8
9 import org.mule.AbstractAgent;
10 import org.mule.api.MuleException;
11 import org.mule.api.endpoint.InboundEndpoint;
12 import org.mule.api.lifecycle.InitialisationException;
13 import org.mule.api.service.Service;
14 import org.mule.api.transformer.wire.WireFormat;
15 import org.mule.config.i18n.CoreMessages;
16 import org.mule.module.client.remoting.notification.RemoteDispatcherNotification;
17 import org.mule.module.client.remoting.notification.RemoteDispatcherNotificationListener;
18 import org.mule.transformer.wire.SerializedMuleMessageWireFormat;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23
24
25
26
27 public class RemoteDispatcherAgent extends AbstractAgent
28 {
29 public static final String AGENT_NAME = "RemoteDispatcherServer";
30
31
32
33
34 protected static final Log logger = LogFactory.getLog(RemoteDispatcherAgent.class);
35
36 private WireFormat wireFormat;
37
38 private InboundEndpoint endpoint;
39
40
41 public RemoteDispatcherAgent()
42 {
43 super(AGENT_NAME);
44 }
45
46
47
48
49 public String getDescription()
50 {
51 return getName() + ": accepting connections on " + endpoint.getEndpointURI().getAddress();
52 }
53
54 public void start() throws MuleException
55 {
56
57 }
58
59 public void stop() throws MuleException
60 {
61
62 }
63
64 public void dispose()
65 {
66
67 }
68
69
70 public void initialise() throws InitialisationException
71 {
72 if (endpoint == null)
73 {
74 throw new IllegalArgumentException(CoreMessages.objectIsNull("remote-endpoint").getMessage());
75 }
76
77 if (wireFormat == null)
78 {
79 wireFormat = new SerializedMuleMessageWireFormat();
80 }
81 wireFormat.setMuleContext(muleContext);
82
83
84
85 muleContext.getNotificationManager().addInterfaceToType(
86 RemoteDispatcherNotificationListener.class,
87 RemoteDispatcherNotification.class);
88
89 try
90 {
91
92 if (muleContext.getRegistry().lookupService(RemoteDispatcherComponent.MANAGER_COMPONENT_NAME) != null)
93 {
94 logger.info("Mule manager component has already been initialised, ignoring server url");
95 }
96 else
97 {
98
99 Service component = RemoteDispatcherComponent.getSerivce(endpoint, wireFormat,
100 muleContext.getConfiguration().getDefaultEncoding(), muleContext.getConfiguration()
101 .getDefaultResponseTimeout(), muleContext);
102 muleContext.getRegistry().registerService(component);
103 }
104 }
105 catch (MuleException e)
106 {
107 throw new InitialisationException(e, this);
108 }
109 }
110
111 public String toString()
112 {
113 String address = "not set";
114 if(endpoint!=null)
115 {
116 address = endpoint.getEndpointURI().getAddress();
117 }
118 return "RemoteDispatcherAgent{" + "remote-endpoint='" + address + "'" + "}";
119 }
120
121 public WireFormat getWireFormat()
122 {
123 return wireFormat;
124 }
125
126 public void setWireFormat(WireFormat wireFormat)
127 {
128 this.wireFormat = wireFormat;
129 }
130
131 public InboundEndpoint getEndpoint()
132 {
133 return endpoint;
134 }
135
136 public void setEndpoint(InboundEndpoint endpoint)
137 {
138 this.endpoint = endpoint;
139 }
140 }