mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-11 23:51:09 +01:00
SMACK-363 Applied code cleanup patches for many generics related issues.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@13325 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
6dc64671e2
commit
e08c8afe44
109 changed files with 577 additions and 605 deletions
|
|
@ -54,7 +54,7 @@ public class BasicResolver extends TransportResolver {
|
|||
|
||||
clearCandidates();
|
||||
|
||||
Enumeration ifaces = null;
|
||||
Enumeration<NetworkInterface> ifaces = null;
|
||||
|
||||
try {
|
||||
ifaces = NetworkInterface.getNetworkInterfaces();
|
||||
|
|
@ -64,11 +64,11 @@ public class BasicResolver extends TransportResolver {
|
|||
|
||||
while (ifaces.hasMoreElements()) {
|
||||
|
||||
NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
|
||||
Enumeration iaddresses = iface.getInetAddresses();
|
||||
NetworkInterface iface = ifaces.nextElement();
|
||||
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
|
||||
|
||||
while (iaddresses.hasMoreElements()) {
|
||||
InetAddress iaddress = (InetAddress) iaddresses.nextElement();
|
||||
InetAddress iaddress = iaddresses.nextElement();
|
||||
if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress() && !iaddress.isSiteLocalAddress()) {
|
||||
TransportCandidate tr = new TransportCandidate.Fixed(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName(), getFreePort());
|
||||
tr.setLocalIp(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName());
|
||||
|
|
@ -87,11 +87,11 @@ public class BasicResolver extends TransportResolver {
|
|||
|
||||
while (ifaces.hasMoreElements()) {
|
||||
|
||||
NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
|
||||
Enumeration iaddresses = iface.getInetAddresses();
|
||||
NetworkInterface iface = ifaces.nextElement();
|
||||
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
|
||||
|
||||
while (iaddresses.hasMoreElements()) {
|
||||
InetAddress iaddress = (InetAddress) iaddresses.nextElement();
|
||||
InetAddress iaddress = iaddresses.nextElement();
|
||||
if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress()) {
|
||||
TransportCandidate tr = new TransportCandidate.Fixed(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName(), getFreePort());
|
||||
tr.setLocalIp(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName());
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ public class BridgedResolver extends TransportResolver {
|
|||
}
|
||||
|
||||
public static String getLocalHost() {
|
||||
Enumeration ifaces = null;
|
||||
Enumeration<NetworkInterface> ifaces = null;
|
||||
|
||||
try {
|
||||
ifaces = NetworkInterface.getNetworkInterfaces();
|
||||
|
|
@ -125,11 +125,11 @@ public class BridgedResolver extends TransportResolver {
|
|||
|
||||
while (ifaces.hasMoreElements()) {
|
||||
|
||||
NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
|
||||
Enumeration iaddresses = iface.getInetAddresses();
|
||||
NetworkInterface iface = ifaces.nextElement();
|
||||
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
|
||||
|
||||
while (iaddresses.hasMoreElements()) {
|
||||
InetAddress iaddress = (InetAddress) iaddresses.nextElement();
|
||||
InetAddress iaddress = iaddresses.nextElement();
|
||||
if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress() && !iaddress.isSiteLocalAddress() && !(iaddress instanceof Inet6Address)) {
|
||||
return iaddress.getHostAddress();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ import org.jivesoftware.smackx.jingle.SmackLogger;
|
|||
*
|
||||
* @author Thiago Camargo
|
||||
*/
|
||||
public class ICECandidate extends TransportCandidate implements Comparable {
|
||||
public class ICECandidate extends TransportCandidate implements Comparable<ICECandidate> {
|
||||
|
||||
private static final SmackLogger LOGGER = SmackLogger.getLogger(ICECandidate.class);
|
||||
|
||||
|
|
@ -438,18 +438,14 @@ public class ICECandidate extends TransportCandidate implements Comparable {
|
|||
* object is less than, equal to, or greater than the specified
|
||||
* object
|
||||
*/
|
||||
public int compareTo(Object arg) {
|
||||
if (arg instanceof ICECandidate) {
|
||||
ICECandidate tc = (ICECandidate) arg;
|
||||
if (getPreference() < tc.getPreference()) {
|
||||
return -1;
|
||||
}
|
||||
else if (getPreference() > tc.getPreference()) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public int compareTo(ICECandidate arg) {
|
||||
if (getPreference() < arg.getPreference()) {
|
||||
return -1;
|
||||
} else if (getPreference() > arg.getPreference()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ public class ICEResolver extends TransportResolver {
|
|||
i++;
|
||||
}
|
||||
} catch (SocketException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +224,7 @@ public class ICEResolver extends TransportResolver {
|
|||
|
||||
if (publicIp != null && !publicIp.equals("")) {
|
||||
|
||||
Enumeration ifaces = null;
|
||||
Enumeration<NetworkInterface> ifaces = null;
|
||||
|
||||
try {
|
||||
ifaces = NetworkInterface.getNetworkInterfaces();
|
||||
|
|
@ -240,11 +239,11 @@ public class ICEResolver extends TransportResolver {
|
|||
|
||||
while (ifaces.hasMoreElements() && !false) {
|
||||
|
||||
NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
|
||||
Enumeration iaddresses = iface.getInetAddresses();
|
||||
NetworkInterface iface = ifaces.nextElement();
|
||||
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
|
||||
|
||||
while (iaddresses.hasMoreElements()) {
|
||||
InetAddress iaddress = (InetAddress) iaddresses.nextElement();
|
||||
InetAddress iaddress = iaddresses.nextElement();
|
||||
if (iaddress.getHostAddress().indexOf(publicIp) > -1) {
|
||||
found = true;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -442,9 +442,9 @@ public class RTPBridge extends IQ {
|
|||
// }
|
||||
|
||||
DiscoverInfo discoInfo = disco.discoverInfo(connection.getServiceName());
|
||||
Iterator iter = discoInfo.getIdentities();
|
||||
Iterator<DiscoverInfo.Identity> iter = discoInfo.getIdentities();
|
||||
while (iter.hasNext()) {
|
||||
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) iter.next();
|
||||
DiscoverInfo.Identity identity = iter.next();
|
||||
if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -528,7 +528,7 @@ public class RTPBridge extends IQ {
|
|||
|
||||
if (response.getIp() == null || response.getIp().equals("")) return null;
|
||||
|
||||
Enumeration ifaces = null;
|
||||
Enumeration<NetworkInterface> ifaces = null;
|
||||
try {
|
||||
ifaces = NetworkInterface.getNetworkInterfaces();
|
||||
}
|
||||
|
|
@ -537,11 +537,11 @@ public class RTPBridge extends IQ {
|
|||
}
|
||||
while (ifaces!=null&&ifaces.hasMoreElements()) {
|
||||
|
||||
NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
|
||||
Enumeration iaddresses = iface.getInetAddresses();
|
||||
NetworkInterface iface = ifaces.nextElement();
|
||||
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
|
||||
|
||||
while (iaddresses.hasMoreElements()) {
|
||||
InetAddress iaddress = (InetAddress) iaddresses.nextElement();
|
||||
InetAddress iaddress = iaddresses.nextElement();
|
||||
if (!iaddress.isLoopbackAddress())
|
||||
if (iaddress.getHostAddress().indexOf(response.getIp()) >= 0)
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -230,9 +230,9 @@ public class STUN extends IQ {
|
|||
try {
|
||||
DiscoverItems items = disco.discoverItems(connection.getServiceName());
|
||||
|
||||
Iterator iter = items.getItems();
|
||||
Iterator<DiscoverItems.Item> iter = items.getItems();
|
||||
while (iter.hasNext()) {
|
||||
DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
|
||||
DiscoverItems.Item item = iter.next();
|
||||
DiscoverInfo info = disco.discoverInfo(item.getEntityID());
|
||||
|
||||
Iterator<DiscoverInfo.Identity> iter2 = info.getIdentities();
|
||||
|
|
|
|||
|
|
@ -134,8 +134,8 @@ public class STUNResolver extends TransportResolver {
|
|||
* @param stunConfigStream An InputStream with the configuration file.
|
||||
* @return A list of loaded servers
|
||||
*/
|
||||
public ArrayList loadSTUNServers(java.io.InputStream stunConfigStream) {
|
||||
ArrayList serversList = new ArrayList();
|
||||
public ArrayList<STUNService> loadSTUNServers(java.io.InputStream stunConfigStream) {
|
||||
ArrayList<STUNService> serversList = new ArrayList<STUNService>();
|
||||
String serverName;
|
||||
int serverPort;
|
||||
|
||||
|
|
@ -216,8 +216,8 @@ public class STUNResolver extends TransportResolver {
|
|||
*
|
||||
* @return a list of services
|
||||
*/
|
||||
public ArrayList loadSTUNServers() {
|
||||
ArrayList serversList = new ArrayList();
|
||||
public ArrayList<STUNService> loadSTUNServers() {
|
||||
ArrayList<STUNService> serversList = new ArrayList<STUNService>();
|
||||
|
||||
// Load the STUN configuration
|
||||
try {
|
||||
|
|
@ -228,11 +228,11 @@ public class STUNResolver extends TransportResolver {
|
|||
classLoaders[1] = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
for (int i = 0; i < classLoaders.length; i++) {
|
||||
Enumeration stunConfigEnum = classLoaders[i]
|
||||
Enumeration<URL> stunConfigEnum = classLoaders[i]
|
||||
.getResources(STUNSERVERS_FILENAME);
|
||||
|
||||
while (stunConfigEnum.hasMoreElements() && serversList.isEmpty()) {
|
||||
URL url = (URL) stunConfigEnum.nextElement();
|
||||
URL url = stunConfigEnum.nextElement();
|
||||
java.io.InputStream stunConfigStream = null;
|
||||
|
||||
stunConfigStream = url.openStream();
|
||||
|
|
@ -253,12 +253,12 @@ public class STUNResolver extends TransportResolver {
|
|||
*
|
||||
* @return the best STUN server that can be used.
|
||||
*/
|
||||
private STUNService bestSTUNServer(ArrayList listServers) {
|
||||
private STUNService bestSTUNServer(ArrayList<STUNService> listServers) {
|
||||
if (listServers.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
// TODO: this should use some more advanced criteria...
|
||||
return (STUNService) listServers.get(0);
|
||||
return listServers.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -305,19 +305,17 @@ public class STUNResolver extends TransportResolver {
|
|||
// Iterate through the list of interfaces, and ask
|
||||
// to the STUN server for our address.
|
||||
try {
|
||||
Enumeration ifaces = NetworkInterface.getNetworkInterfaces();
|
||||
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
|
||||
String candAddress;
|
||||
int candPort;
|
||||
|
||||
while (ifaces.hasMoreElements()) {
|
||||
|
||||
NetworkInterface iface = (NetworkInterface) ifaces
|
||||
.nextElement();
|
||||
Enumeration iaddresses = iface.getInetAddresses();
|
||||
NetworkInterface iface = ifaces.nextElement();
|
||||
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
|
||||
|
||||
while (iaddresses.hasMoreElements()) {
|
||||
InetAddress iaddress = (InetAddress) iaddresses
|
||||
.nextElement();
|
||||
InetAddress iaddress = iaddresses.nextElement();
|
||||
if (!iaddress.isLoopbackAddress()
|
||||
&& !iaddress.isLinkLocalAddress()) {
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ import java.util.List;
|
|||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.SmackLogger;
|
||||
import org.jivesoftware.smackx.jingle.nat.TransportResolverListener.Checker;
|
||||
|
||||
/**
|
||||
* Transport candidate.
|
||||
|
|
@ -103,7 +104,7 @@ public abstract class TransportCandidate {
|
|||
private Thread echoThread = null;
|
||||
|
||||
// Listeners for events
|
||||
private final List<TransportResolverListener.Checker> listeners = new ArrayList();
|
||||
private final List<TransportResolverListener.Checker> listeners = new ArrayList<Checker>();
|
||||
|
||||
public void addCandidateEcho(JingleSession session) throws SocketException, UnknownHostException {
|
||||
candidateEcho = new CandidateEcho(this, session);
|
||||
|
|
@ -387,9 +388,9 @@ public abstract class TransportCandidate {
|
|||
public void run() {
|
||||
boolean isUsable;
|
||||
|
||||
InetAddress candAddress;
|
||||
|
||||
try {
|
||||
candAddress = InetAddress.getByName(getIp());
|
||||
InetAddress candAddress = InetAddress.getByName(getIp());
|
||||
isUsable = true;//candAddress.isReachable(TransportResolver.CHECK_TIMEOUT);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
@ -425,7 +426,7 @@ public abstract class TransportCandidate {
|
|||
*/
|
||||
public List<TransportResolverListener.Checker> getListenersList() {
|
||||
synchronized (listeners) {
|
||||
return new ArrayList(listeners);
|
||||
return new ArrayList<Checker>(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -449,9 +449,9 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
*
|
||||
* @return The list of valid (ie, already checked) remote candidates.
|
||||
*/
|
||||
final ArrayList getValidRemoteCandidatesList() {
|
||||
final ArrayList<TransportCandidate> getValidRemoteCandidatesList() {
|
||||
synchronized (validRemoteCandidates) {
|
||||
return new ArrayList(validRemoteCandidates);
|
||||
return new ArrayList<TransportCandidate>(validRemoteCandidates);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -461,7 +461,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
* @return The iterator for the list of valid (ie, already checked) remote
|
||||
* candidates.
|
||||
*/
|
||||
public final Iterator getValidRemoteCandidates() {
|
||||
public final Iterator<TransportCandidate> getValidRemoteCandidates() {
|
||||
return Collections.unmodifiableList(getRemoteCandidates()).iterator();
|
||||
}
|
||||
|
||||
|
|
@ -471,11 +471,11 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
*
|
||||
* @param rc the remote candidate to add.
|
||||
*/
|
||||
private void addRemoteCandidates(List rc) {
|
||||
private void addRemoteCandidates(List<TransportCandidate> rc) {
|
||||
if (rc != null) {
|
||||
if (rc.size() > 0) {
|
||||
for (Object aRc : rc) {
|
||||
addRemoteCandidate((TransportCandidate) aRc);
|
||||
for (TransportCandidate aRc : rc) {
|
||||
addRemoteCandidate(aRc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -829,7 +829,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
*/
|
||||
public TransportCandidate getBestRemoteCandidate() {
|
||||
// Hopefully, we only have one validRemoteCandidate
|
||||
ArrayList cands = getValidRemoteCandidatesList();
|
||||
ArrayList<TransportCandidate> cands = getValidRemoteCandidatesList();
|
||||
if (!cands.isEmpty()) {
|
||||
LOGGER.debug("RAW CAND");
|
||||
return (TransportCandidate) cands.get(0);
|
||||
|
|
@ -883,14 +883,17 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
public TransportCandidate getBestRemoteCandidate() {
|
||||
ICECandidate result = null;
|
||||
|
||||
ArrayList<ICECandidate> cands = getValidRemoteCandidatesList();
|
||||
ArrayList<TransportCandidate> cands = getValidRemoteCandidatesList();
|
||||
if (!cands.isEmpty()) {
|
||||
int highest = -1;
|
||||
ICECandidate chose = null;
|
||||
for (ICECandidate transportCandidate : cands) {
|
||||
if (transportCandidate.getPreference() > highest) {
|
||||
chose = transportCandidate;
|
||||
highest = transportCandidate.getPreference();
|
||||
for (TransportCandidate transportCandidate : cands) {
|
||||
if (transportCandidate instanceof ICECandidate) {
|
||||
ICECandidate icecandidate = (ICECandidate) transportCandidate;
|
||||
if (icecandidate.getPreference() > highest) {
|
||||
chose = icecandidate;
|
||||
highest = icecandidate.getPreference();
|
||||
}
|
||||
}
|
||||
}
|
||||
result = chose;
|
||||
|
|
|
|||
|
|
@ -233,9 +233,9 @@ public abstract class TransportResolver {
|
|||
*
|
||||
* @return the list of listeners
|
||||
*/
|
||||
public ArrayList getListenersList() {
|
||||
public ArrayList<TransportResolverListener> getListenersList() {
|
||||
synchronized (listeners) {
|
||||
return new ArrayList(listeners);
|
||||
return new ArrayList<TransportResolverListener>(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -245,9 +245,9 @@ public abstract class TransportResolver {
|
|||
* @param cand The candidate added to the list of candidates.
|
||||
*/
|
||||
protected void triggerCandidateAdded(TransportCandidate cand) {
|
||||
Iterator iter = getListenersList().iterator();
|
||||
Iterator<TransportResolverListener> iter = getListenersList().iterator();
|
||||
while (iter.hasNext()) {
|
||||
TransportResolverListener trl = (TransportResolverListener) iter.next();
|
||||
TransportResolverListener trl = iter.next();
|
||||
if (trl instanceof TransportResolverListener.Resolver) {
|
||||
TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl;
|
||||
LOGGER.debug("triggerCandidateAdded : " + cand.getLocalIp());
|
||||
|
|
@ -260,9 +260,9 @@ public abstract class TransportResolver {
|
|||
* Trigger a event notifying the initialization of the resolution process.
|
||||
*/
|
||||
private void triggerResolveInit() {
|
||||
Iterator iter = getListenersList().iterator();
|
||||
Iterator<TransportResolverListener> iter = getListenersList().iterator();
|
||||
while (iter.hasNext()) {
|
||||
TransportResolverListener trl = (TransportResolverListener) iter.next();
|
||||
TransportResolverListener trl = iter.next();
|
||||
if (trl instanceof TransportResolverListener.Resolver) {
|
||||
TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl;
|
||||
li.init();
|
||||
|
|
@ -274,9 +274,9 @@ public abstract class TransportResolver {
|
|||
* Trigger a event notifying the obtention of all the candidates.
|
||||
*/
|
||||
private void triggerResolveEnd() {
|
||||
Iterator iter = getListenersList().iterator();
|
||||
Iterator<TransportResolverListener> iter = getListenersList().iterator();
|
||||
while (iter.hasNext()) {
|
||||
TransportResolverListener trl = (TransportResolverListener) iter.next();
|
||||
TransportResolverListener trl = iter.next();
|
||||
if (trl instanceof TransportResolverListener.Resolver) {
|
||||
TransportResolverListener.Resolver li = (TransportResolverListener.Resolver) trl;
|
||||
li.end();
|
||||
|
|
@ -315,9 +315,9 @@ public abstract class TransportResolver {
|
|||
*
|
||||
* @return an iterator
|
||||
*/
|
||||
public Iterator getCandidates() {
|
||||
public Iterator<TransportCandidate> getCandidates() {
|
||||
synchronized (candidates) {
|
||||
return Collections.unmodifiableList(new ArrayList(candidates)).iterator();
|
||||
return Collections.unmodifiableList(new ArrayList<TransportCandidate>(candidates)).iterator();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -329,7 +329,13 @@ public abstract class TransportResolver {
|
|||
public TransportCandidate getPreferredCandidate() {
|
||||
TransportCandidate result = null;
|
||||
|
||||
ArrayList cands = (ArrayList) getCandidatesList();
|
||||
ArrayList<ICECandidate> cands = new ArrayList<ICECandidate>();
|
||||
for (TransportCandidate tpcan : getCandidatesList()) {
|
||||
if (tpcan instanceof ICECandidate)
|
||||
cands.add((ICECandidate) tpcan);
|
||||
}
|
||||
|
||||
// (ArrayList<ICECandidate>) getCandidatesList();
|
||||
if (cands.size() > 0) {
|
||||
Collections.sort(cands);
|
||||
// Return the last candidate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue