public class MultiThreadURLFileSystemHelper extends URLFileSystemHelper
Modifier and Type | Class and Description |
---|---|
static interface |
MultiThreadURLFileSystemHelper.InterruptibleClosure<R,C extends java.net.URLConnection>
A closure for performing network operation in a context that they can be
interrupted.
|
Constructor and Description |
---|
MultiThreadURLFileSystemHelper() |
Modifier and Type | Method and Description |
---|---|
protected void |
closeConnection(java.net.URLConnection connection)
Close a URLConnection.
|
<R,C extends java.net.URLConnection> |
invokeInterruptibly(java.net.URL url,
MultiThreadURLFileSystemHelper.InterruptibleClosure<R,C> callable)
This method allows client to invoke IO bound operations in a way that is still Interruptible
unlike standard stream IO.
|
protected <T> T |
invokeInterruptiblyNoThrowIO(java.net.URL url,
MultiThreadURLFileSystemHelper.InterruptibleClosure<T,?> callable,
T defaultValue)
Internal convenienice version of the above method that eats the IOException and just
returns a default value.
|
protected java.net.URLConnection |
openConnection(java.net.URL url)
Open a URLConnection.
|
protected java.io.InputStream |
openInterruptibleInputStream(java.net.URL url) |
addURLFileSystemListener, appendRelativePath, areEqual, areEqualPathElems, canCreate, canDelete, canonicalize, canRead, canWrite, code, convertSuffix, createReader, createTempFile, delete, ensureSuffix, equals, exists, getBaseParent, getDefaultIcon, getFileName, getLength, getName, getParent, getPath, getPathNoExt, getPlatformPathName, getPort, getSuffix, getSystemDisplayName, getSystemIcon, getTempDirectory, hashCode, hasSuffix, haveSameAuthority, haveSameHost, haveSamePath, haveSamePort, haveSameProtocol, haveSameQuery, haveSameRef, haveSameUserInfo, isBaseURLFor, isDirectory, isDirectoryPath, isHidden, isLocal, isReadOnly, isRegularFile, isValid, lastModified, list, list, list, listRoots, ls, ls, lsCached, lsCached, mkdir, mkdirs, openInputStream, openOutputStream, removeURLFileSystemListener, rename, setLastModified, setReadOnly, toDisplayString, toEncodedString, toEncodedString, toRelativeSpec, toRelativeSpec, verifyList
protected java.net.URLConnection openConnection(java.net.URL url) throws java.io.IOException
url
- java.io.IOException
protected void closeConnection(java.net.URLConnection connection) throws java.io.IOException
connection
- java.io.IOException
public <R,C extends java.net.URLConnection> R invokeInterruptibly(java.net.URL url, MultiThreadURLFileSystemHelper.InterruptibleClosure<R,C> callable) throws java.io.IOException
This method allows client to invoke IO bound operations in a way that is still Interruptible unlike standard stream IO. With standard IO the close will not react to a interrupt until either the connection times out or the connection is closed. this can result in deadlocks caused by background threads being trapped an unable to release locks on nodes.
The closure run in a thread pool so the latency of this operation should be low; but the code in the closure should be careful not to take any locks or require any locks to prevent deadlocks elsewhere.
The type of the connection is specified by the second type parameter on the closure, this is so that the enclosing code can close any open sockets in order to bring the enclosed code to an early end. At the moment the only connection type supported is URLConnection in the future when there is a more standard HttpClient support by the JDK, in 8, then we should probably support this also.
R
- The value we are interested inC
- The value we are interested incallable
- The callable to be performed on the event queueurl
- The URL we want to work onjava.io.IOException
protected <T> T invokeInterruptiblyNoThrowIO(java.net.URL url, MultiThreadURLFileSystemHelper.InterruptibleClosure<T,?> callable, T defaultValue)
T
- The value we are interested incallable
- The callable to be performed on the event queueurl
- The URL to create the connection toprotected java.io.InputStream openInterruptibleInputStream(java.net.URL url) throws java.io.IOException
url
- The create the input stream for.java.io.IOException