JML

net.sf.jqql.obsolete
Class FileWatcher

java.lang.Object
  extended by net.sf.jqql.obsolete.FileWatcher
Direct Known Subclasses:
FileReceiver, FileSender

public abstract class FileWatcher
extends Object

file wathcer, take charge to manage once file transfer 文件守望者,负责管理一次文件传输

Author:
luma

Field Summary
protected  ByteBuffer buffer
           
protected  int condition
           
protected  FileControlPacket fcp
           
protected  FileDataPacket fdp
           
protected  byte[] fileAgentKey
           
protected  byte[] fileAgentToken
           
protected  byte[] fileMD5
           
protected  String fileName
           
protected  byte[] fileNameMD5
           
protected  int fileSize
           
protected  int fileTransferStatus
           
protected  int fragments
           
static int FT_NEGOTIATING
           
static int FT_NONE
           
static int FT_RECEIVING
           
static int FT_SAYING_HELLO
           
static int FT_SENDING
           
static int FT_SENDING_BASIC
           
static int FT_SENDING_EOF
           
protected  byte[] hisFileSessionKey
           
protected  byte[] hisInternetIp
           
protected  int hisInternetPort
           
protected  byte[] hisLocalIp
           
protected  int hisMajorPort
           
protected  int hisMinorPort
           
protected  int hisQQ
           
protected  List<IFileListener> listeners
           
protected  RandomAccessFile localFile
           
protected  String localFileName
           
protected static org.apache.commons.logging.Log log
           
protected  boolean major
           
protected  int maxFragmentSize
           
protected  FilePacketMonitor monitor
           
protected  byte myFace
           
protected  byte[] myFileSessionKey
           
protected  byte[] myInternetIp
           
protected  int myInternetPort
           
protected  byte[] myLocalIp
           
protected  int myMajorPort
           
protected  int myMinorPort
           
protected  int myQQ
           
protected  Selector selector
           
protected  char sessionSequence
           
protected  boolean shutdown
           
protected  boolean useUdp
           
protected  SlideWindow window
           
 
Constructor Summary
FileWatcher()
           
 
Method Summary
abstract  void abort()
          abort file transfer 取消文件传输
 void addFileListener(IFileListener listener)
          add file transfer event listener 添加文件传输事件监听器
protected  void checkCondition()
          get both side's condition in network from IP condition 根据各方的IP情况,得到双方在网络上的处境
abstract  void finish()
          finish file transfer, process some post event 结束文件传输,处理一些善后事宜
protected  void fireFileAbortedEvent()
          fire file transfer aborted event 触发文件传输被取消事件
protected  void fireFileConnectedEvent()
          fire connected event 触发连接建立事件
protected  void fireFileFinishedEvent()
          fire file transfer finished event 触发文件传输完成事件
protected  void fireFileInProgressEvent()
          fire file transfer in progress event 触发文件传送中事件
 int getCondition()
           
 byte[] getFileAgentKey()
           
 byte[] getFileAgentToken()
           
 byte[] getFileMD5()
           
 String getFileName()
           
 byte[] getFileNameMD5()
           
 int getFileSize()
           
 int getFileTransferStatus()
           
 int getFragments()
           
 byte[] getHisFileSessionKey()
           
 byte[] getHisInternetIp()
           
 int getHisInternetPort()
           
 byte[] getHisLocalIp()
           
 int getHisMajorPort()
           
 int getHisMinorPort()
           
 int getHisQQ()
           
 String getLocalFileName()
           
 String getLocalFilePath()
           
 int getMaxFragmentSize()
           
 byte getMyFace()
           
 byte[] getMyFileSessionKey()
           
 byte[] getMyInternetIp()
           
 int getMyInternetPort()
           
 byte[] getMyLocalIp()
           
 int getMyMajorPort()
           
 int getMyMinorPort()
           
 int getMyQQ()
           
 char getSessionSequence()
           
 SlideWindow getSlideWindow()
           
 void initSlideWindow(int size, int l, int m)
          init slide window 初始化滑窗
 boolean isUseUdp()
           
abstract  boolean openLocalFile()
          opent local file to read and write 打开本地文件准备读和写
 void removeFileListener(IFileListener listener)
          remover file transfer event listener 移除文件传输事件监听器
 void setCondition(int connectType)
           
 void setFileAgentKey(byte[] fileAgentKey)
           
 void setFileAgentToken(byte[] fileAgentToken)
           
 void setFileMD5(byte[] firstMD5)
           
 void setFileName(String fileName)
           
 void setFileNameMD5(byte[] secondMD5)
           
 void setFileSize(int fileSize)
           
 void setFileTransferStatus(int fileTransferStatus)
           
 void setFragments(int fragments)
           
 void setHisFileSessionKey(byte[] hisFileSessionKey)
           
 void setHisInternetIp(byte[] hisInternetIp)
           
 void setHisInternetPort(int hisExternalPort)
           
 void setHisLocalIp(byte[] hisLocalIp)
           
 void setHisMajorPort(int hisFirstPort)
           
 void setHisMinorPort(int hisSecondPort)
           
 void setHisQQ(int hisQQ)
           
 void setLocalFileName(String localFileName)
           
 void setMaxFragmentSize(int maxFragmentSize)
           
 void setMyFace(byte face)
           
 void setMyFileSessionKey(byte[] myFileSessionKey)
           
 void setMyInternetIp(byte[] myInternetIp)
           
 void setMyInternetPort(int myExternalPort)
           
 void setMyLocalIp(byte[] myLocalIp)
           
 void setMyMajorPort(int myFirstPort)
           
 void setMyMinorPort(int mySecondPort)
           
 void setMyQQ(int myQQ)
           
 void setSessionSequence(char sessionSequence)
           
abstract  void shutdown()
          close watcher 关闭守望者
abstract  void start()
           start watcher, for receiver, he will choose a link to transfer for sender, he will start two port waiting for reply by the other side 启动守望者,对于接收者,他将选择一条链路进行连接准备传输 对于发送者,他将启动两个端口等待对方应答
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FT_NONE

public static final int FT_NONE
See Also:
Constant Field Values

FT_NEGOTIATING

public static final int FT_NEGOTIATING
See Also:
Constant Field Values

FT_SENDING

public static final int FT_SENDING
See Also:
Constant Field Values

FT_RECEIVING

public static final int FT_RECEIVING
See Also:
Constant Field Values

FT_SAYING_HELLO

public static final int FT_SAYING_HELLO
See Also:
Constant Field Values

FT_SENDING_EOF

public static final int FT_SENDING_EOF
See Also:
Constant Field Values

FT_SENDING_BASIC

public static final int FT_SENDING_BASIC
See Also:
Constant Field Values

log

protected static org.apache.commons.logging.Log log

myMajorPort

protected int myMajorPort

myMinorPort

protected int myMinorPort

myLocalIp

protected byte[] myLocalIp

myInternetIp

protected byte[] myInternetIp

myInternetPort

protected int myInternetPort

hisMajorPort

protected int hisMajorPort

hisMinorPort

protected int hisMinorPort

hisLocalIp

protected byte[] hisLocalIp

hisInternetIp

protected byte[] hisInternetIp

hisInternetPort

protected int hisInternetPort

myFileSessionKey

protected byte[] myFileSessionKey

hisFileSessionKey

protected byte[] hisFileSessionKey

fileAgentKey

protected byte[] fileAgentKey

fileAgentToken

protected byte[] fileAgentToken

hisQQ

protected int hisQQ

myQQ

protected int myQQ

myFace

protected byte myFace

sessionSequence

protected char sessionSequence

condition

protected int condition

fileSize

protected int fileSize

fileName

protected String fileName

fragments

protected int fragments

localFileName

protected String localFileName

localFile

protected RandomAccessFile localFile

window

protected SlideWindow window

maxFragmentSize

protected int maxFragmentSize

fileMD5

protected byte[] fileMD5

fileNameMD5

protected byte[] fileNameMD5

fdp

protected FileDataPacket fdp

fcp

protected FileControlPacket fcp

selector

protected Selector selector

shutdown

protected boolean shutdown

buffer

protected ByteBuffer buffer

useUdp

protected boolean useUdp

major

protected boolean major

fileTransferStatus

protected int fileTransferStatus

monitor

protected FilePacketMonitor monitor

listeners

