1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.transport.ajax; |
11 | |
|
12 | |
import org.mule.api.MuleException; |
13 | |
import org.mule.api.endpoint.OutboundEndpoint; |
14 | |
import org.mule.api.transport.MessageDispatcher; |
15 | |
import org.mule.transport.AbstractMessageDispatcherFactory; |
16 | |
import org.mule.transport.ajax.container.AjaxServletConnector; |
17 | |
import org.mule.transport.ajax.embedded.AjaxConnector; |
18 | |
|
19 | |
import org.mortbay.cometd.AbstractBayeux; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | 0 | public class AjaxMessageDispatcherFactory extends AbstractMessageDispatcherFactory |
25 | |
{ |
26 | |
|
27 | |
public MessageDispatcher create(OutboundEndpoint endpoint) throws MuleException |
28 | |
{ |
29 | 0 | AjaxMessageDispatcher dispatcher = new AjaxMessageDispatcher(endpoint); |
30 | |
|
31 | 0 | if (endpoint.getConnector() instanceof AjaxConnector) |
32 | |
{ |
33 | |
|
34 | |
|
35 | 0 | dispatcher.setBayeux(((AjaxConnector) endpoint.getConnector()).getBayeux()); |
36 | |
} |
37 | |
else |
38 | |
{ |
39 | |
|
40 | |
|
41 | 0 | AbstractBayeux b = ((AjaxServletConnector) endpoint.getConnector()).getBayeux(); |
42 | 0 | if (b == null) |
43 | |
{ |
44 | 0 | long start = System.currentTimeMillis(); |
45 | |
|
46 | 0 | long timeout = start + endpoint.getResponseTimeout(); |
47 | 0 | while (start < timeout) |
48 | |
{ |
49 | |
try |
50 | |
{ |
51 | 0 | Thread.sleep(1000); |
52 | 0 | b = ((AjaxServletConnector) endpoint.getConnector()).getBayeux(); |
53 | 0 | if (b != null) |
54 | |
{ |
55 | 0 | break; |
56 | |
} |
57 | |
} |
58 | 0 | catch (InterruptedException e) |
59 | |
{ |
60 | |
|
61 | 0 | } |
62 | |
} |
63 | 0 | throw new IllegalArgumentException("Bayeux is null: " + endpoint.getConnector() + ". Waited for " + |
64 | |
endpoint.getResponseTimeout() + " for object to become availble, this usually caused if the servlet container takes a long time to start up"); |
65 | |
} |
66 | 0 | dispatcher.setBayeux(b); |
67 | |
} |
68 | |
|
69 | |
|
70 | 0 | return dispatcher; |
71 | |
} |
72 | |
} |