- java.lang.Object
-
- org.xnio.Xnio
-
public abstract class Xnio extends java.lang.Object
The XNIO provider class.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
NIO2
A flag indicating the presence of NIO.2 (JDK 7).
-
Constructor Summary
Constructors Modifier Constructor Description protected
Xnio(java.lang.String name)
Construct an XNIO provider instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static boolean
allowBlocking(boolean newSetting)
Allow (or disallow) blocking I/O on the current thread.protected abstract XnioWorker
build(XnioWorker.Builder builder)
Construct an XNIO worker from a builder.static void
checkBlockingAllowed()
Perform a check for whether blocking is allowed on the current thread.FileSystemWatcher
createFileSystemWatcher(java.lang.String name, OptionMap options)
Creates a file system watcher, that can be used to monitor file system changes.XnioWorker
createWorker(java.lang.ThreadGroup threadGroup, OptionMap optionMap)
Construct a new XNIO worker.XnioWorker
createWorker(java.lang.ThreadGroup threadGroup, OptionMap optionMap, java.lang.Runnable terminationTask)
Construct a new XNIO worker.XnioWorker
createWorker(OptionMap optionMap)
Construct a new XNIO worker.XnioWorker.Builder
createWorkerBuilder()
Create a new worker builder.static Xnio
getInstance()
Get an XNIO provider instance from XNIO's class loader.static Xnio
getInstance(java.lang.ClassLoader classLoader)
Get an XNIO provider instance.static Xnio
getInstance(java.lang.String provider)
Get a specific XNIO provider instance from XNIO's class loader.static Xnio
getInstance(java.lang.String provider, java.lang.ClassLoader classLoader)
Get a specific XNIO provider instance.java.lang.String
getName()
Get the name of this XNIO provider.protected static java.lang.String
getProperty(java.lang.String name)
Get an XNIO property.protected static java.lang.String
getProperty(java.lang.String name, java.lang.String defaultValue)
Get an XNIO property.XnioSsl
getSslProvider(javax.net.ssl.KeyManager[] keyManagers, javax.net.ssl.TrustManager[] trustManagers, OptionMap optionMap)
Get an SSL provider for this XNIO provider.XnioSsl
getSslProvider(OptionMap optionMap)
Get an SSL provider for this XNIO provider.protected void
handleThreadExit()
Implement tasks that will be executed on thread exits if a task worker thread is initialized throughXnioWorker$WorkerThreadFactory
.static boolean
isBlockingAllowed()
Determine whether blocking I/O is allowed from the current thread.java.nio.channels.FileChannel
openFile(java.io.File file, FileAccess access)
Open a file on the filesystem.java.nio.channels.FileChannel
openFile(java.io.File file, OptionMap options)
Open a file on the filesystem.java.nio.channels.FileChannel
openFile(java.lang.String fileName, FileAccess access)
Open a file on the filesystem.java.nio.channels.FileChannel
openFile(java.lang.String fileName, OptionMap options)
Open a file on the filesystem.protected static java.io.Closeable
register(XnioProviderMXBean providerMXBean)
Register an MBean.protected static java.io.Closeable
register(XnioServerMXBean serverMXBean)
Register an MBean.protected static java.io.Closeable
register(XnioWorkerMXBean workerMXBean)
Register an MBean.java.lang.String
toString()
Get a string representation of this XNIO provider.protected java.nio.channels.FileChannel
unwrapFileChannel(java.nio.channels.FileChannel src)
Unwrap an XNIO-wrapped file channel.
-
-
-
Field Detail
-
NIO2
public static final boolean NIO2
A flag indicating the presence of NIO.2 (JDK 7). Alwaystrue
as of XNIO version 3.5.0, which requires Java 8.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Xnio
protected Xnio(java.lang.String name)
Construct an XNIO provider instance. Used by implementors only. To get an XNIO instance, use one of thegetInstance()
methods.- Parameters:
name
- the provider name
-
-
Method Detail
-
allowBlocking
public static boolean allowBlocking(boolean newSetting) throws java.lang.SecurityException
Allow (or disallow) blocking I/O on the current thread. Requires thechangeThreadBlockingSetting
RuntimePermission
.- Parameters:
newSetting
-true
to allow blocking I/O,false
to disallow it- Returns:
- the previous setting
- Throws:
java.lang.SecurityException
- if a security manager is present and disallows changing thechangeThreadBlockingSetting
RuntimePermission
-
isBlockingAllowed
public static boolean isBlockingAllowed()
Determine whether blocking I/O is allowed from the current thread.- Returns:
true
if blocking I/O is allowed,false
otherwise
-
checkBlockingAllowed
public static void checkBlockingAllowed() throws java.lang.IllegalStateException
Perform a check for whether blocking is allowed on the current thread.- Throws:
java.lang.IllegalStateException
- if blocking is not allowed on the current thread
-
getInstance
public static Xnio getInstance(java.lang.ClassLoader classLoader)
Get an XNIO provider instance. If multiple providers are available, use the first one encountered.- Parameters:
classLoader
- the class loader to search in- Returns:
- the XNIO provider instance
- Since:
- 3.0
-
getInstance
public static Xnio getInstance()
Get an XNIO provider instance from XNIO's class loader. If multiple providers are available, use the first one encountered.- Returns:
- the XNIO provider instance
- Since:
- 3.0
-
getInstance
public static Xnio getInstance(java.lang.String provider, java.lang.ClassLoader classLoader)
Get a specific XNIO provider instance.- Parameters:
provider
- the provider name, ornull
for the first availableclassLoader
- the class loader to search in- Returns:
- the XNIO provider instance
- Since:
- 3.0
-
getInstance
public static Xnio getInstance(java.lang.String provider)
Get a specific XNIO provider instance from XNIO's class loader.- Parameters:
provider
- the provider name, ornull
for the first available- Returns:
- the XNIO provider instance
- Since:
- 3.0
-
getSslProvider
public XnioSsl getSslProvider(OptionMap optionMap) throws java.security.GeneralSecurityException
Get an SSL provider for this XNIO provider.- Parameters:
optionMap
- the option map to use for configuring SSL- Returns:
- the SSL provider
- Throws:
java.security.GeneralSecurityException
- if an exception occurred configuring the SSL provider
-
getSslProvider
public XnioSsl getSslProvider(javax.net.ssl.KeyManager[] keyManagers, javax.net.ssl.TrustManager[] trustManagers, OptionMap optionMap) throws java.security.GeneralSecurityException
Get an SSL provider for this XNIO provider.- Parameters:
optionMap
- the option map to use for configuring SSLkeyManagers
- the key managers to use, ornull
to configure from the option maptrustManagers
- the trust managers to use, ornull
to configure from the option map- Returns:
- the SSL provider
- Throws:
java.security.GeneralSecurityException
- if an exception occurred configuring the SSL provider
-
openFile
public java.nio.channels.FileChannel openFile(java.io.File file, OptionMap options) throws java.io.IOException
Open a file on the filesystem.- Parameters:
file
- the file to openoptions
- the file-open options- Returns:
- the file channel
- Throws:
java.io.IOException
- if an I/O error occurs
-
openFile
public java.nio.channels.FileChannel openFile(java.lang.String fileName, OptionMap options) throws java.io.IOException
Open a file on the filesystem.- Parameters:
fileName
- the file name of the file to openoptions
- the file-open options- Returns:
- the file channel
- Throws:
java.io.IOException
- if an I/O error occurs
-
openFile
public java.nio.channels.FileChannel openFile(java.io.File file, FileAccess access) throws java.io.IOException
Open a file on the filesystem.- Parameters:
file
- the file to openaccess
- the file access level to use- Returns:
- the file channel
- Throws:
java.io.IOException
- if an I/O error occurs
-
openFile
public java.nio.channels.FileChannel openFile(java.lang.String fileName, FileAccess access) throws java.io.IOException
Open a file on the filesystem.- Parameters:
fileName
- the file name of the file to openaccess
- the file access level to use- Returns:
- the file channel
- Throws:
java.io.IOException
- if an I/O error occurs
-
unwrapFileChannel
protected java.nio.channels.FileChannel unwrapFileChannel(java.nio.channels.FileChannel src)
Unwrap an XNIO-wrapped file channel. For use by providers.- Parameters:
src
- the possibly wrapped file channel- Returns:
- the unwrapped file channel
-
createWorkerBuilder
public XnioWorker.Builder createWorkerBuilder()
Create a new worker builder.- Returns:
- the worker builder (not
null
)
-
build
protected abstract XnioWorker build(XnioWorker.Builder builder)
Construct an XNIO worker from a builder.- Parameters:
builder
- the builder (must not benull
)- Returns:
- the constructed worker
-
createWorker
public XnioWorker createWorker(OptionMap optionMap) throws java.io.IOException, java.lang.IllegalArgumentException
Construct a new XNIO worker.- Parameters:
optionMap
- the options to use to configure the worker- Returns:
- the new worker
- Throws:
java.io.IOException
- if the worker failed to be openedjava.lang.IllegalArgumentException
- if an option value is invalid for this worker
-
createWorker
public XnioWorker createWorker(java.lang.ThreadGroup threadGroup, OptionMap optionMap) throws java.io.IOException, java.lang.IllegalArgumentException
Construct a new XNIO worker.- Parameters:
threadGroup
- the thread group for worker threadsoptionMap
- the options to use to configure the worker- Returns:
- the new worker
- Throws:
java.io.IOException
- if the worker failed to be openedjava.lang.IllegalArgumentException
- if an option value is invalid for this worker
-
createWorker
public XnioWorker createWorker(java.lang.ThreadGroup threadGroup, OptionMap optionMap, java.lang.Runnable terminationTask) throws java.io.IOException, java.lang.IllegalArgumentException
Construct a new XNIO worker.- Parameters:
threadGroup
- the thread group for worker threadsoptionMap
- the options to use to configure the workerterminationTask
- the task to run after the worker has shut down- Returns:
- the new worker
- Throws:
java.io.IOException
- if the worker failed to be openedjava.lang.IllegalArgumentException
- if an option value is invalid for this worker
-
createFileSystemWatcher
public FileSystemWatcher createFileSystemWatcher(java.lang.String name, OptionMap options)
Creates a file system watcher, that can be used to monitor file system changes.- Parameters:
name
- The watcher nameoptions
- The options to use to create the watcher- Returns:
- The file system watcher
-
handleThreadExit
protected void handleThreadExit()
Implement tasks that will be executed on thread exits if a task worker thread is initialized throughXnioWorker$WorkerThreadFactory
.
-
getName
public final java.lang.String getName()
Get the name of this XNIO provider.- Returns:
- the name
-
toString
public final java.lang.String toString()
Get a string representation of this XNIO provider.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string representation
-
getProperty
protected static java.lang.String getProperty(java.lang.String name)
Get an XNIO property. The property name must start with"xnio."
.- Parameters:
name
- the property name- Returns:
- the property value, or
null
if it wasn't found - Since:
- 1.2
-
getProperty
protected static java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)
Get an XNIO property. The property name must start with"xnio."
.- Parameters:
name
- the property namedefaultValue
- the default value- Returns:
- the property value, or
defaultValue
if it wasn't found - Since:
- 1.2
-
register
protected static java.io.Closeable register(XnioProviderMXBean providerMXBean)
Register an MBean. If the MBean cannot be registered, this method will simply return.- Parameters:
providerMXBean
- the provider MBean to register- Returns:
- a handle which may be used to remove the registration
-
register
protected static java.io.Closeable register(XnioWorkerMXBean workerMXBean)
Register an MBean. If the MBean cannot be registered, this method will simply return.- Parameters:
workerMXBean
- the worker MBean to register- Returns:
- a handle which may be used to remove the registration
-
register
protected static java.io.Closeable register(XnioServerMXBean serverMXBean)
Register an MBean. If the MBean cannot be registered, this method will simply return.- Parameters:
serverMXBean
- the server MBean to register- Returns:
- a handle which may be used to remove the registration
-
-