protected List<IFileListener> listeners
Constructor Detail

FileWatcher

public FileWatcher()
Parameters:
udp - 是否是udp方式 // whether is udp mode
parent - FileWatcher所属的发送消息窗口 // send message of FileWatcher
me - QQUser对象 // QQUser object
Method Detail

initSlideWindow

public void initSlideWindow(int size,
                            int l,
                            int m)
init slide window 初始化滑窗

Parameters:
size - 窗口大小 window size
l - 窗口初始下限 window initial low
m - 窗口最大值 max of window

addFileListener

public void addFileListener(IFileListener listener)
add file transfer event listener 添加文件传输事件监听器

Parameters:
listener -

removeFileListener

public void removeFileListener(IFileListener listener)
remover file transfer event listener 移除文件传输事件监听器

Parameters:
listener -

fireFileAbortedEvent

protected void fireFileAbortedEvent()
fire file transfer aborted event 触发文件传输被取消事件


fireFileFinishedEvent

protected void fireFileFinishedEvent()
fire file transfer finished event 触发文件传输完成事件


fireFileInProgressEvent

protected void fireFileInProgressEvent()
fire file transfer in progress event 触发文件传送中事件


fireFileConnectedEvent

protected void fireFileConnectedEvent()
fire connected event 触发连接建立事件


checkCondition

protected void checkCondition()
get both side's condition in network from IP condition 根据各方的IP情况,得到双方在网络上的处境


shutdown

public abstract void shutdown()
close watcher 关闭守望者


abort

public abstract void abort()
abort file transfer 取消文件传输


finish

public abstract void finish()
finish file transfer, process some post event 结束文件传输,处理一些善后事宜


openLocalFile

public abstract boolean openLocalFile()
opent local file to read and write 打开本地文件准备读和写


start

public abstract void start()
 start watcher, for receiver, he will choose a link to transfer
 for sender, he will start two port waiting for reply by the other side
 启动守望者,对于接收者,他将选择一条链路进行连接准备传输
 对于发送者,他将启动两个端口等待对方应答
 


getHisMajorPort

public int getHisMajorPort()
Returns:
Returns the hisFirstPort.

setHisMajorPort

public void setHisMajorPort(int hisFirstPort)
Parameters:
hisFirstPort - The hisFirstPort to set.

getHisMinorPort

public int getHisMinorPort()
Returns:
Returns the hisSecondPort.

setHisMinorPort

public void setHisMinorPort(int hisSecondPort)
Parameters:
hisSecondPort - The hisSecondPort to set.

getMyMajorPort

public int getMyMajorPort()
Returns:
Returns the myFirstPort.

setMyMajorPort

public void setMyMajorPort(int myFirstPort)
Parameters:
myFirstPort - The myFirstPort to set.

getMyMinorPort

public int getMyMinorPort()
Returns:
Returns the mySecondPort.

setMyMinorPort

public void setMyMinorPort(int mySecondPort)
Parameters:
mySecondPort - The mySecondPort to set.

getMyInternetPort

public int getMyInternetPort()
Returns:
Returns the myExternalPort.

setMyInternetPort

public void setMyInternetPort(int myExternalPort)
Parameters:
myExternalPort - The myExternalPort to set.

getHisFileSessionKey

public byte[] getHisFileSessionKey()
Returns:
Returns the hisFileSessionKey.

setHisFileSessionKey

public void setHisFileSessionKey(byte[] hisFileSessionKey)
Parameters:
hisFileSessionKey - The hisFileSessionKey to set.

getHisQQ

public int getHisQQ()
Returns:
Returns the hisQQ.

setHisQQ

public void setHisQQ(int hisQQ)
Parameters:
hisQQ - The hisQQ to set.

getMyFileSessionKey

public byte[] getMyFileSessionKey()
Returns:
Returns the myFileSessionKey.

setMyFileSessionKey

public void setMyFileSessionKey(byte[] myFileSessionKey)
Parameters:
myFileSessionKey - The myFileSessionKey to set.

getMyQQ

public int getMyQQ()
Returns:
Returns the myQQ.

setMyQQ

public void setMyQQ(int myQQ)
Parameters:
myQQ - The myQQ to set.

getSessionSequence

public char getSessionSequence()
Returns:
Returns the sessionSequence.

setSessionSequence

public void setSessionSequence(char sessionSequence)
Parameters:
sessionSequence - The sessionSequence to set.

getMyFace

public byte getMyFace()
Returns:
Returns the face.

setMyFace

public void setMyFace(byte face)
Parameters:
face - The face to set.

getHisInternetIp

public byte[] getHisInternetIp()
Returns:
Returns the hisExternalIp.

setHisInternetIp

public void setHisInternetIp(byte[] hisInternetIp)
Parameters:
hisInternetIp - The hisExternalIp to set.

getHisLocalIp

public byte[] getHisLocalIp()
Returns:
Returns the hisInternalIp.

setHisLocalIp

public void setHisLocalIp(byte[] hisLocalIp)
Parameters:
hisLocalIp - The hisInternalIp to set.

getMyInternetIp

public byte[] getMyInternetIp()
Returns:
Returns the myExternalIp.

setMyInternetIp

public void setMyInternetIp(byte[] myInternetIp)
Parameters:
myInternetIp - The myExternalIp to set.

getMyLocalIp

public byte[] getMyLocalIp()
Returns:
Returns the myInternalIp.

setMyLocalIp

public void setMyLocalIp(byte[] myLocalIp)
Parameters:
myLocalIp - The myInternalIp to set.

getHisInternetPort

public int getHisInternetPort()
Returns:
Returns the hisExternalPort.

setHisInternetPort

public void setHisInternetPort(int hisExternalPort)
Parameters:
hisExternalPort - The hisExternalPort to set.

getCondition

public int getCondition()
Returns:
Returns the connectType.

setCondition

public void setCondition(int connectType)
Parameters:
connectType - The connectType to set.

getFileName

public String getFileName()
Returns:
Returns the fileName.

setFileName

public void setFileName(String fileName)
Parameters:
fileName - The fileName to set.

getFileSize

public int getFileSize()
Returns:
Returns the fileSize.

setFileSize

public void setFileSize(int fileSize)
Parameters:
fileSize - The fileSize to set.

getFragments

public int getFragments()
Returns:
Returns the fragments.

setFragments

public void setFragments(int fragments)
Parameters:
fragments - The fragments to set.

getLocalFileName

public String getLocalFileName()
Returns:
Returns the localFileName.

setLocalFileName

public void setLocalFileName(String localFileName)
Parameters:
localFileName - The localFileName to set.

getMaxFragmentSize

public int getMaxFragmentSize()
Returns:
Returns the maxFragmentSize.

setMaxFragmentSize

public void setMaxFragmentSize(int maxFragmentSize)
Parameters:
maxFragmentSize - The maxFragmentSize to set.

getFileMD5

public byte[] getFileMD5()
Returns:
Returns the firstMD5.

setFileMD5

public void setFileMD5(byte[] firstMD5)
Parameters:
firstMD5 - The firstMD5 to set.

getFileNameMD5

public byte[] getFileNameMD5()
Returns:
Returns the secondMD5.

setFileNameMD5

public void setFileNameMD5(byte[] secondMD5)
Parameters:
secondMD5 - The secondMD5 to set.

getFileTransferStatus

public int getFileTransferStatus()
Returns:
Returns the fileTransferStatus.

setFileTransferStatus

public void setFileTransferStatus(int fileTransferStatus)
Parameters:
fileTransferStatus - The fileTransferStatus to set.

getLocalFilePath

public String getLocalFilePath()
Returns:
本地文件的路径 // local file path

getSlideWindow

public SlideWindow getSlideWindow()
Returns:
滑窗对象 // slide window object

isUseUdp

public boolean isUseUdp()
Returns:

getFileAgentKey

public byte[] getFileAgentKey()
Returns:
Returns the fileAgentKey.

setFileAgentKey

public void setFileAgentKey(byte[] fileAgentKey)
Parameters:
fileAgentKey - The fileAgentKey to set.

getFileAgentToken

public byte[] getFileAgentToken()
Returns:
Returns the fileAgentToken.

setFileAgentToken

public void setFileAgentToken(byte[] fileAgentToken)
Parameters:
fileAgentToken - The fileAgentToken to set.

JML