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