org.tranche.add
Class AddFileTool

java.lang.Object
  extended by org.tranche.commons.Debuggable
      extended by org.tranche.add.AddFileTool

public class AddFileTool
extends org.tranche.commons.Debuggable

A helper utility that adds single files or directories (a.k.a. "data sets" or "projects") of files to the repository.

Author:
James "Augie" Hill - augman85@gmail.com, Jayson Falkner - jfalkner@umich.edu, Bryan E. Smith - bryanesmith@gmail.com

Field Summary
static boolean DEFAULT_CHECK_EXISTING_CHUNKS
           
static boolean DEFAULT_COMPRESS
           
static boolean DEFAULT_DATA_ONLY
           
static int DEFAULT_DATA_QUEUE_SIZE
           
static boolean DEFAULT_EMAIL_ON_FAILURE
           
static boolean DEFAULT_EXPLODE_BEFORE_UPLOAD
           
static int DEFAULT_META_DATA_QUEUE_SIZE
           
static int DEFAULT_MINIMUM_THREADS
           
static boolean DEFAULT_SHOW_META_DATA_IF_ENCRYPTED
           
static boolean DEFAULT_SHOW_SUMMARY
           
static int DEFAULT_SIZE_FILE_ENCODING_BUFFER
           
static int DEFAULT_THREADS
          Default parameters
static boolean DEFAULT_USE_PERFORMANCE_LOG
           
static boolean DEFAULT_USE_UNSPECIFIED_SERVERS
           
 
Constructor Summary
AddFileTool()
           
 
Method Summary
 boolean addConfirmationEmail(java.lang.String email)
          Adds
 boolean addConfirmationEmails(java.util.Collection<java.lang.String> emails)
           
 boolean addListener(AddFileToolListener l)
          Adds a listener.
 void addMetaDataAnnotation(MetaDataAnnotation annotation)
          Adds the given meta data annotation to the meta data annotations.
 boolean addServersToUse(java.util.Collection<java.lang.String> serverHostNames)
          Adds a collection of server host names to be used during upload.
 boolean addServerToUse(java.lang.String serverHostName)
          Adds the host name of a server to be used during upload.
 boolean addStickyServer(java.lang.String serverHostName)
          Adds the host name of a server to which data should be stuck.
 boolean addStickyServers(java.util.Collection<java.lang.String> serverHostNames)
          Adds a collection of server host names to which data should be stuck.
 void clearMetaDataAnnotations()
          Clears the meta data annotations.
 void clearPassphrase()
          Unsets the passphrase -- the upload will not be encrypted.
 AddFileToolReport execute()
           
 AddFileToolReport execute(long startTimestamp)
           
 long getBytesToUpload()
          Gets the number of bytes that are being uploaded.
 long getBytesUploaded()
          Gets the number of bytes that have been uploaded.
 java.util.Collection<java.lang.String> getConfirmationEmails()
           
protected  java.util.Collection<java.lang.String> getCoreServersToUploadTo(BigHash hash)
          Gets a collection of hosts of core writable servers to which a chunk with the given hash should be uploaded.
 java.lang.String getDescription()
          Gets the description of the upload.
 java.io.File getFile()
           
 int getFileCount()
           
 License getLicense()
          Gets the license to be attached to the upload.
 java.util.Collection<AddFileToolListener> getListeners()
           
 java.util.Collection<MetaDataAnnotation> getMetaDataAnnotations()
          Gets the meta data annotations to be added to the data set's project file meta data.
protected  java.util.Collection<java.lang.String> getNonCoreServersToUploadTo(BigHash hash)
          Gets a collection of hosts of non-core writable servers to which one should upload a chunk with the given hash.
 java.lang.String getPassphrase()
          Gets the passphrase that will be used to encrypt the data.
 java.util.Collection<java.lang.String> getServersToUse()
          Gets the collection of server host names to be used.
 long getSize()
           
 java.util.Collection<java.lang.String> getStickyServers()
          Gets the collection of server host names to which data should be stuck.
 int getThreadCount()
          Gets the number of threads to be used.
 TimeEstimator getTimeEstimator()
          Gets the time to upload object.
 java.lang.String getTitle()
          Gets the title of the upload.
 java.security.cert.X509Certificate getUserCertificate()
          Gets the certificate for the uploading user.
 java.security.PrivateKey getUserPrivateKey()
          Gets the private key for the uploading user.
 boolean isCompress()
          Gets whether the files should be compressed before upload.
 boolean isDataOnly()
          Gets whether only the data chunks will be uploaded.
 boolean isEmailOnFailure()
           
 boolean isExecuting()
           
 boolean isExplodeBeforeUpload()
          Gets whether to try to decompress/unpack a compressed or bundled archive before uploading it.
 boolean isLocked()
           
 boolean isPaused()
          Gets whether the upload is paused.
 boolean isSendPerformanceInfo()
          
 boolean isShowMetaDataIfEncrypted()
           
 boolean isStopped()
           
 boolean isUsingUnspecifiedServers()
          Whether servers other than the ones specified should be used.
static void main(java.lang.String[] args)
          Command-line interface to tool.
 boolean removeConfirmationEmail(java.lang.String email)
           
 boolean removeConfirmationEmails(java.util.Collection<java.lang.String> emails)
           
 boolean removeListener(AddFileToolListener l)
          Removes a listener.
 boolean removeServersToUse(java.util.Collection<java.lang.String> serverHostNames)
          Removes a collection of host names from the list of servers to be used.
 boolean removeServerToUse(java.lang.String serverHostName)
          Removes the server host name from the list of servers to be used.
 boolean removeStickyServer(java.lang.String serverHostName)
          Removes the server host name from the list of sticky servers.
 boolean removeStickyServers(java.util.Collection<java.lang.String> serverHostNames)
          Removes a collection of host names from the list of sticky servers.
 void setCompress(boolean compress)
          Sets whether the files should be compressed before upload.
 void setDataOnly(boolean dataOnly)
          Sets whether only the data chunks will be uploaded.
 void setDescription(java.lang.String description)
          Sets the description of the upload.
 void setEmailOnFailure(boolean emailOnFailure)
           
 void setExplodeBeforeUpload(boolean explodeBeforeUpload)
          Sets whether to try to decompress/unpack a compressed or bundled archive before uploading it.
 void setFile(java.io.File file)
           
 void setLicense(License license)
          Sets the license to be attached to the upload.
 void setMetaDataAnnotations(java.util.Collection<MetaDataAnnotation> annotations)
          Sets the meta data annotations to be added to the data set's project file meta data.
 void setPassphrase(java.lang.String passphrase)
          Sets the passphrase with which to encrypt the data.
 void setPause(boolean paused)
          Set whether the upload is paused.
 void setSendPerformanceInfo(boolean sendPerformanceInfo)
          
 boolean setServersToUse(java.util.Collection<java.lang.String> serverHostNames)
           
 void setShowMetaDataIfEncrypted(boolean showMetaDataIfEncrypted)
           
 boolean setStickyServers(java.util.Collection<java.lang.String> serverHostNames)
           
 void setThreadCount(int threadCount)
          Sets the number of threads to be used.
 void setTitle(java.lang.String title)
          Sets the title of the upload.
protected  void setUpConnections()
          Used internally to establish and lock connections with servers that will be used.
 void setUserCertificate(java.security.cert.X509Certificate userCertificate)
          Sets the certificate for the uploading user.
 void setUserPrivateKey(java.security.PrivateKey userPrivateKey)
          Sets the private key for the uploading user.
 void setUseUnspecifiedServers(boolean useUnspecifiedServers)
          Sets whether servers other than the ones specified should be used.
 void stop()
          Stops the upload.
protected  void tearDownConnections()
          Used internally to unlock connections made during set-up.
 void throwExceptionIfLocked()
           
 
Methods inherited from class org.tranche.commons.Debuggable
debugErr, debugErr, debugOut, isDebug, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_THREADS

public static int DEFAULT_THREADS
Default parameters


DEFAULT_MINIMUM_THREADS

public static int DEFAULT_MINIMUM_THREADS

DEFAULT_DATA_QUEUE_SIZE

public static int DEFAULT_DATA_QUEUE_SIZE

DEFAULT_META_DATA_QUEUE_SIZE

