mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 07:22:07 +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:
parent
b3b0e02ae1
commit
522d0f30ff
5 changed files with 17 additions and 15 deletions
|
@ -103,8 +103,9 @@ public class PacketCollector {
|
||||||
* @return the next packet result, or <tt>null</tt> if there are no more
|
* @return the next packet result, or <tt>null</tt> if there are no more
|
||||||
* results.
|
* results.
|
||||||
*/
|
*/
|
||||||
public Packet pollResult() {
|
@SuppressWarnings("unchecked")
|
||||||
return resultQueue.poll();
|
public <P extends Packet> P pollResult() {
|
||||||
|
return (P) resultQueue.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,9 +114,10 @@ public class PacketCollector {
|
||||||
*
|
*
|
||||||
* @return the next available packet.
|
* @return the next available packet.
|
||||||
*/
|
*/
|
||||||
public Packet nextResultBlockForever() {
|
@SuppressWarnings("unchecked")
|
||||||
|
public <P extends Packet> P nextResultBlockForever() {
|
||||||
try {
|
try {
|
||||||
return resultQueue.take();
|
return (P) resultQueue.take();
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -128,7 +130,7 @@ public class PacketCollector {
|
||||||
*
|
*
|
||||||
* @return the next availabe packet.
|
* @return the next availabe packet.
|
||||||
*/
|
*/
|
||||||
public Packet nextResult() {
|
public <P extends Packet> P nextResult() {
|
||||||
return nextResult(connection.getPacketReplyTimeout());
|
return nextResult(connection.getPacketReplyTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,10 +157,10 @@ public class OfflineMessageManager {
|
||||||
try {
|
try {
|
||||||
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
// Collect the received offline messages
|
// Collect the received offline messages
|
||||||
Message message = (Message) messageCollector.nextResult();
|
Message message = messageCollector.nextResult();
|
||||||
while (message != null) {
|
while (message != null) {
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
message = (Message) messageCollector.nextResult();
|
message = messageCollector.nextResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -191,10 +191,10 @@ public class OfflineMessageManager {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Collect the received offline messages
|
// Collect the received offline messages
|
||||||
Message message = (Message) messageCollector.nextResult();
|
Message message = messageCollector.nextResult();
|
||||||
while (message != null) {
|
while (message != null) {
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
message = (Message) messageCollector.nextResult();
|
message = messageCollector.nextResult();
|
||||||
}
|
}
|
||||||
resultCollector.nextResultOrThrow();
|
resultCollector.nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,7 +396,7 @@ public class RTPBridge extends IQ {
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollectorAndSend(rtpPacket);
|
PacketCollector collector = connection.createPacketCollectorAndSend(rtpPacket);
|
||||||
|
|
||||||
RTPBridge response = (RTPBridge) collector.nextResult();
|
RTPBridge response = collector.nextResult();
|
||||||
|
|
||||||
// Cancel the collector.
|
// Cancel the collector.
|
||||||
collector.cancel();
|
collector.cancel();
|
||||||
|
@ -470,7 +470,7 @@ public class RTPBridge extends IQ {
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollectorAndSend(rtpPacket);
|
PacketCollector collector = connection.createPacketCollectorAndSend(rtpPacket);
|
||||||
|
|
||||||
RTPBridge response = (RTPBridge) collector.nextResult();
|
RTPBridge response = collector.nextResult();
|
||||||
|
|
||||||
// Cancel the collector.
|
// Cancel the collector.
|
||||||
collector.cancel();
|
collector.cancel();
|
||||||
|
@ -499,7 +499,7 @@ public class RTPBridge extends IQ {
|
||||||
|
|
||||||
PacketCollector collector = xmppConnection.createPacketCollectorAndSend(rtpPacket);
|
PacketCollector collector = xmppConnection.createPacketCollectorAndSend(rtpPacket);
|
||||||
|
|
||||||
RTPBridge response = (RTPBridge) collector.nextResult();
|
RTPBridge response = collector.nextResult();
|
||||||
|
|
||||||
// Cancel the collector.
|
// Cancel the collector.
|
||||||
collector.cancel();
|
collector.cancel();
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class STUN extends IQ {
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollectorAndSend(stunPacket);
|
PacketCollector collector = connection.createPacketCollectorAndSend(stunPacket);
|
||||||
|
|
||||||
STUN response = (STUN) collector.nextResult();
|
STUN response = collector.nextResult();
|
||||||
|
|
||||||
// Cancel the collector.
|
// Cancel the collector.
|
||||||
collector.cancel();
|
collector.cancel();
|
||||||
|
|
|
@ -827,7 +827,7 @@ public class AgentSession {
|
||||||
request.setType(IQ.Type.get);
|
request.setType(IQ.Type.get);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
AgentChatHistory response = (AgentChatHistory) connection.createPacketCollectorAndSend(
|
AgentChatHistory response = connection.createPacketCollectorAndSend(
|
||||||
request).nextResult();
|
request).nextResult();
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -901,7 +901,7 @@ public class AgentSession {
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
request.setSessionID(sessionID);
|
request.setSessionID(sessionID);
|
||||||
|
|
||||||
ChatMetadata response = (ChatMetadata) connection.createPacketCollectorAndSend(request).nextResult();
|
ChatMetadata response = connection.createPacketCollectorAndSend(request).nextResult();
|
||||||
|
|
||||||
return response.getMetadata();
|
return response.getMetadata();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue