O'Reilly logo

Java NIO by Ron Hitchens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix B. Selectable Channels SPI

If you build it, he will come.

An Iowa Cornfield

The selectable-channel architecture, like several other components of the Java platform, is pluggable by means of a Service Provider Interface (SPI). Chapter 6 showed how to use the pluggable Charset SPI, and the Channel SPI works essentially the same way. Channel, Selector, and even SelectionKey implementations can be quite complex and are necessarily operating system-dependent. A sample channel implementation is beyond the scope of this book. This appendix only summarizes the SPI at a high level. If you are setting out to create your own custom channel implementation, you will require more detailed information than can be presented here.

As we saw in Section 6.3, services are facilitated by a provider class instantiated by the low-level services mechanism. For channels, the base provider class is java.nio.channels.spi.SelectorProvider. Note that this isn’t named ChannelProvider. This SPI applies only to selectable channels, not all channel types. There’s a tight dependency between selectable channels and related selectors (and selection keys, which associate one with the other). Channels and selectors from different providers will not work together.

package java.nio.channels.spi; public abstract class SelectorProvider { public static SelectorProvider provider( ) // The following methods all throw IOException public abstract AbstractSelector openSelector( ) public abstract ServerSocketChannel ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required