jdk/src/share/classes/java/nio/channels/spi/SelectorProvider.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 51 6fe31bc95bbc
child 1152 29d6145d1097
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 51
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.FileDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.ServerSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.Socket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.channels.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ServiceLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.ServiceConfigurationError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Service-provider class for selectors and selectable channels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p> A selector provider is a concrete subclass of this class that has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * zero-argument constructor and implements the abstract methods specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * below.  A given invocation of the Java virtual machine maintains a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * system-wide default provider instance, which is returned by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * #provider() provider} method.  The first invocation of that method will locate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the default provider as specified below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p> The system-wide default provider is used by the static <tt>open</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * methods of the {@link java.nio.channels.DatagramChannel#open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * DatagramChannel}, {@link java.nio.channels.Pipe#open Pipe}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * java.nio.channels.Selector#open Selector}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * java.nio.channels.ServerSocketChannel#open ServerSocketChannel}, and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * java.nio.channels.SocketChannel#open SocketChannel} classes.  It is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * used by the {@link java.lang.System#inheritedChannel System.inheritedChannel()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * method. A program may make use of a provider other than the default provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * by instantiating that provider and then directly invoking the <tt>open</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * methods defined in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p> All of the methods in this class are safe for use by multiple concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * threads.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public abstract class SelectorProvider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static SelectorProvider provider = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Initializes a new instance of this class.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *          If a security manager has been installed and it denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *          {@link RuntimePermission}<tt>("selectorProvider")</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected SelectorProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (sm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            sm.checkPermission(new RuntimePermission("selectorProvider"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static boolean loadProviderFromProperty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        String cn = System.getProperty("java.nio.channels.spi.SelectorProvider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (cn == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            Class c = Class.forName(cn, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                    ClassLoader.getSystemClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            provider = (SelectorProvider)c.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        } catch (ClassNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            throw new ServiceConfigurationError(null, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } catch (IllegalAccessException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            throw new ServiceConfigurationError(null, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        } catch (InstantiationException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            throw new ServiceConfigurationError(null, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } catch (SecurityException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            throw new ServiceConfigurationError(null, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static boolean loadProviderAsService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        ServiceLoader<SelectorProvider> sl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            ServiceLoader.load(SelectorProvider.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                               ClassLoader.getSystemClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Iterator<SelectorProvider> i = sl.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                if (!i.hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                provider = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            } catch (ServiceConfigurationError sce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                if (sce.getCause() instanceof SecurityException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    // Ignore the security exception, try the next provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                throw sce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Returns the system-wide default selector provider for this invocation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <p> The first invocation of this method locates the default provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * object as follows: </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *   <li><p> If the system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *   <tt>java.nio.channels.spi.SelectorProvider</tt> is defined then it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *   taken to be the fully-qualified name of a concrete provider class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *   The class is loaded and instantiated; if this process fails then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *   unspecified error is thrown.  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *   <li><p> If a provider class has been installed in a jar file that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *   visible to the system class loader, and that jar file contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *   provider-configuration file named
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *   <tt>java.nio.channels.spi.SelectorProvider</tt> in the resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *   directory <tt>META-INF/services</tt>, then the first class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *   specified in that file is taken.  The class is loaded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *   instantiated; if this process fails then an unspecified error is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *   thrown.  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *   <li><p> Finally, if no provider has been specified by any of the above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *   means then the system-default provider class is instantiated and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *   result is returned.  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p> Subsequent invocations of this method return the provider that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * returned by the first invocation.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return  The system-wide default selector provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public static SelectorProvider provider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (provider != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                return provider;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   170
            return AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   171
                new PrivilegedAction<SelectorProvider>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   172
                    public SelectorProvider run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                            if (loadProviderFromProperty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                            if (loadProviderAsService())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                            provider = sun.nio.ch.DefaultSelectorProvider.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                            return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Opens a datagram channel.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @return  The new channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public abstract DatagramChannel openDatagramChannel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Opens a pipe.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @return  The new pipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public abstract Pipe openPipe()
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Opens a selector.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return  The new selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public abstract AbstractSelector openSelector()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Opens a server-socket channel.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return  The new channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public abstract ServerSocketChannel openServerSocketChannel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Opens a socket channel. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @return  The new channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public abstract SocketChannel openSocketChannel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Returns the channel inherited from the entity that created this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p> On many operating systems a process, such as a Java virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * machine, can be started in a manner that allows the process to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * inherit a channel from the entity that created the process. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * manner in which this is done is system dependent, as are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * possible entities to which the channel may be connected. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * on UNIX systems, the Internet services daemon (<i>inetd</i>) is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * start programs to service requests when a request arrives on an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * associated network port. In this example, the process that is started,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * inherits a channel representing a network socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * <p> In cases where the inherited channel represents a network socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * then the {@link java.nio.channels.Channel Channel} type returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * by this method is determined as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *  <li><p> If the inherited channel represents a stream-oriented connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *  socket then a {@link java.nio.channels.SocketChannel SocketChannel} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *  returned. The socket channel is, at least initially, in blocking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *  mode, bound to a socket address, and connected to a peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *  <li><p> If the inherited channel represents a stream-oriented listening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *  socket then a {@link java.nio.channels.ServerSocketChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *  ServerSocketChannel} is returned. The server-socket channel is, at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *  least initially, in blocking mode, and bound to a socket address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *  <li><p> If the inherited channel is a datagram-oriented socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *  then a {@link java.nio.channels.DatagramChannel DatagramChannel} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *  returned. The datagram channel is, at least initially, in blocking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *  mode, and bound to a socket address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <p> In addition to the network-oriented channels described, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * may return other kinds of channels in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p> The first invocation of this method creates the channel that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * returned. Subsequent invocations of this method return the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * channel. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return  The inherited channel, if any, otherwise <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *          If a security manager has been installed and it denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *          {@link RuntimePermission}<tt>("inheritedChannel")</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
   public Channel inheritedChannel() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
}