JXTA

net.jxta.impl.content.defprovider
Class DefaultContentTransfer

java.lang.Object
  extended by net.jxta.impl.content.AbstractContentTransfer
      extended by net.jxta.impl.content.defprovider.DefaultContentTransfer
All Implemented Interfaces:
EventListener, ContentTransfer, PipeMsgListener

public class DefaultContentTransfer
extends AbstractContentTransfer
implements PipeMsgListener


Field Summary
 
Fields inherited from class net.jxta.impl.content.AbstractContentTransfer
DEFAULT_DISCOVERY_THRESHOLD, DEFAULT_ENABLE_LOCAL, DEFAULT_ENABLE_REMOTE, DEFAULT_MAX_STALLS, DEFAULT_SOURCE_LOCATION_INTERVAL
 
Constructor Summary
DefaultContentTransfer(DefaultContentProvider origin, ScheduledExecutorService schedExecutor, PeerGroup group, ContentID contentID)
          Constructor for use with ContentIDs.
DefaultContentTransfer(DefaultContentProvider origin, ScheduledExecutorService schedExecutor, PeerGroup group, ContentShareAdvertisement contentAdv)
          Constructor for use with ContentShareAdvertisements.
 
Method Summary
 void cancel()
          Cancels all remote data source location and Content transfer activity, if still in progress.
protected  int getEnoughLocationCount()
          Gets the number of source location advertisements that must be obtained before attempting to start a transfer.
protected  int getManyLocationCount()
          Gets the number of source location advertisements that must be obtained before source location will be shut down.
protected  boolean isAdvertisementOfUse(ContentShareAdvertisement adv)
          Determines whether or not the advertisement provided is of use to the provider.
 void pipeMsgEvent(PipeMsgEvent pme)
          Processes incoming Content service requests.
 void processMessage(Message msg)
          Processes incoming Content service responses.
protected  ContentTransferState transferAttempt(File dest, List<ContentShareAdvertisement> sources, List<ContentShareAdvertisement> newSources)
          Attempt to transfer the content from the allSources provided, using the specified destination file for data storage.
 
Methods inherited from class net.jxta.impl.content.AbstractContentTransfer
addContentTransferListener, getContent, getContentProvider, getContentTransferListeners, getSourceLocationState, getTransferContentID, getTransferState, removeContentTransferListener, setContent, setDiscoveryThreshold, setLocalDiscoveryEnabled, setRemoteDiscoveryEnabled, setSourceLocationInterval, startSourceLocation, startTransfer, stopSourceLocation, waitFor, waitFor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultContentTransfer

public DefaultContentTransfer(DefaultContentProvider origin,
                              ScheduledExecutorService schedExecutor,
                              PeerGroup group,
                              ContentShareAdvertisement contentAdv)
Constructor for use with ContentShareAdvertisements.

Parameters:
origin - content provider which created and manager this transfer
schedExecutor - executor to use when running tasks
group - parent peer group
contentAdv - content that we want to retrieve

DefaultContentTransfer

public DefaultContentTransfer(DefaultContentProvider origin,
                              ScheduledExecutorService schedExecutor,
                              PeerGroup group,
                              ContentID contentID)
Constructor for use with ContentIDs.

Parameters:
origin - content provider which created and manager this transfer
schedExecutor - executor to use when running tasks
group - parent peer group
contentID - ID of the content that we want to retrieve
Method Detail

getEnoughLocationCount

protected int getEnoughLocationCount()
Gets the number of source location advertisements that must be obtained before attempting to start a transfer. Typically, this will be a small number, even 1.

Specified by:
getEnoughLocationCount in class AbstractContentTransfer
Returns:
number of advertisements to discover before transfer will be attempted

getManyLocationCount

protected int getManyLocationCount()
Gets the number of source location advertisements that must be obtained before source location will be shut down. This should represent some happy medium between having too few allSources to be efficient and having too many allSources to practically use.

Specified by:
getManyLocationCount in class AbstractContentTransfer
Returns:
number of advertisements to discover before source location will be stopped

isAdvertisementOfUse

protected boolean isAdvertisementOfUse(ContentShareAdvertisement adv)
Determines whether or not the advertisement provided is of use to the provider. Advertisements not of use are not counted toward the provider's "enough" and "many" thresholds.

Specified by:
isAdvertisementOfUse in class AbstractContentTransfer
Parameters:
adv - advertisement to test
Returns:
true if advertisment is of use, false otherwise

transferAttempt

protected ContentTransferState transferAttempt(File dest,
                                               List<ContentShareAdvertisement> sources,
                                               List<ContentShareAdvertisement> newSources)
                                        throws TransferException
Attempt to transfer the content from the allSources provided, using the specified destination file for data storage.

Specified by:
transferAttempt in class AbstractContentTransfer
Parameters:
dest - destination file which should be used to store the content data
sources - all currently known sources
newSources - all sources which have been discovered since the last transfer attempt
Returns:
content transfer state best representing the results of this attempt. Must be set to ContentState.COMPLETED on success, in which case the implementation must have called setContent().
Throws:
TransferException - when a problem occurs during transfer attempt

cancel

public void cancel()
Cancels all remote data source location and Content transfer activity, if still in progress. After a transfer has been cancelled it can no longer be used to locate sources or retrieve data.

Specified by:
cancel in interface ContentTransfer
Overrides:
cancel in class AbstractContentTransfer

pipeMsgEvent

public void pipeMsgEvent(PipeMsgEvent pme)
Processes incoming Content service requests.

Specified by:
pipeMsgEvent in interface PipeMsgListener
Parameters:
pme - pipe message event received

processMessage

public void processMessage(Message msg)
Processes incoming Content service responses.

Parameters:
msg - message received

JXSE