|
JML | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
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 All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |