src/java.base/share/classes/java/nio/channels/spi/SelectorProvider.java
author michaelm
Fri, 25 Oct 2019 15:56:35 +0100
branchunixdomainchannels
changeset 58801 119ac9128c1b
parent 55026 a8673ccddffd
permissions -rw-r--r--
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55026
a8673ccddffd 8214563: Use {@systemProperty} in specification of system properties in java.nio packages
dkejriwal
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2019, 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: 2057
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: 2057
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: 2057
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
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.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
    29
import java.net.ProtocolFamily;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.channels.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.ServiceLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ServiceConfigurationError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Service-provider class for selectors and selectable channels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p> A selector provider is a concrete subclass of this class that has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * zero-argument constructor and implements the abstract methods specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * below.  A given invocation of the Java virtual machine maintains a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * system-wide default provider instance, which is returned by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * #provider() provider} method.  The first invocation of that method will locate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the default provider as specified below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 29986
diff changeset
    49
 * <p> The system-wide default provider is used by the static {@code open}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * methods of the {@link java.nio.channels.DatagramChannel#open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * DatagramChannel}, {@link java.nio.channels.Pipe#open Pipe}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * java.nio.channels.Selector#open Selector}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * java.nio.channels.ServerSocketChannel#open ServerSocketChannel}, and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * java.nio.channels.SocketChannel#open SocketChannel} classes.  It is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * used by the {@link java.lang.System#inheritedChannel System.inheritedChannel()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * method. A program may make use of a provider other than the default provider
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 29986
diff changeset
    57
 * by instantiating that provider and then directly invoking the {@code open}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * methods defined in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p> All of the methods in this class are safe for use by multiple concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * threads.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public abstract class SelectorProvider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static SelectorProvider provider = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
22053
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    74
    private static Void checkPermission() {
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    75
        SecurityManager sm = System.getSecurityManager();
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    76
        if (sm != null)
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    77
            sm.checkPermission(new RuntimePermission("selectorProvider"));
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    78
        return null;
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    79
    }
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    80
    private SelectorProvider(Void ignore) { }
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    81
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
    83
     * Initializes a new instance of this class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *          If a security manager has been installed and it denies
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 29986
diff changeset
    87
     *          {@link RuntimePermission}{@code ("selectorProvider")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected SelectorProvider() {
22053
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    90
        this(checkPermission());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static boolean loadProviderFromProperty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        String cn = System.getProperty("java.nio.channels.spi.SelectorProvider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (cn == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        try {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32143
diff changeset
    98
            @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32143
diff changeset
    99
            Object tmp = Class.forName(cn, true,
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32143
diff changeset
   100
                                       ClassLoader.getSystemClassLoader()).newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32143
diff changeset
   101
            provider = (SelectorProvider)tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        } catch (ClassNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new ServiceConfigurationError(null, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } catch (IllegalAccessException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            throw new ServiceConfigurationError(null, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } catch (InstantiationException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            throw new ServiceConfigurationError(null, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } catch (SecurityException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            throw new ServiceConfigurationError(null, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static boolean loadProviderAsService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        ServiceLoader<SelectorProvider> sl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            ServiceLoader.load(SelectorProvider.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                               ClassLoader.getSystemClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        Iterator<SelectorProvider> i = sl.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                if (!i.hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                provider = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            } catch (ServiceConfigurationError sce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                if (sce.getCause() instanceof SecurityException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    // Ignore the security exception, try the next provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                throw sce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Returns the system-wide default selector provider for this invocation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <p> The first invocation of this method locates the default provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * object as follows: </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *   <li><p> If the system property
55026
a8673ccddffd 8214563: Use {@systemProperty} in specification of system properties in java.nio packages
dkejriwal
parents: 47216
diff changeset
   146
     *   {@systemProperty java.nio.channels.spi.SelectorProvider} is defined
a8673ccddffd 8214563: Use {@systemProperty} in specification of system properties in java.nio packages
dkejriwal
parents: 47216
diff changeset
   147
     *   then it is taken to be the fully-qualified name of a concrete provider
a8673ccddffd 8214563: Use {@systemProperty} in specification of system properties in java.nio packages
dkejriwal
parents: 47216
diff changeset
   148
     *   class. The class is loaded and instantiated; if this process fails then
a8673ccddffd 8214563: Use {@systemProperty} in specification of system properties in java.nio packages
dkejriwal
parents: 47216
diff changeset
   149
     *   an unspecified error is thrown.  </p></li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *   <li><p> If a provider class has been installed in a jar file that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *   visible to the system class loader, and that jar file contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *   provider-configuration file named
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 29986
diff changeset
   154
     *   {@code java.nio.channels.spi.SelectorProvider} in the resource
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 29986
diff changeset
   155
     *   directory {@code META-INF/services}, then the first class name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *   specified in that file is taken.  The class is loaded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *   instantiated; if this process fails then an unspecified error is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *   thrown.  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *   <li><p> Finally, if no provider has been specified by any of the above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *   means then the system-default provider class is instantiated and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *   result is returned.  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p> Subsequent invocations of this method return the provider that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * returned by the first invocation.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @return  The system-wide default selector provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public static SelectorProvider provider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (provider != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                return provider;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   175
            return AccessController.doPrivileged(
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   176
                new PrivilegedAction<>() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   177
                    public SelectorProvider run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                            if (loadProviderFromProperty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                            if (loadProviderAsService())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                            provider = sun.nio.ch.DefaultSelectorProvider.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                            return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
   190
     * Opens a datagram channel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return  The new channel
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   193
     *
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   194
     * @throws  IOException
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   195
     *          If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public abstract DatagramChannel openDatagramChannel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   201
     * Opens a datagram channel.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   202
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   203
     * @param   family
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   204
     *          The protocol family
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   205
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   206
     * @return  A new datagram channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   207
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   208
     * @throws  UnsupportedOperationException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   209
     *          If the specified protocol family is not supported
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   210
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   211
     *          If an I/O error occurs
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   212
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   213
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   214
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   215
    public abstract DatagramChannel openDatagramChannel(ProtocolFamily family)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   216
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   217
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 715
diff changeset
   218
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
   219
     * Opens a pipe.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return  The new pipe
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   222
     *
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   223
     * @throws  IOException
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   224
     *          If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public abstract Pipe openPipe()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
   230
     * Opens a selector.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return  The new selector
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   233
     *
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   234
     * @throws  IOException
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   235
     *          If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public abstract AbstractSelector openSelector()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
   241
     * Opens a server-socket channel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @return  The new channel
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   244
     *
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   245
     * @throws  IOException
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   246
     *          If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public abstract ServerSocketChannel openServerSocketChannel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
   252
     * Opens a socket channel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return  The new channel
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   255
     *
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   256
     * @throws  IOException
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   257
     *          If an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public abstract SocketChannel openSocketChannel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Returns the channel inherited from the entity that created this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <p> On many operating systems a process, such as a Java virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * machine, can be started in a manner that allows the process to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * inherit a channel from the entity that created the process. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * manner in which this is done is system dependent, as are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * possible entities to which the channel may be connected. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * on UNIX systems, the Internet services daemon (<i>inetd</i>) is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * start programs to service requests when a request arrives on an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * associated network port. In this example, the process that is started,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * inherits a channel representing a network socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <p> In cases where the inherited channel represents a network socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * then the {@link java.nio.channels.Channel Channel} type returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * by this method is determined as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *  <li><p> If the inherited channel represents a stream-oriented connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *  socket then a {@link java.nio.channels.SocketChannel SocketChannel} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *  returned. The socket channel is, at least initially, in blocking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *  mode, bound to a socket address, and connected to a peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *  <li><p> If the inherited channel represents a stream-oriented listening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *  socket then a {@link java.nio.channels.ServerSocketChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *  ServerSocketChannel} is returned. The server-socket channel is, at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *  least initially, in blocking mode, and bound to a socket address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *  <li><p> If the inherited channel is a datagram-oriented socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *  then a {@link java.nio.channels.DatagramChannel DatagramChannel} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *  returned. The datagram channel is, at least initially, in blocking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *  mode, and bound to a socket address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <p> In addition to the network-oriented channels described, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * may return other kinds of channels in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <p> The first invocation of this method creates the channel that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * returned. Subsequent invocations of this method return the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * channel. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 29986
diff changeset
   309
     * @return  The inherited channel, if any, otherwise {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *          If a security manager has been installed and it denies
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 29986
diff changeset
   316
     *          {@link RuntimePermission}{@code ("inheritedChannel")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   320
    public Channel inheritedChannel() throws IOException {
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   321
        return null;
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   322
    }
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   323
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   324
    /**
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   325
     * Returns a {@link SocketChannel} from the given protocol family.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   326
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   327
     * @param family the protocol family
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   328
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   329
     * @return a SocketChannel
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   330
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   331
     * @throws IOException if an I/O error occurs
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   332
     * @throws UnsupportedAddressTypeException if the protocol family not supported
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   333
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   334
     * @since 14
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   335
     */
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   336
    public SocketChannel openSocketChannel(ProtocolFamily family) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return null;
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   338
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   340
    /**
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   341
     * Returns a {@link ServerSocketChannel} from the given protocol family.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   342
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   343
     * @param family the protocol family
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   344
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   345
     * @return a ServerSocketChannel
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   346
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   347
     * @throws IOException if an I/O error occurs
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   348
     * @throws UnsupportedAddressTypeException if the protocol family not supported
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   349
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   350
     * @since 14
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   351
     */
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   352
    public ServerSocketChannel openServerSocketChannel(ProtocolFamily family) throws IOException {
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   353
        return null;
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 55026
diff changeset
   354
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
}