|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mpisws.p2p.filetransfer.FileTransferImpl
public class FileTransferImpl
TODO: implement read, write
Field Summary | |
---|---|
protected FileTransferCallback |
callback
|
static byte |
CANCEL_PRIORITY
|
protected int |
CHUNK_SIZE
Max size of a message, (the size that can't be preempted) |
static byte |
DEFAULT_PRIORITY
|
protected Environment |
environment
|
protected int |
FILE_CACHE
Number of chunks to keep in memory per file. |
protected FileAllocationStrategy |
fileAllocater
|
int |
fileChunksInMemory
Synchronized by only being mutated/checked on selector thread can be reading when < MAX_PENDING_CHUNKS, allowed to be greater |
static byte |
HIGH_PRIORITY
|
protected Logger |
logger
|
static byte |
LOW_PRIORITY
|
static byte |
LOWEST_PRIORITY
|
static int |
MAX_FILE_CHUNKS_IN_MEMORY
|
static byte |
MAX_PRIORITY
|
static byte |
MEDIUM_HIGH_PRIORITY
|
static byte |
MEDIUM_LOW_PRIORITY
|
static byte |
MEDIUM_PRIORITY
|
static byte |
MSG_BB_HEADER
Contains int UID, int length |
static byte |
MSG_CANCEL
Contains int UID |
static byte |
MSG_CANCEL_REQUEST
Contains int UID |
static byte |
MSG_CHUNK
Contains int UID, int chunk_length, byte[chunk_length] msg |
static byte |
MSG_FILE_HEADER
Contains int UID, long offset, long length, int nameLength, UTF name |
protected Processor |
processor
|
protected SelectorManager |
selectorManager
|
protected AppSocket |
socket
|
Constructor Summary | |
---|---|
FileTransferImpl(AppSocket socket,
FileTransferCallback callback,
Environment env)
|
|
FileTransferImpl(AppSocket socket,
FileTransferCallback callback,
FileAllocationStrategy fileAllocater,
Environment env)
|
|
FileTransferImpl(AppSocket socket,
FileTransferCallback callback,
FileAllocationStrategy fileAllocater,
Environment env,
Processor p)
|
|
FileTransferImpl(AppSocket socket,
FileTransferCallback callback,
FileAllocationStrategy fileAllocater,
Environment env,
Processor p,
int chunkSize,
int numChunksToWriteToNetwork)
|
Method Summary | |
---|---|
void |
addIncomingFile(int uid,
byte[] metadata,
long offset,
long length)
|
void |
addIncomingMessage(int uid,
int size)
|
void |
addListener(FileTransferListener listener)
|
protected boolean |
complete(org.mpisws.p2p.filetransfer.FileTransferImpl.MessageWrapper wrapper)
|
protected void |
decrementFileChunksInMemory()
|
java.lang.Iterable<FileTransferListener> |
getListeners()
|
protected int |
getUid()
|
protected void |
incrementFileChunksInMemory()
|
protected void |
notifyListenersReceiveFileProgress(FileReceipt receipt,
long bytesReceived,
long bytesTotal)
|
protected void |
notifyListenersReceiveMsgProgress(BBReceipt receipt,
int bytesReceived,
int bytesTotal)
|
protected void |
notifyListenersReceiverCancelled(Receipt receipt)
|
protected void |
notifyListenersSenderCancelled(org.mpisws.p2p.filetransfer.FileTransferImpl.DataReader receipt)
|
protected void |
notifyListenersSendFileProgress(FileReceipt receipt,
long bytesSent,
long bytesTotal)
|
protected void |
notifyListenersSendMsgProgress(BBReceipt receipt,
int bytesSent,
int bytesTotal)
|
protected void |
notifyListenersTransferFailed(Receipt receipt,
boolean incoming)
|
protected void |
purge()
|
void |
receiveException(AppSocket socket,
java.lang.Exception e)
Called when there is an error |
protected void |
receiverCancelled(int uid)
|
void |
receiveSelectResult(AppSocket socket,
boolean canRead,
boolean canWrite)
Called when a socket is available for read/write |
void |
receiveSocket(AppSocket socket)
Called when we have a new socket (due to a call to connect or accept) |
void |
registerToReadIfPossible()
|
void |
removeListener(FileTransferListener listener)
|
protected boolean |
requestCancel(int uid)
Only call this on the receiver side, b/c uid is simplex |
protected void |
scheduleToWriteIfNeeded()
Must be called on selectorManager. |
protected boolean |
sendCancel(int uid)
Only call this on the sender side, b/c uid is simplex |
protected void |
senderCancelled(int uid)
|
FileReceipt |
sendFile(java.io.File f,
java.nio.ByteBuffer metadata,
byte priority,
Continuation<FileReceipt,java.lang.Exception> c)
|
FileReceipt |
sendFile(java.io.File f,
java.nio.ByteBuffer metadataBB,
byte priority,
long offset,
long length,
Continuation<FileReceipt,java.lang.Exception> c)
|
BBReceipt |
sendMsg(java.nio.ByteBuffer bb,
byte priority,
Continuation<BBReceipt,java.lang.Exception> c)
|
protected void |
socketClosed()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte MSG_FILE_HEADER
public static final byte MSG_BB_HEADER
public static final byte MSG_CHUNK
public static final byte MSG_CANCEL
public static final byte MSG_CANCEL_REQUEST
protected FileAllocationStrategy fileAllocater
protected AppSocket socket
protected FileTransferCallback callback
protected int CHUNK_SIZE
protected int FILE_CACHE
protected SelectorManager selectorManager
protected Logger logger
protected Processor processor
protected Environment environment
public static final byte MAX_PRIORITY
public static final byte HIGH_PRIORITY
public static final byte MEDIUM_HIGH_PRIORITY
public static final byte MEDIUM_PRIORITY
public static final byte MEDIUM_LOW_PRIORITY
public static final byte LOW_PRIORITY
public static final byte LOWEST_PRIORITY
public static final byte DEFAULT_PRIORITY
public static final byte CANCEL_PRIORITY
public static final int MAX_FILE_CHUNKS_IN_MEMORY
public int fileChunksInMemory
Constructor Detail |
---|
public FileTransferImpl(AppSocket socket, FileTransferCallback callback, FileAllocationStrategy fileAllocater, Environment env, Processor p)
public FileTransferImpl(AppSocket socket, FileTransferCallback callback, FileAllocationStrategy fileAllocater, Environment env, Processor p, int chunkSize, int numChunksToWriteToNetwork)
public FileTransferImpl(AppSocket socket, FileTransferCallback callback, Environment env)
public FileTransferImpl(AppSocket socket, FileTransferCallback callback, FileAllocationStrategy fileAllocater, Environment env)
Method Detail |
---|
protected void socketClosed()
public void receiveException(AppSocket socket, java.lang.Exception e)
AppSocketReceiver
receiveException
in interface AppSocketReceiver
protected void purge()
protected void scheduleToWriteIfNeeded()
protected boolean complete(org.mpisws.p2p.filetransfer.FileTransferImpl.MessageWrapper wrapper)
public void addListener(FileTransferListener listener)
addListener
in interface FileTransfer
public void removeListener(FileTransferListener listener)
removeListener
in interface FileTransfer
public java.lang.Iterable<FileTransferListener> getListeners()
protected void notifyListenersSendMsgProgress(BBReceipt receipt, int bytesSent, int bytesTotal)
protected void notifyListenersReceiveMsgProgress(BBReceipt receipt, int bytesReceived, int bytesTotal)
protected void notifyListenersSendFileProgress(FileReceipt receipt, long bytesSent, long bytesTotal)
protected void notifyListenersReceiveFileProgress(FileReceipt receipt, long bytesReceived, long bytesTotal)
protected void notifyListenersSenderCancelled(org.mpisws.p2p.filetransfer.FileTransferImpl.DataReader receipt)
protected void notifyListenersReceiverCancelled(Receipt receipt)
protected void notifyListenersTransferFailed(Receipt receipt, boolean incoming)
public FileReceipt sendFile(java.io.File f, java.nio.ByteBuffer metadata, byte priority, Continuation<FileReceipt,java.lang.Exception> c) throws java.io.IOException
sendFile
in interface FileTransfer
java.io.IOException
public FileReceipt sendFile(java.io.File f, java.nio.ByteBuffer metadataBB, byte priority, long offset, long length, Continuation<FileReceipt,java.lang.Exception> c) throws java.io.IOException
sendFile
in interface FileTransfer
f
- the file to sendmetadataBB
- this data will be delivered to the FileAllocationStrategy and the FileTransferCallback, it can
contain whatever the application needs to name the file, often a filename is sufficient.priority
- the priority of sendingoffset
- where to start in the filelength
- how many bytes to send (must be <= fileLength-offset)c
- who to notify when it is done
java.io.IOException
public BBReceipt sendMsg(java.nio.ByteBuffer bb, byte priority, Continuation<BBReceipt,java.lang.Exception> c)
sendMsg
in interface FileTransfer
protected int getUid()
public void receiveSelectResult(AppSocket socket, boolean canRead, boolean canWrite)
AppSocketReceiver
receiveSelectResult
in interface AppSocketReceiver
protected void incrementFileChunksInMemory()
protected void decrementFileChunksInMemory()
public void registerToReadIfPossible()
protected void receiverCancelled(int uid)
protected void senderCancelled(int uid)
public void addIncomingMessage(int uid, int size)
public void addIncomingFile(int uid, byte[] metadata, long offset, long length) throws java.io.IOException
java.io.IOException
public void receiveSocket(AppSocket socket)
AppSocketReceiver
receiveSocket
in interface AppSocketReceiver
protected boolean requestCancel(int uid)
uid
-
protected boolean sendCancel(int uid)
uid
-
|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |