src/java.base/share/classes/java/nio/channels/SelectableChannel.java
author alanb
Wed, 18 Apr 2018 10:20:09 +0100
changeset 49802 8ac08fa69f00
parent 48761 74c1fa26435a
permissions -rw-r--r--
8201315: (se) Allow SelectableChannel.register to be invoked while selection operation is in progress Reviewed-by: bpb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49802
8ac08fa69f00 8201315: (se) Allow SelectableChannel.register to be invoked while selection operation is in progress
alanb
parents: 48761
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.nio.channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.channels.spi.AbstractInterruptibleChannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.channels.spi.SelectorProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A channel that can be multiplexed via a {@link Selector}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p> In order to be used with a selector, an instance of this class must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * first be <i>registered</i> via the {@link #register(Selector,int,Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * register} method.  This method returns a new {@link SelectionKey} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * that represents the channel's registration with the selector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p> Once registered with a selector, a channel remains registered until it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * is <i>deregistered</i>.  This involves deallocating whatever resources were
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * allocated to the channel by the selector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p> A channel cannot be deregistered directly; instead, the key representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * its registration must be <i>cancelled</i>.  Cancelling a key requests that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the channel be deregistered during the selector's next selection operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * A key may be cancelled explicitly by invoking its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * SelectionKey#cancel() cancel} method.  All of a channel's keys are cancelled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * implicitly when the channel is closed, whether by invoking its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Channel#close close} method or by interrupting a thread blocked in an I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * operation upon the channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p> If the selector itself is closed then the channel will be deregistered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * and the key representing its registration will be invalidated, without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * further delay.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p> A channel may be registered at most once with any particular selector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p> Whether or not a channel is registered with one or more selectors may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * determined by invoking the {@link #isRegistered isRegistered} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p> Selectable channels are safe for use by multiple concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * threads. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 32143
diff changeset
    67
 * <a id="bm"></a>
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    68
 * <h2>Blocking mode</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * A selectable channel is either in <i>blocking</i> mode or in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <i>non-blocking</i> mode.  In blocking mode, every I/O operation invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * upon the channel will block until it completes.  In non-blocking mode an I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * operation will never block and may transfer fewer bytes than were requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * or possibly no bytes at all.  The blocking mode of a selectable channel may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * be determined by invoking its {@link #isBlocking isBlocking} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p> Newly-created selectable channels are always in blocking mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Non-blocking mode is most useful in conjunction with selector-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * multiplexing.  A channel must be placed into non-blocking mode before being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * registered with a selector, and may not be returned to blocking mode until
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * it has been deregistered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @see SelectionKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @see Selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
public abstract class SelectableChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    extends AbstractInterruptibleChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    implements Channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Initializes a new instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected SelectableChannel() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Returns the provider that created this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return  The provider that created this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public abstract SelectorProvider provider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Returns an <a href="SelectionKey.html#opsets">operation set</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * identifying this channel's supported operations.  The bits that are set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * in this integer value denote exactly the operations that are valid for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * this channel.  This method always returns the same value for a given
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
   114
     * concrete channel class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @return  The valid-operation set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public abstract int validOps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Tells whether or not this channel is currently registered with any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * selectors.  A newly-created channel is not registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p> Due to the inherent delay between key cancellation and channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * deregistration, a channel may remain registered for some time after all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * of its keys have been cancelled.  A channel may also remain registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * for some time after it is closed.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   129
     * @return {@code true} if, and only if, this channel is registered
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public abstract boolean isRegistered();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Retrieves the key representing the channel's registration with the given
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
   135
     * selector.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   137
     * @param   sel
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   138
     *          The selector
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   139
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return  The key returned when this channel was last registered with the
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   141
     *          given selector, or {@code null} if this channel is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *          currently registered with that selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public abstract SelectionKey keyFor(Selector sel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Registers this channel with the given selector, returning a selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <p> If this channel is currently registered with the given selector then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * the selection key representing that registration is returned.  The key's
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   152
     * interest set will have been changed to {@code ops}, as if by invoking
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * the {@link SelectionKey#interestOps(int) interestOps(int)} method.  If
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   154
     * the {@code att} argument is not {@code null} then the key's attachment
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * will have been set to that value.  A {@link CancelledKeyException} will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * be thrown if the key has already been cancelled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <p> Otherwise this channel has not yet been registered with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * selector, so it is registered and the resulting new key is returned.
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   160
     * The key's initial interest set will be {@code ops} and its attachment
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   161
     * will be {@code att}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <p> This method may be invoked at any time.  If this method is invoked
49802
8ac08fa69f00 8201315: (se) Allow SelectableChannel.register to be invoked while selection operation is in progress
alanb
parents: 48761
diff changeset
   164
     * while a selection operation is in progress then it has no effect upon
8ac08fa69f00 8201315: (se) Allow SelectableChannel.register to be invoked while selection operation is in progress
alanb
parents: 48761
diff changeset
   165
     * that operation; the new registration or change to the key's interest set
8ac08fa69f00 8201315: (se) Allow SelectableChannel.register to be invoked while selection operation is in progress
alanb
parents: 48761
diff changeset
   166
     * will be seen by the next selection operation.  If this method is invoked
8ac08fa69f00 8201315: (se) Allow SelectableChannel.register to be invoked while selection operation is in progress
alanb
parents: 48761
diff changeset
   167
     * while an invocation of {@link #configureBlocking(boolean) configureBlocking}
8ac08fa69f00 8201315: (se) Allow SelectableChannel.register to be invoked while selection operation is in progress
alanb
parents: 48761
diff changeset
   168
     * is in progress then it will block until the channel's blocking mode has
8ac08fa69f00 8201315: (se) Allow SelectableChannel.register to be invoked while selection operation is in progress
alanb
parents: 48761
diff changeset
   169
     * been adjusted.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <p> If this channel is closed while this operation is in progress then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * the key returned by this method will have been cancelled and will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * therefore be invalid. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param  sel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *         The selector with which this channel is to be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param  ops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *         The interest set for the resulting key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param  att
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   182
     *         The attachment for the resulting key; may be {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
1449
2ed6188288d6 5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents: 2
diff changeset
   187
     * @throws  ClosedSelectorException
2ed6188288d6 5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents: 2
diff changeset
   188
     *          If the selector is closed
2ed6188288d6 5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents: 2
diff changeset
   189
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @throws  IllegalBlockingModeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *          If this channel is in blocking mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @throws  IllegalSelectorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *          If this channel was not created by the same provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *          as the given selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @throws  CancelledKeyException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *          If this channel is currently registered with the given selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *          but the corresponding key has already been cancelled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @throws  IllegalArgumentException
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   202
     *          If a bit in the {@code ops} set does not correspond to an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *          operation that is supported by this channel, that is, if
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
   204
     *          {@code set & ~validOps() != 0}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @return  A key representing the registration of this channel with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *          the given selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public abstract SelectionKey register(Selector sel, int ops, Object att)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        throws ClosedChannelException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Registers this channel with the given selector, returning a selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <p> An invocation of this convenience method of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   218
     * <blockquote>{@code sc.register(sel, ops)}</blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   222
     * <blockquote>{@code sc.}{@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * #register(java.nio.channels.Selector,int,java.lang.Object)
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   224
     * register(sel, ops, null)}</blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param  sel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *         The selector with which this channel is to be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param  ops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *         The interest set for the resulting key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
1449
2ed6188288d6 5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents: 2
diff changeset
   235
     * @throws  ClosedSelectorException
2ed6188288d6 5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents: 2
diff changeset
   236
     *          If the selector is closed
2ed6188288d6 5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents: 2
diff changeset
   237
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @throws  IllegalBlockingModeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *          If this channel is in blocking mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @throws  IllegalSelectorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *          If this channel was not created by the same provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *          as the given selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @throws  CancelledKeyException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *          If this channel is currently registered with the given selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *          but the corresponding key has already been cancelled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @throws  IllegalArgumentException
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   250
     *          If a bit in {@code ops} does not correspond to an operation
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
   251
     *          that is supported by this channel, that is, if {@code set &
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
   252
     *          ~validOps() != 0}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return  A key representing the registration of this channel with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *          the given selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public final SelectionKey register(Selector sel, int ops)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        throws ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return register(sel, ops, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Adjusts this channel's blocking mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <p> If this channel is registered with one or more selectors then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * attempt to place it into blocking mode will cause an {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * IllegalBlockingModeException} to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <p> This method may be invoked at any time.  The new blocking mode will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * only affect I/O operations that are initiated after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * For some implementations this may require blocking until all pending I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * operations are complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <p> If this method is invoked while another invocation of this method or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * of the {@link #register(Selector, int) register} method is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * then it will first block until the other operation is complete. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   279
     * @param  block  If {@code true} then this channel will be placed in
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   280
     *                blocking mode; if {@code false} then it will be placed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *                non-blocking mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @return  This selectable channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @throws  IllegalBlockingModeException
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   289
     *          If {@code block} is {@code true} and this channel is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *          registered with one or more selectors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *         If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public abstract SelectableChannel configureBlocking(boolean block)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Tells whether or not every I/O operation on this channel will block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * until it completes.  A newly-created channel is always in blocking mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <p> If this channel is closed then the value returned by this method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * not specified. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   305
     * @return {@code true} if, and only if, this channel is in blocking mode
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public abstract boolean isBlocking();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Retrieves the object upon which the {@link #configureBlocking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * configureBlocking} and {@link #register register} methods synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * This is often useful in the implementation of adaptors that require a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * specific blocking mode to be maintained for a short period of time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @return  The blocking-mode lock object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public abstract Object blockingLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
}