FileDocCategorySizeDatePackage
AbstractSelector.javaAPI DocAndroid 1.5 API5936Wed May 06 22:41:04 BST 2009java.nio.channels.spi

AbstractSelector

public abstract class AbstractSelector extends Selector
{@code AbstractSelector} is the base implementation class for selectors. It realizes the interruption of selection by {@code begin} and {@code end}. It also holds the cancellation and the deletion of the key set.
since
Android 1.0

Fields Summary
private volatile boolean
isOpen
private SelectorProvider
provider
private Set
cancelledKeysSet
Constructors Summary
protected AbstractSelector(SelectorProvider selectorProvider)
Constructs a new {@code AbstractSelector}.

param
selectorProvider the selector provider that creates this selector.
since
Android 1.0


                                      
       
        provider = selectorProvider;
    
Methods Summary
protected final voidbegin()
Indicates the beginning of a code section that includes an I/O operation that is potentially blocking. After this operation, the application should invoke the corresponding {@code end(boolean)} method.

since
Android 1.0

        // FIXME: be accommodate before VM actually provides
        // setInterruptAction method
        if (AbstractInterruptibleChannel.setInterruptAction != null) {
            try {
                AbstractInterruptibleChannel.setInterruptAction.invoke(Thread
                        .currentThread(), new Object[] { new Runnable() {
                    public void run() {
                        AbstractSelector.this.wakeup();
                    }
                } });
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    
voidcancel(java.nio.channels.SelectionKey key)

        synchronized (cancelledKeysSet) {
            cancelledKeysSet.add(key);
        }
    
protected final java.util.SetcancelledKeys()
Returns this channel's set of canceled selection keys.

return
the set of canceled selection keys.
since
Android 1.0

        return cancelledKeysSet;
    
public final synchronized voidclose()
Closes this selector. This method does nothing if this selector is already closed. The actual closing must be implemented by subclasses in {@code implCloseSelector()}.

throws
IOException if an I/O error occurs.
since
Android 1.0

        if (isOpen) {
            isOpen = false;
            implCloseSelector();
        }
    
protected final voidderegister(java.nio.channels.spi.AbstractSelectionKey key)
Deletes the key from the channel's key set.

param
key the key.
since
Android 1.0

        ((AbstractSelectableChannel) key.channel()).deregister(key);
        key.isValid = false;
    
protected final voidend()
Indicates the end of a code section that has been started with {@code begin()} and that includes a potentially blocking I/O operation.

since
Android 1.0

        // FIXME: be accommodate before VM actually provides
        // setInterruptAction method
        if (AbstractInterruptibleChannel.setInterruptAction != null) {
            try {
                AbstractInterruptibleChannel.setInterruptAction.invoke(Thread
                        .currentThread(), new Object[] { null });
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    
protected abstract voidimplCloseSelector()
Implements the closing of this channel.

throws
IOException if an I/O error occurs.
since
Android 1.0

public final booleanisOpen()
Indicates whether this selector is open.

return
{@code true} if this selector is not closed, {@code false} otherwise.
since
Android 1.0

        return isOpen;
    
public final java.nio.channels.spi.SelectorProviderprovider()
Gets this selector's provider.

return
the provider of this selector.
since
Android 1.0

        return provider;
    
protected abstract java.nio.channels.SelectionKeyregister(java.nio.channels.spi.AbstractSelectableChannel channel, int operations, java.lang.Object attachment)
Registers a channel with this selector.

param
channel the channel to be registered.
param
operations the {@link SelectionKey interest set} of {@code channel}.
param
attachment the attachment for the selection key.
return
the key related to the channel and this selector.
since
Android 1.0