public static int DEFAULT_META_DATA_QUEUE_SIZE

DEFAULT_SIZE_FILE_ENCODING_BUFFER

public static int DEFAULT_SIZE_FILE_ENCODING_BUFFER

DEFAULT_CHECK_EXISTING_CHUNKS

public static boolean DEFAULT_CHECK_EXISTING_CHUNKS

DEFAULT_USE_UNSPECIFIED_SERVERS

public static boolean DEFAULT_USE_UNSPECIFIED_SERVERS

DEFAULT_EXPLODE_BEFORE_UPLOAD

public static boolean DEFAULT_EXPLODE_BEFORE_UPLOAD

DEFAULT_COMPRESS

public static boolean DEFAULT_COMPRESS

DEFAULT_DATA_ONLY

public static boolean DEFAULT_DATA_ONLY

DEFAULT_SHOW_SUMMARY

public static boolean DEFAULT_SHOW_SUMMARY

DEFAULT_SHOW_META_DATA_IF_ENCRYPTED

public static boolean DEFAULT_SHOW_META_DATA_IF_ENCRYPTED

DEFAULT_EMAIL_ON_FAILURE

public static boolean DEFAULT_EMAIL_ON_FAILURE

DEFAULT_USE_PERFORMANCE_LOG

public static boolean DEFAULT_USE_PERFORMANCE_LOG
Constructor Detail

AddFileTool

public AddFileTool()
Method Detail

isExecuting

public boolean isExecuting()
Returns:

isLocked

public boolean isLocked()
Returns:

throwExceptionIfLocked

public void throwExceptionIfLocked()

setCompress

public void setCompress(boolean compress)

Sets whether the files should be compressed before upload.

Parameters:
compress - Whether the files should be compressed before upload.

isCompress

public boolean isCompress()

Gets whether the files should be compressed before upload.

Returns:
Whether the files should be compressed before upload.

setExplodeBeforeUpload

public void setExplodeBeforeUpload(boolean explodeBeforeUpload)

Sets whether to try to decompress/unpack a compressed or bundled archive before uploading it.

Parameters:
explodeBeforeUpload - Whether to try to decompress/unpack a compressed or bundled archive before uploading it.

isExplodeBeforeUpload

public boolean isExplodeBeforeUpload()

Gets whether to try to decompress/unpack a compressed or bundled archive before uploading it.


setDataOnly

public void setDataOnly(boolean dataOnly)

Sets whether only the data chunks will be uploaded.

Parameters:
dataOnly - Whether only the data chunks will be uploaded.

isDataOnly

public boolean isDataOnly()

Gets whether only the data chunks will be uploaded.

Returns:
Whether only the data chunks will be uploaded.

setEmailOnFailure

public void setEmailOnFailure(boolean emailOnFailure)
Parameters:
emailOnFailure -

isEmailOnFailure

public boolean isEmailOnFailure()
Returns:

setShowMetaDataIfEncrypted

public void setShowMetaDataIfEncrypted(boolean showMetaDataIfEncrypted)
Parameters:
showMetaDataIfEncrypted -

isShowMetaDataIfEncrypted

public boolean isShowMetaDataIfEncrypted()
Returns:

setLicense

public void setLicense(License license)

Sets the license to be attached to the upload.

Parameters:
license - The license to be attached to the upload.

getLicense

public License getLicense()

Gets the license to be attached to the upload.

Returns:
The license to be attached to the upload.

setUserCertificate

public void setUserCertificate(java.security.cert.X509Certificate userCertificate)

Sets the certificate for the uploading user.

Parameters:
userCertificate - The certificate for the uploading user.

getUserCertificate

public java.security.cert.X509Certificate getUserCertificate()

Gets the certificate for the uploading user.

Returns:
The certificate for hte uploading user.

setUserPrivateKey

public void setUserPrivateKey(java.security.PrivateKey userPrivateKey)

Sets the private key for the uploading user.

Parameters:
userPrivateKey - The private key for the uploading user.

getUserPrivateKey

public java.security.PrivateKey getUserPrivateKey()

Gets the private key for the uploading user.

Returns:
The private key for the uploading user.

setTitle

public void setTitle(java.lang.String title)

Sets the title of the upload.

Parameters:
title - The title of the upload.

getTitle

public java.lang.String getTitle()

Gets the title of the upload.

Returns:
The title of the upload.

setDescription

public void setDescription(java.lang.String description)

Sets the description of the upload.

Parameters:
description - The description of the upload.

getDescription

public java.lang.String getDescription()

Gets the description of the upload.

Returns:
The description of the upload.

setPassphrase

public void setPassphrase(java.lang.String passphrase)

Sets the passphrase with which to encrypt the data.

Parameters:
passphrase - The passphrase with which to encrypt the data.

clearPassphrase

public void clearPassphrase()

Unsets the passphrase -- the upload will not be encrypted.


getPassphrase

public java.lang.String getPassphrase()

Gets the passphrase that will be used to encrypt the data.

Returns:
The passphrase that will be used to encrypt the data.

setMetaDataAnnotations

public void setMetaDataAnnotations(java.util.Collection<MetaDataAnnotation> annotations)

Sets the meta data annotations to be added to the data set's project file meta data.

Parameters:
annotations - The meta data annotations.

addMetaDataAnnotation

public void addMetaDataAnnotation(MetaDataAnnotation annotation)

Adds the given meta data annotation to the meta data annotations.

Parameters:
annotation - A meta data annotation.

clearMetaDataAnnotations

public void clearMetaDataAnnotations()

Clears the meta data annotations.


getMetaDataAnnotations

public java.util.Collection<MetaDataAnnotation> getMetaDataAnnotations()

Gets the meta data annotations to be added to the data set's project file meta data.

Returns:
The meta data annotations to be added to the data set's project file meta data.

addConfirmationEmail

public boolean addConfirmationEmail(java.lang.String email)

Adds

Parameters:
email -
Returns:

addConfirmationEmails

public boolean addConfirmationEmails(java.util.Collection<java.lang.String> emails)
Parameters:
emails -
Returns:

removeConfirmationEmail

public boolean removeConfirmationEmail(java.lang.String email)
Parameters:
email -
Returns:

removeConfirmationEmails

public boolean removeConfirmationEmails(java.util.Collection<java.lang.String> emails)
Parameters:
emails -
Returns:

getConfirmationEmails

public java.util.Collection<java.lang.String> getConfirmationEmails()
Returns:

addStickyServer

public boolean addStickyServer(java.lang.String serverHostName)

Adds the host name of a server to which data should be stuck.

Parameters:
serverHostName - The host name of a server.
Returns:
Whether the host name was added to the list.

addStickyServers

public boolean addStickyServers(java.util.Collection<java.lang.String> serverHostNames)

Adds a collection of server host names to which data should be stuck.

Parameters:
serverHostNames - A collection of host names.
Returns:
Whether the host names were added to the list.

removeStickyServer

public boolean removeStickyServer(java.lang.String serverHostName)

Removes the server host name from the list of sticky servers.

Parameters:
serverHostName - The host name of a server.
Returns:
Whether the host name was removed from the list.

removeStickyServers

public boolean removeStickyServers(java.util.Collection<java.lang.String> serverHostNames)

Removes a collection of host names from the list of sticky servers.

Parameters:
serverHostNames - A collection of server host names.
Returns:
Whether the host names were removed from the list.

getStickyServers

public java.util.Collection<java.lang.String> getStickyServers()

Gets the collection of server host names to which data should be stuck.

Returns:
A collection of server host names.

setStickyServers

public boolean setStickyServers(java.util.Collection<java.lang.String> serverHostNames)
Parameters:
serverHostNames -
Returns:

addServerToUse

public boolean addServerToUse(java.lang.String serverHostName)

Adds the host name of a server to be used during upload.

Parameters:
serverHostName - The host name of a server.
Returns:
Whether the host name was added to the list.

addServersToUse

public boolean addServersToUse(java.util.Collection<java.lang.String> serverHostNames)

Adds a collection of server host names to be used during upload.

Parameters:
serverHostNames - A collection of host names to be used during upload.
Returns:
Whether the host names were added to the list.

setServersToUse

