Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mpisws.p2p.filetransfer
Class FileTransferImpl

    java.lang.Object
      org.mpisws.p2p.filetransfer.FileTransferImpl

All Implemented Interfaces:
  FileTransfer, AppSocketReceiver

    public class FileTransferImpl

extends java.lang.Object
implements FileTransfer, AppSocketReceiver

TODO: implement read, write

Author:
  Jeff Hoye

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)`

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

### MSG_FILE_HEADER

    public static final byte MSG_FILE_HEADER

  Contains int UID, long offset, long length, int nameLength, UTF name

  See Also:
    Constant Field Values

### MSG_BB_HEADER

    public static final byte MSG_BB_HEADER

  Contains int UID, int length

  See Also:
    Constant Field Values

### MSG_CHUNK

    public static final byte MSG_CHUNK

  Contains int UID, int chunk_length, byte[chunk_length] msg

  See Also:
    Constant Field Values

### MSG_CANCEL

    public static final byte MSG_CANCEL

  Contains int UID

  See Also:
    Constant Field Values

### MSG_CANCEL_REQUEST

    public static final byte MSG_CANCEL_REQUEST

  Contains int UID

  See Also:
    Constant Field Values

### fileAllocater

    protected FileAllocationStrategy fileAllocater

### socket

    protected AppSocket socket

### callback

    protected FileTransferCallback callback

### CHUNK_SIZE

    protected int CHUNK_SIZE

  Max size of a message, (the size that can't be preempted)

### FILE_CACHE

    protected int FILE_CACHE

  Number of chunks to keep in memory per file. If this is too big, takes more memory, if this is too small, we are always blocking on file I/O when there is available network I/O... Is there a way to make this adaptive? Think about it...

### selectorManager

    protected SelectorManager selectorManager

### logger

    protected Logger logger

### processor

    protected Processor processor

### environment

    protected Environment environment

### MAX_PRIORITY

    public static final byte MAX_PRIORITY

See Also:
  Constant Field Values

### HIGH_PRIORITY

    public static final byte HIGH_PRIORITY

See Also:
  Constant Field Values

### MEDIUM_HIGH_PRIORITY

    public static final byte MEDIUM_HIGH_PRIORITY

See Also:
  Constant Field Values

### MEDIUM_PRIORITY

    public static final byte MEDIUM_PRIORITY

See Also:
  Constant Field Values

### MEDIUM_LOW_PRIORITY

    public static final byte MEDIUM_LOW_PRIORITY

See Also:
  Constant Field Values

### LOW_PRIORITY

    public static final byte LOW_PRIORITY

See Also:
  Constant Field Values

### LOWEST_PRIORITY

    public static final byte LOWEST_PRIORITY

See Also:
  Constant Field Values

### DEFAULT_PRIORITY

    public static final byte DEFAULT_PRIORITY

See Also:
  Constant Field Values

### CANCEL_PRIORITY

    public static final byte CANCEL_PRIORITY

See Also:
  Constant Field Values

### MAX_FILE_CHUNKS_IN_MEMORY

    public static final int MAX_FILE_CHUNKS_IN_MEMORY

See Also:
  Constant Field Values

### fileChunksInMemory

    public int fileChunksInMemory

  Synchronized by only being mutated/checked on selector thread can be reading when < MAX_PENDING_CHUNKS, allowed to be greater

Constructor Detail

### FileTransferImpl

    public FileTransferImpl(AppSocket socket,
                            FileTransferCallback callback,
                            FileAllocationStrategy fileAllocater,
                            Environment env)

### FileTransferImpl

    public FileTransferImpl(AppSocket socket,
                            FileTransferCallback callback,
                            Environment env)

Method Detail

### socketClosed

    protected void socketClosed()

### receiveException

    public void receiveException(AppSocket socket,
                                 java.lang.Exception e)

  Description copied from interface: `AppSocketReceiver`
  Called when there is an error

  Specified by:
    `receiveException` in interface `AppSocketReceiver`

### purge

    protected void purge()

### scheduleToWriteIfNeeded

    protected void scheduleToWriteIfNeeded()

  Must be called on selectorManager. A) finds a writingSocket if possible opens one if needed

### complete

    protected boolean complete(org.mpisws.p2p.filetransfer.FileTransferImpl.MessageWrapper wrapper)

### addListener

    public void addListener(FileTransferListener listener)

  Specified by:
    `addListener` in interface `FileTransfer`

### removeListener

    public void removeListener(FileTransferListener listener)

  Specified by:
    `removeListener` in interface `FileTransfer`

### getListeners

    public java.lang.Iterable<FileTransferListener> getListeners()

### notifyListenersSendMsgProgress

    protected void notifyListenersSendMsgProgress(BBReceipt receipt,
                                                  int bytesSent,
                                                  int bytesTotal)

### notifyListenersReceiveMsgProgress

    protected void notifyListenersReceiveMsgProgress(BBReceipt receipt,
                                                     int bytesReceived,
                                                     int bytesTotal)

### notifyListenersSendFileProgress

    protected void notifyListenersSendFileProgress(FileReceipt receipt,
                                                   long bytesSent,
                                                   long bytesTotal)

### notifyListenersReceiveFileProgress

    protected void notifyListenersReceiveFileProgress(FileReceipt receipt,
                                                      long bytesReceived,
                                                      long bytesTotal)

### notifyListenersSenderCancelled

    protected void notifyListenersSenderCancelled(org.mpisws.p2p.filetransfer.FileTransferImpl.DataReader receipt)

### notifyListenersReceiverCancelled

    protected void notifyListenersReceiverCancelled(Receipt receipt)

### notifyListenersTransferFailed

    protected void notifyListenersTransferFailed(Receipt receipt,
                                                 boolean incoming)

### sendFile

    public FileReceipt sendFile(java.io.File f,
                                java.nio.ByteBuffer metadata,
                                byte priority,
                                Continuation<FileReceipt,java.lang.Exception> c)
                         throws java.io.IOException

  Specified by:
    `sendFile` in interface `FileTransfer`
  Throws:
    `java.io.IOException`

### sendFile

    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

  Specified by:
    `sendFile` in interface `FileTransfer`
  Parameters:
    `f` - the file to send
    `metadataBB` - 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 sending
    `offset` - where to start in the file
    `length` - how many bytes to send (must be <= fileLength-offset)
    `c` - who to notify when it is done
  Returns:
  Throws:
    `java.io.IOException`

### sendMsg

    public BBReceipt sendMsg(java.nio.ByteBuffer bb,
                             byte priority,
                             Continuation<BBReceipt,java.lang.Exception> c)

  Specified by:
    `sendMsg` in interface `FileTransfer`

### getUid

    protected int getUid()

### receiveSelectResult

    public void receiveSelectResult(AppSocket socket,
                                    boolean canRead,
                                    boolean canWrite)

  Description copied from interface: `AppSocketReceiver`
  Called when a socket is available for read/write

  Specified by:
    `receiveSelectResult` in interface `AppSocketReceiver`

### incrementFileChunksInMemory

    protected void incrementFileChunksInMemory()

### decrementFileChunksInMemory

    protected void decrementFileChunksInMemory()

### registerToReadIfPossible

    public void registerToReadIfPossible()

### receiverCancelled

    protected void receiverCancelled(int uid)

### senderCancelled

    protected void senderCancelled(int uid)

### addIncomingMessage

    public void addIncomingMessage(int uid,
                                   int size)

### addIncomingFile

    public void addIncomingFile(int uid,
                                byte[] metadata,
                                long offset,
                                long length)
                         throws java.io.IOException

  Throws:
    `java.io.IOException`

### receiveSocket

    public void receiveSocket(AppSocket socket)

  Description copied from interface: `AppSocketReceiver`
  Called when we have a new socket (due to a call to connect or accept)

  Specified by:
    `receiveSocket` in interface `AppSocketReceiver`

### requestCancel

    protected boolean requestCancel(int uid)

  Only call this on the receiver side, b/c uid is simplex

  Parameters:
    `uid` -
  Returns:
    if we can guarantee the request was cancelled

### sendCancel

    protected boolean sendCancel(int uid)

  Only call this on the sender side, b/c uid is simplex

  Parameters:
    `uid` -
  Returns:

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Rice Pastry.