Top Description Inners Constructors Methods
java.nio.channels.spi

public abstract Class SelectorProvider

extends Object
Class Inheritance
Known Direct Subclasses
sun.nio.ch.SelectorProviderImpl
Imports
java.io.IOException, java.lang.reflect.InvocationTargetException, java.net.ProtocolFamily, java.nio.channels.Channel, .DatagramChannel, .Pipe, .ServerSocketChannel, .SocketChannel, java.security.AccessController, .PrivilegedAction, java.util.Iterator, .Objects, .ServiceLoader, .ServiceConfigurationError

Service-provider class for selectors and selectable channels.

A selector provider is a concrete subclass of this class that has a zero-argument constructor and implements the abstract methods specified below. A given invocation of the Java virtual machine maintains a single system-wide default provider instance, which is returned by the provider method. The first invocation of that method will locate the default provider as specified below.

The system-wide default provider is used by the static open methods of the DatagramChannel, Pipe, Selector, ServerSocketChannel, and SocketChannel classes. It is also used by the System.inheritedChannel() method. A program may make use of a provider other than the default provider by instantiating that provider and then directly invoking the open methods defined in this class.

All of the methods in this class are safe for use by multiple concurrent threads.

Authors
Mark Reinhold, JSR-51 Expert Group
Since
1.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Constructor Summary

AccessConstructor and Description
private
protected
SelectorProvider()

Initializes a new instance of this class.

Method Summary

Modifier and TypeMethod and Description
private static Void
public Channel

Returns:

The inherited channel, if any, otherwise null.
inheritedChannel
()

Returns the channel inherited from the entity that created this Java virtual machine.

public abstract DatagramChannel

Returns:

The new channel
openDatagramChannel
()

Opens a datagram channel.

public abstract DatagramChannel

Returns:

A new datagram channel
openDatagramChannel
(ProtocolFamily
The protocol family
family
)

Opens a datagram channel.

public abstract Pipe

Returns:

The new pipe
openPipe
()

Opens a pipe.

public abstract AbstractSelector

Returns:

The new selector
openSelector
()

Opens a selector.

public abstract ServerSocketChannel

Returns:

The new channel
openServerSocketChannel
()

Opens a server-socket channel.

public ServerSocketChannel

Returns:

The new channel
openServerSocketChannel
(ProtocolFamily
The protocol family
family
)

Opens a server-socket channel.

public abstract SocketChannel

Returns:

The new channel
openSocketChannel
()

Opens a socket channel.

public SocketChannel

Returns:

The new channel
openSocketChannel
(ProtocolFamily
The protocol family
family
)

Opens a socket channel.

public static SelectorProvider

Returns:

The system-wide default selector provider
provider
()

Returns the system-wide default selector provider for this invocation of the Java virtual machine.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SelectorProviderback to summary
private SelectorProvider(Void ignore)
SelectorProviderback to summary
protected SelectorProvider()

Initializes a new instance of this class.

Exceptions
SecurityException:
If a security manager has been installed and it denies RuntimePermission("selectorProvider")

Method Detail

checkPermissionback to summary
private static Void checkPermission()
inheritedChannelback to summary
public Channel inheritedChannel() throws IOException

Returns the channel inherited from the entity that created this Java virtual machine.

On many operating systems a process, such as a Java virtual machine, can be started in a manner that allows the process to inherit a channel from the entity that created the process. The manner in which this is done is system dependent, as are the possible entities to which the channel may be connected. For example, on UNIX systems, the Internet services daemon (inetd) is used to start programs to service requests when a request arrives on an associated network port. In this example, the process that is started, inherits a channel representing a network socket.

In cases where the inherited channel is for an Internet protocol socket then the Channel type returned by this method is determined as follows:

  • If the inherited channel is for a stream-oriented connected socket then a SocketChannel is returned. The socket channel is, at least initially, in blocking mode, bound to a socket address, and connected to a peer.

  • If the inherited channel is for a stream-oriented listening socket then a ServerSocketChannel is returned. The server-socket channel is, at least initially, in blocking mode, and bound to a socket address.

  • If the inherited channel is a datagram-oriented socket then a DatagramChannel is returned. The datagram channel is, at least initially, in blocking mode, and bound to a socket address.

