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