|
JML | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jqql.packets.PacketHistory
public class PacketHistory
packet monitor.
this class use a hashtable and a linked list to manage received packet, other people can use his
method to checkout a packet whether is received, for example resend thread use is to checkout whether answer
of a packet is arrived. if is, don't resend. and received thread, once received a packet, save hash value of
this packet into this class. and packet handler, also need it to checkout whether a packet is reduplicate.
Of course, this method can't perfect avoid any needless resend, but at least have som help.
on the side, this packet monitor also manage all request, because answer packet of these packet haven't any usable info.
info are all in request packet, so ...
包监视器.
这个类使用一个hashtable和一个linked list来管理收到的包,其他人可以调用他的
方法来检查一个包是否收到,比如重发线程通过它来检查是否一个包的应答已经到达,
如果是,则不需要重发。还有接收线程,一旦收到一个包,就把这个包的hash值存入这
个类,还有包处理器,也要通过来检查是否一个包是重复的。当然这种方法还不能完美
的避免任何不必要的重发,但是至少有点帮助,-_-!....
另外这个包监视器还要管理所有的请求,因为这些包的应答包里面没有什么有用的信息,
信息都在请求包里,所以...
(edit by notxx)
change into using LinkedHashSet and HashMap to manage, speed would be faster.
no need to create a Integer object as key, immediacy use packet itself.
改变成使用LinkedHashSet和HashMap来管理. 速度应该快一些.
不需要创建一个Integer对象作为key了, 直接使用Packet本身即可.
Packet.hashCode()
,
Packet.equals(Object)
Constructor Summary | |
---|---|
PacketHistory()
constructed function 构造函数 |
Method Summary | |
---|---|
boolean |
check(int hashValue,
boolean add)
checkout appointed hash value whether is exist 检查指定的hash值是否已经存在 |
boolean |
check(Object packet,
boolean add)
this method checkout packet whether is received, remarkable is that checkout is for hash value of this packet, not for packet object, account of hash value is completing in hashCode in packet. |
boolean |
check(Packet packet,
boolean add)
this method checkout packet whether is received, remarkable is that checkout is for hash value of this packet, not for packet object, account of hash value is completing in hashCode in packet. |
void |
clear()
clear packet monitor buffer 清空包监视缓冲区 |
void |
putSent(OutPacket packet)
push requst into hashMap 把请求推入哈希表 |
OutPacket |
retrieveSent(InPacket packet)
return request packet for this reply packet 返回这个回复包对应的请求包 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PacketHistory()
Method Detail |
---|
public boolean check(Packet packet, boolean add)
packet
- packet to be checkout
要检查的包add
- if is true, then while this packet is null, add hash of this packet, or don't add
如果为true,则当这个包不存在时,添加这个包的hash,否则不添加
Packet.hashCode()
,
Packet.equals(Object);
public boolean check(int hashValue, boolean add)
hashValue
- 哈希值 // hash valueadd
- true means if not exist then add this hash value
true表示如果不存在则添加这个哈希值
public boolean check(Object packet, boolean add)
packet
- packet to be checkout
要检查的包add
- add
- if is true, then while this packet is null, add hash of this packet, or don't add
如果为true,则当这个包不存在时,添加这个包的hash,否则不添加
public void putSent(OutPacket packet)
packet
- request packet
请求包public OutPacket retrieveSent(InPacket packet)
packet
- InPacket
public void clear()
|
JML | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |