1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.xmpp; |
8 | |
|
9 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
10 | |
import org.mule.transport.ConnectException; |
11 | |
|
12 | |
import org.apache.commons.logging.Log; |
13 | |
import org.apache.commons.logging.LogFactory; |
14 | |
import org.jivesoftware.smack.PacketCollector; |
15 | |
import org.jivesoftware.smack.XMPPConnection; |
16 | |
import org.jivesoftware.smack.filter.PacketFilter; |
17 | |
import org.jivesoftware.smack.packet.Message; |
18 | |
|
19 | |
|
20 | |
public abstract class AbstractXmppConversation implements XmppConversation |
21 | |
{ |
22 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
23 | |
|
24 | |
protected XMPPConnection connection; |
25 | |
protected String recipient; |
26 | |
protected PacketCollector packetCollector; |
27 | |
|
28 | |
public AbstractXmppConversation(ImmutableEndpoint endpoint) |
29 | |
{ |
30 | 0 | super(); |
31 | 0 | connection = ((XmppConnector) endpoint.getConnector()).getXmppConnection(); |
32 | 0 | recipient = XmppConnector.getRecipient(endpoint); |
33 | 0 | } |
34 | |
|
35 | |
public void connect() throws ConnectException |
36 | |
{ |
37 | 0 | doConnect(); |
38 | 0 | packetCollector = createPacketCollector(); |
39 | 0 | } |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
protected void doConnect() throws ConnectException |
45 | |
{ |
46 | |
|
47 | 0 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
protected PacketCollector createPacketCollector() |
54 | |
{ |
55 | 0 | PacketFilter filter = createPacketFilter(); |
56 | 0 | return connection.createPacketCollector(filter); |
57 | |
} |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
protected PacketFilter createPacketFilter() |
64 | |
{ |
65 | 0 | return null; |
66 | |
} |
67 | |
|
68 | |
public void disconnect() |
69 | |
{ |
70 | 0 | if (packetCollector != null) |
71 | |
{ |
72 | 0 | packetCollector.cancel(); |
73 | |
} |
74 | |
|
75 | 0 | doDisconnect(); |
76 | 0 | } |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
protected void doDisconnect() |
82 | |
{ |
83 | |
|
84 | 0 | } |
85 | |
|
86 | |
public Message receive(long timeout) |
87 | |
{ |
88 | |
|
89 | |
|
90 | 0 | return (Message) packetCollector.nextResult(timeout); |
91 | |
} |
92 | |
|
93 | |
public Message receive() |
94 | |
{ |
95 | |
|
96 | |
|
97 | 0 | return (Message) packetCollector.nextResult(); |
98 | |
} |
99 | |
} |