In cases where the inherited channel is for a Unix domain socket then the Channel type returned is the same as for Internet protocol sockets as described above, except that datagram-oriented sockets are not supported.

In addition to the two types of socket just described, this method may return other types in the future.

The first invocation of this method creates the channel that is returned. Subsequent invocations of this method return the same channel.

Implementation Specification

The default implementation of this method returns null.

Returns:Channel

The inherited channel, if any, otherwise null.

Exceptions
IOException:
If an I/O error occurs
SecurityException:
If a security manager has been installed and it denies RuntimePermission("inheritedChannel")
Since
1.5
openDatagramChannelback to summary
public abstract DatagramChannel openDatagramChannel() throws IOException

Opens a datagram channel.

Returns:DatagramChannel

The new channel

Exceptions
IOException:
If an I/O error occurs
openDatagramChannelback to summary
public abstract DatagramChannel openDatagramChannel(ProtocolFamily family) throws IOException

Opens a datagram channel.

Parameters
family:ProtocolFamily

The protocol family

Returns:DatagramChannel

A new datagram channel

Exceptions
IOException:
If an I/O error occurs
UnsupportedOperationException:
If the specified protocol family is not supported
Since
1.7
openPipeback to summary
public abstract Pipe openPipe() throws IOException

Opens a pipe.

Returns:Pipe

The new pipe

Exceptions
IOException:
If an I/O error occurs
openSelectorback to summary
public abstract AbstractSelector openSelector() throws IOException

Opens a selector.

Returns:AbstractSelector

The new selector

Exceptions
IOException:
If an I/O error occurs
openServerSocketChannelback to summary
public abstract ServerSocketChannel openServerSocketChannel() throws IOException

Opens a server-socket channel.

Returns:ServerSocketChannel

The new channel

Exceptions
IOException:
If an I/O error occurs
openServerSocketChannelback to summary
public ServerSocketChannel openServerSocketChannel(ProtocolFamily family) throws IOException

Opens a server-socket channel.

Implementation Specification

The default implementation of this method first checks that the given protocol family is not null, then throws UnsupportedOperationException.

Parameters
family:ProtocolFamily

The protocol family

Returns:ServerSocketChannel

The new channel

Exceptions
IOException:
If an I/O error occurs
UnsupportedOperationException:
If the specified protocol family is not supported
Since
15
openSocketChannelback to summary
public abstract SocketChannel openSocketChannel() throws IOException

Opens a socket channel.

Returns:SocketChannel

The new channel

Exceptions
IOException:
If an I/O error occurs
openSocketChannelback to summary
public SocketChannel openSocketChannel(ProtocolFamily family) throws IOException

Opens a socket channel.

Implementation Specification

The default implementation of this method first checks that the given protocol family is not null, then throws UnsupportedOperationException.

Parameters
family:ProtocolFamily

The protocol family

Returns:SocketChannel

The new channel

Exceptions
IOException:
If an I/O error occurs
UnsupportedOperationException:
If the specified protocol family is not supported
Since
15
providerback to summary
public static SelectorProvider provider()

Returns the system-wide default selector provider for this invocation of the Java virtual machine.

The first invocation of this method locates the default provider object as follows:

  1. If the system property java.nio.channels.spi.SelectorProvider is defined then it is taken to be the fully-qualified name of a concrete provider class. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.

  2. If a provider class has been installed in a jar file that is visible to the system class loader, and that jar file contains a provider-configuration file named java.nio.channels.spi.SelectorProvider in the resource directory META-INF/services, then the first class name specified in that file is taken. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.

  3. Finally, if no provider has been specified by any of the above means then the system-default provider class is instantiated and the result is returned.

Subsequent invocations of this method return the provider that was returned by the first invocation.

Returns:SelectorProvider

The system-wide default selector provider

java.nio.channels.spi back to summary

private Class SelectorProvider.Holder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final SelectorProvider

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static SelectorProvider
private static SelectorProvider
pack-priv static SelectorProvider
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
pack-priv static final SelectorProvider INSTANCE

Constructor Detail

Holderback to summary
private Holder()

Method Detail

loadProviderAsServiceback to summary
private static SelectorProvider loadProviderAsService()
loadProviderFromPropertyback to summary
private static SelectorProvider loadProviderFromProperty()
providerback to summary
pack-priv static SelectorProvider provider()
Annotations
@SuppressWarnings:removal