001/** 002 * 003 * Copyright 2003-2006 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.jingleold.nat; 018 019import org.jivesoftware.smack.SmackException.NotConnectedException; 020import org.jivesoftware.smack.XMPPException; 021import org.jivesoftware.smackx.jingleold.JingleSession; 022 023/** 024 * The FixedResolver is a resolver where 025 * the external address and port are previously known when the object is 026 * initialized. 027 * 028 * @author Alvaro Saurin <alvaro.saurin@gmail.com> 029 */ 030public class FixedResolver extends TransportResolver { 031 032 TransportCandidate fixedCandidate; 033 034 /** 035 * Constructor. 036 */ 037 public FixedResolver(String ip, int port) { 038 super(); 039 setFixedCandidate(ip, port); 040 } 041 042 /** 043 * Create a basic resolver, where we provide the IP and port. 044 * 045 * @param ip an IP address 046 * @param port a port 047 */ 048 public void setFixedCandidate(String ip, int port) { 049 fixedCandidate = new TransportCandidate.Fixed(ip, port); 050 } 051 052 /** 053 * Resolve the IP address. 054 * @throws NotConnectedException 055 * @throws InterruptedException 056 */ 057 @Override 058 public synchronized void resolve(JingleSession session) throws XMPPException, NotConnectedException, InterruptedException { 059 if (!isResolving()) { 060 setResolveInit(); 061 062 clearCandidates(); 063 064 if (fixedCandidate.getLocalIp() == null) 065 fixedCandidate.setLocalIp(fixedCandidate.getIp()); 066 067 if (fixedCandidate != null) { 068 addCandidate(fixedCandidate); 069 } 070 071 setResolveEnd(); 072 } 073 } 074 075 /** 076 * Initialize the resolver. 077 * 078 * @throws XMPPException 079 */ 080 @Override 081 public void initialize() throws XMPPException { 082 setInitialized(); 083 } 084 085 @Override 086 public void cancel() throws XMPPException { 087 // Nothing to do here 088 } 089}