Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c4fdc2d5803a676d0fb09629cf66f093ec0c660b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.jivesoftware.smackx.nat;

import org.jivesoftware.smack.XMPPException;

/**
 * Specialization of the BasicResolver. The FixedResolver is a resolver where
 * the external address and port are previously known when the object is
 * initialized.
 * 
 * @author Alvaro Saurin <alvaro.saurin@gmail.com>
 */
public class FixedResolver extends BasicResolver {

	TransportCandidate fixedCandidate;

	/**
	 * Constructor.
	 */
	public FixedResolver(final String ip, final int port) {
		super();
		setFixedCandidate(ip, port);
	}

	/**
	 * Create a basic resolver, where we provide the IP and port.
	 * 
	 * @param ip an IP address
	 * @param port a port
	 */
	public void setFixedCandidate(final String ip, final int port) {
		fixedCandidate = new TransportCandidate.Fixed(ip, port);
	}

	/**
	 * Resolve the IP address.
	 */
	public synchronized void resolve() throws XMPPException {

		if (!isResolving()) {
			setResolveInit();

			clearCandidates();

			if (fixedCandidate != null) {
				addCandidate(fixedCandidate);
			}

			setResolveEnd();
		}
	}
}

Back to the top