1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 10:37:59 +01:00

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).
This commit is contained in:
Vyacheslav Blinov 2014-08-15 12:49:05 +04:00 committed by Florian Schmaus
parent b3b0e02ae1
commit 522d0f30ff
5 changed files with 17 additions and 15 deletions

View file

@ -103,8 +103,9 @@ public class PacketCollector {
* @return the next packet result, or <tt>null</tt> if there are no more
* results.
*/
public Packet pollResult() {
return resultQueue.poll();
@SuppressWarnings("unchecked")
public <P extends Packet> 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 extends Packet> 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 extends Packet> P nextResult() {
return nextResult(connection.getPacketReplyTimeout());
}

View file

@ -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();
}

View file

@ -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();

View file

@ -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();

View file

@ -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();
}