public boolean setServersToUse(java.util.Collection<java.lang.String> serverHostNames)
Parameters:
serverHostNames -
Returns:

removeServerToUse

public boolean removeServerToUse(java.lang.String serverHostName)

Removes the server host name from the list of servers to be used.

Parameters:
serverHostName - The host name of a server.
Returns:
Whether the host name was removed from the list.

removeServersToUse

public boolean removeServersToUse(java.util.Collection<java.lang.String> serverHostNames)

Removes a collection of host names from the list of servers to be used.

Parameters:
serverHostNames - A collection of server host names.
Returns:
Whether the host names were removed from the list.

getServersToUse

public java.util.Collection<java.lang.String> getServersToUse()

Gets the collection of server host names to be used.

Returns:
A collection of server host names.

setUseUnspecifiedServers

public void setUseUnspecifiedServers(boolean useUnspecifiedServers)

Sets whether servers other than the ones specified should be used.

Parameters:
useUnspecifiedServers - Whether servers other than the ones specified should be used.

isUsingUnspecifiedServers

public boolean isUsingUnspecifiedServers()

Whether servers other than the ones specified should be used.

Returns:
Whether servers other than the ones specified should be used.

setSendPerformanceInfo

public void setSendPerformanceInfo(boolean sendPerformanceInfo)

Parameters:
sendPerformanceInfo -

isSendPerformanceInfo

public boolean isSendPerformanceInfo()

Returns:

setPause

public void setPause(boolean paused)

Set whether the upload is paused.

Parameters:
paused - Whether the upload is paused.

isPaused

public boolean isPaused()

Gets whether the upload is paused.

Returns:
Whether the upload is paused.

stop

public void stop()

Stops the upload.


isStopped

public boolean isStopped()
Returns:

addListener

public boolean addListener(AddFileToolListener l)

Adds a listener.

Parameters:
l - A listener.
Returns:
Whether the listener was added.

removeListener

public boolean removeListener(AddFileToolListener l)

Removes a listener.

Parameters:
l - A listener.
Returns:
Whether the listener was removed.

getListeners

public java.util.Collection<AddFileToolListener> getListeners()
Returns:

getBytesToUpload

public long getBytesToUpload()

Gets the number of bytes that are being uploaded.

Returns:
The number of bytes that are being uploaded.

getBytesUploaded

public long getBytesUploaded()

Gets the number of bytes that have been uploaded.

Returns:
The number of bytes that have been uploaded.

getTimeEstimator

public TimeEstimator getTimeEstimator()

Gets the time to upload object.

Returns:
The time to upload object.

setThreadCount

public void setThreadCount(int threadCount)

Sets the number of threads to be used.

Parameters:
threadCount - The number of threads to be used.

getThreadCount

public int getThreadCount()

Gets the number of threads to be used.

Returns:
The number of threads to be used.

getFile

public java.io.File getFile()
Returns:

getFileCount

public int getFileCount()
Returns:

getSize

public long getSize()
Returns:

setFile

public void setFile(java.io.File file)
Parameters:
file -

setUpConnections

protected void setUpConnections()
                         throws java.lang.Exception

Used internally to establish and lock connections with servers that will be used.

Throws:
java.lang.Exception

tearDownConnections

protected void tearDownConnections()

Used internally to unlock connections made during set-up.


getCoreServersToUploadTo

protected java.util.Collection<java.lang.String> getCoreServersToUploadTo(BigHash hash)

Gets a collection of hosts of core writable servers to which a chunk with the given hash should be uploaded.

Parameters:
hash -
Returns:

getNonCoreServersToUploadTo

protected java.util.Collection<java.lang.String> getNonCoreServersToUploadTo(BigHash hash)

Gets a collection of hosts of non-core writable servers to which one should upload a chunk with the given hash.

Parameters:
hash -
Returns:

execute

public AddFileToolReport execute()
Returns:

execute

public AddFileToolReport execute(long startTimestamp)
Parameters:
startTimestamp -
Returns:

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception

Command-line interface to tool. Use -h or --help to see usage.

Parameters:
args - The set of arguments to be used when parsing the program.
Throws:
java.lang.Exception


This code is free for use both commercially and non-commercially as stated in the project's license