From 522d0f30ff86bd8d8c523424ac35efdb3ef5da23 Mon Sep 17 00:00:00 2001 From: Vyacheslav Blinov Date: Fri, 15 Aug 2014 12:49:05 +0400 Subject: [PATCH] Generify Packet class returned by PackageCollector everywhere This will help to get rid of repetitive class casts, and make PacketCollector api more inline with itself (since some methods are already generic return methods). --- .../java/org/jivesoftware/smack/PacketCollector.java | 12 +++++++----- .../smackx/offline/OfflineMessageManager.java | 8 ++++---- .../jivesoftware/smackx/jingle/nat/RTPBridge.java | 6 +++--- .../org/jivesoftware/smackx/jingle/nat/STUN.java | 2 +- .../smackx/workgroup/agent/AgentSession.java | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java b/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java index fd952d687..c95ffda6c 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java @@ -103,8 +103,9 @@ public class PacketCollector { * @return the next packet result, or null if there are no more * results. */ - public Packet pollResult() { - return resultQueue.poll(); + @SuppressWarnings("unchecked") + public

P pollResult() { + return (P) resultQueue.poll(); } /** @@ -113,9 +114,10 @@ public class PacketCollector { * * @return the next available packet. */ - public Packet nextResultBlockForever() { + @SuppressWarnings("unchecked") + public

P nextResultBlockForever() { try { - return resultQueue.take(); + return (P) resultQueue.take(); } catch (InterruptedException e) { throw new RuntimeException(e); @@ -128,7 +130,7 @@ public class PacketCollector { * * @return the next availabe packet. */ - public Packet nextResult() { + public

P nextResult() { return nextResult(connection.getPacketReplyTimeout()); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java index b62172140..709a55052 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java @@ -157,10 +157,10 @@ public class OfflineMessageManager { try { connection.createPacketCollectorAndSend(request).nextResultOrThrow(); // Collect the received offline messages - Message message = (Message) messageCollector.nextResult(); + Message message = messageCollector.nextResult(); while (message != null) { messages.add(message); - message = (Message) messageCollector.nextResult(); + message = messageCollector.nextResult(); } } finally { @@ -191,10 +191,10 @@ public class OfflineMessageManager { try { // Collect the received offline messages - Message message = (Message) messageCollector.nextResult(); + Message message = messageCollector.nextResult(); while (message != null) { messages.add(message); - message = (Message) messageCollector.nextResult(); + message = messageCollector.nextResult(); } resultCollector.nextResultOrThrow(); } diff --git a/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/nat/RTPBridge.java b/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/nat/RTPBridge.java index 764f54fe0..1197f44e3 100644 --- a/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/nat/RTPBridge.java +++ b/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/nat/RTPBridge.java @@ -396,7 +396,7 @@ public class RTPBridge extends IQ { PacketCollector collector = connection.createPacketCollectorAndSend(rtpPacket); - RTPBridge response = (RTPBridge) collector.nextResult(); + RTPBridge response = collector.nextResult(); // Cancel the collector. collector.cancel(); @@ -470,7 +470,7 @@ public class RTPBridge extends IQ { PacketCollector collector = connection.createPacketCollectorAndSend(rtpPacket); - RTPBridge response = (RTPBridge) collector.nextResult(); + RTPBridge response = collector.nextResult(); // Cancel the collector. collector.cancel(); @@ -499,7 +499,7 @@ public class RTPBridge extends IQ { PacketCollector collector = xmppConnection.createPacketCollectorAndSend(rtpPacket); - RTPBridge response = (RTPBridge) collector.nextResult(); + RTPBridge response = collector.nextResult(); // Cancel the collector. collector.cancel(); diff --git a/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/nat/STUN.java b/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/nat/STUN.java index ee8420294..1db835070 100644 --- a/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/nat/STUN.java +++ b/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/nat/STUN.java @@ -194,7 +194,7 @@ public class STUN extends IQ { PacketCollector collector = connection.createPacketCollectorAndSend(stunPacket); - STUN response = (STUN) collector.nextResult(); + STUN response = collector.nextResult(); // Cancel the collector. collector.cancel(); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java index 3d707ed58..cb1d77f28 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java @@ -827,7 +827,7 @@ public class AgentSession { request.setType(IQ.Type.get); request.setTo(workgroupJID); - AgentChatHistory response = (AgentChatHistory) connection.createPacketCollectorAndSend( + AgentChatHistory response = connection.createPacketCollectorAndSend( request).nextResult(); return response; @@ -901,7 +901,7 @@ public class AgentSession { request.setTo(workgroupJID); request.setSessionID(sessionID); - ChatMetadata response = (ChatMetadata) connection.createPacketCollectorAndSend(request).nextResult(); + ChatMetadata response = connection.createPacketCollectorAndSend(request).nextResult(); return response.getMetadata(); }