Package ipsk.net
Class UploadCache
- java.lang.Object
-
- ipsk.net.UploadCache
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
HttpUploadCache
,SplittingHttpUploadCache
public abstract class UploadCache extends java.lang.Object implements java.lang.Runnable
Caches upload data and sends it to remote server.- Author:
- K.Jaensch, klausj@phonetik.uni-muenchen.de
- See Also:
Upload
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
UploadCache.EventTransformer
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
buffer
protected int
bufSize
protected float
byteRate
protected static int
CONNECT_RETRY_DELAY
protected boolean
connected
protected long
connectedTimeInMillis
protected java.net.URLConnection
connection
protected Upload
currentStream
protected int
currentStreamIndex
protected Upload[]
currentUpload
protected static boolean
DEBUG
protected static int
DEBUG_DELAY
static java.lang.String
DEF_CHECKSUM_ALGORITHM
protected static int
DEFAULT_BUFSIZE
protected static int
DEFAULT_CONNECT_RETRIES
protected UploadCache.EventTransformer
eventTransformer
protected long
guessedToUploadLength
protected long
holdLength
protected long
holdSize
protected boolean
idle
protected boolean
idleNotified
protected java.io.InputStream
inputStream
protected static int
ON_IDLE_DELAY
protected java.io.OutputStream
outputStream
protected java.lang.String
requestMethod
protected java.lang.String
responseMessage
protected boolean
running
protected long
startConnect
protected boolean
synced
protected long
totalLength
protected long
totalUploadLength
protected long
toUploadLength
protected int
transferRateLimit
protected boolean
transferRateLimitSupported
static int
UNLIMITED
protected static int
UPLOAD_RETRIES
protected static int
UPLOAD_RETRY_DELAY
protected int
uploadRetryCount
-
Constructor Summary
Constructors Constructor Description UploadCache()
Create new empty cache.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addUploadCacheListener(UploadCacheListener acl)
Add listener.protected void
calculateLength()
void
clear()
Clear all contents.void
close()
Close upload cache.protected void
fireConnected()
protected void
fireDisconnected()
protected void
fireFinished()
protected void
fireStateChanged(Upload uvb)
protected void
fireStateChangedWait(Upload uvb)
protected void
fireTryConnect()
float
getByteRate()
Get estimated upload byte rate.java.io.InputStream[]
getCachedInputStream(java.net.URL[] urls)
Try to get an input stream to cached data for the given URL.Upload
getCurrentUploadStream()
Get the current upload.long
getGuessedToUploadLength()
Get guessed bytes to upload.long
getHoldLength()
Get current count of hold bytes.long
getHoldSize()
Get maximum of bytes to hold in the cache.protected void
getNextUpload()
java.lang.String
getRequestMethod()
Get HTTP request method.int
getResponseCode()
Get current HTTP response code.java.lang.String
getResponseMessage()
Get HTTP response message.long
getTotalLength()
Get total length in bytes.long
getTotalUploadLength()
Get total bytes already uploaded.long
getToUploadLength()
Get bytes to upload.int
getTransferLimit()
boolean
isConnected()
Get connected status.boolean
isIdle()
Get idle status.boolean
isOverwrite()
boolean
isRunning()
Get upload running status.boolean
isTransferLimitSupported()
void
removeUploadCacheListener(UploadCacheListener acl)
Remove listener.abstract void
run()
void
setHoldSize(long l)
Set maximum of bytes to hold in the cache.void
setOverwrite(boolean overwrite)
void
setRequestMethod(java.lang.String string)
Set HTTP request method.void
setTransferLimit(int transferLimit)
void
setTransferLimitSupported(boolean transferLimitSupported)
void
start()
Start upload.void
stop()
Stop upload.void
upload(Upload[] vbs)
Request an upload of the referenced data buffers to the given URLs.
-
-
-
Field Detail
-
DEF_CHECKSUM_ALGORITHM
public static final java.lang.String DEF_CHECKSUM_ALGORITHM
- See Also:
- Constant Field Values
-
DEBUG
protected static boolean DEBUG
-
UNLIMITED
public static final int UNLIMITED
- See Also:
- Constant Field Values
-
ON_IDLE_DELAY
protected static int ON_IDLE_DELAY
-
CONNECT_RETRY_DELAY
protected static int CONNECT_RETRY_DELAY
-
DEFAULT_CONNECT_RETRIES
protected static int DEFAULT_CONNECT_RETRIES
-
UPLOAD_RETRY_DELAY
protected static int UPLOAD_RETRY_DELAY
-
UPLOAD_RETRIES
protected static int UPLOAD_RETRIES
-
DEBUG_DELAY
protected static int DEBUG_DELAY
-
DEFAULT_BUFSIZE
protected static int DEFAULT_BUFSIZE
-
byteRate
protected float byteRate
-
connectedTimeInMillis
protected long connectedTimeInMillis
-
totalUploadLength
protected long totalUploadLength
-
connected
protected boolean connected
-
idle
protected boolean idle
-
idleNotified
protected boolean idleNotified
-
bufSize
protected int bufSize
-
outputStream
protected java.io.OutputStream outputStream
-
inputStream
protected java.io.InputStream inputStream
-
buffer
protected byte[] buffer
-
connection
protected java.net.URLConnection connection
-
requestMethod
protected java.lang.String requestMethod
-
currentUpload
protected Upload[] currentUpload
-
currentStream
protected Upload currentStream
-
currentStreamIndex
protected int currentStreamIndex
-
running
protected boolean running
-
eventTransformer
protected UploadCache.EventTransformer eventTransformer
-
startConnect
protected long startConnect
-
totalLength
protected long totalLength
-
toUploadLength
protected long toUploadLength
-
guessedToUploadLength
protected long guessedToUploadLength
-
holdLength
protected long holdLength
-
holdSize
protected long holdSize
-
synced
protected boolean synced
-
responseMessage
protected java.lang.String responseMessage
-
uploadRetryCount
protected int uploadRetryCount
-
transferRateLimitSupported
protected boolean transferRateLimitSupported
-
transferRateLimit
protected int transferRateLimit
-
-
Method Detail
-
calculateLength
protected void calculateLength()
-
upload
public void upload(Upload[] vbs) throws UploadException
Request an upload of the referenced data buffers to the given URLs.- Parameters:
vbs
- the container of buffer references with data to upload- Throws:
UploadException
-
getCachedInputStream
public java.io.InputStream[] getCachedInputStream(java.net.URL[] urls) throws UploadException
Try to get an input stream to cached data for the given URL.- Parameters:
urls
-- Returns:
- the input stream if the requested data was found in the cache
null
if the requested URL data was not found in the cache
- Throws:
UploadException
-
start
public void start()
Start upload.
-
stop
public void stop()
Stop upload.
-
getNextUpload
protected void getNextUpload()
-
run
public abstract void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
getCurrentUploadStream
public Upload getCurrentUploadStream()
Get the current upload.- Returns:
- current upload
-
isConnected
public boolean isConnected()
Get connected status.- Returns:
- true if connected
-
clear
public void clear()
Clear all contents.
-
close
public void close()
Close upload cache. Same as stop() and clear().
-
addUploadCacheListener
public void addUploadCacheListener(UploadCacheListener acl)
Add listener.- Parameters:
acl
- listener to add
-
removeUploadCacheListener
public void removeUploadCacheListener(UploadCacheListener acl)
Remove listener.- Parameters:
acl
- listener to remove
-
fireConnected
protected void fireConnected()
-
fireTryConnect
protected void fireTryConnect()
-
fireStateChanged
protected void fireStateChanged(Upload uvb)
-
fireStateChangedWait
protected void fireStateChangedWait(Upload uvb)
-
fireDisconnected
protected void fireDisconnected()
-
fireFinished
protected void fireFinished()
-
getTotalLength
public long getTotalLength()
Get total length in bytes.- Returns:
- total length of
-
getTotalUploadLength
public long getTotalUploadLength()
Get total bytes already uploaded.- Returns:
- uploaded count of bytes
-
isIdle
public boolean isIdle()
Get idle status.- Returns:
- idle status
-
getResponseCode
public int getResponseCode()
Get current HTTP response code.- Returns:
- HTTP response code
-
getResponseMessage
public java.lang.String getResponseMessage()
Get HTTP response message.- Returns:
- HTTP response message
-
getHoldSize
public long getHoldSize()
Get maximum of bytes to hold in the cache.- Returns:
- maximum hold size
-
setHoldSize
public void setHoldSize(long l)
Set maximum of bytes to hold in the cache.- Parameters:
l
- maximum hold size
-
getHoldLength
public long getHoldLength()
Get current count of hold bytes.- Returns:
- bytes currently hold
-
getByteRate
public float getByteRate()
Get estimated upload byte rate.- Returns:
- byte rate in bytes/second
-
getToUploadLength
public long getToUploadLength()
Get bytes to upload. The current upload is ignored.- Returns:
- bytes to upload
- See Also:
getGuessedToUploadLength()
-
getGuessedToUploadLength
public long getGuessedToUploadLength()
Get guessed bytes to upload. The progress of the current upload can only be estimated.- Returns:
- estimated count of bytes not yet uploaded
-
getRequestMethod
public java.lang.String getRequestMethod()
Get HTTP request method.- Returns:
- request method
-
setRequestMethod
public void setRequestMethod(java.lang.String string)
Set HTTP request method.- Parameters:
string
- request method
-
isRunning
public boolean isRunning()
Get upload running status.- Returns:
- true if upload thread is running.
-
isOverwrite
public boolean isOverwrite()
-
setOverwrite
public void setOverwrite(boolean overwrite)
-
getTransferLimit
public int getTransferLimit()
-
setTransferLimit
public void setTransferLimit(int transferLimit)
-
isTransferLimitSupported
public boolean isTransferLimitSupported()
-
setTransferLimitSupported
public void setTransferLimitSupported(boolean transferLimitSupported)
-
-