4700N/A/*
4700N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4700N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4700N/A *
4700N/A * This code is free software; you can redistribute it and/or modify it
4700N/A * under the terms of the GNU General Public License version 2 only, as
4700N/A * published by the Free Software Foundation. Oracle designates this
4700N/A * particular file as subject to the "Classpath" exception as provided
4700N/A * by Oracle in the LICENSE file that accompanied this code.
4700N/A *
4700N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4700N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4700N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4700N/A * version 2 for more details (a copy is included in the LICENSE file that
4700N/A * accompanied this code).
4700N/A *
4700N/A * You should have received a copy of the GNU General Public License version
4700N/A * 2 along with this work; if not, write to the Free Software Foundation,
4700N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4700N/A *
4700N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4700N/A * or visit www.oracle.com if you need additional information or have any
4700N/A * questions.
4700N/A */
4700N/A
4700N/Apackage sun.nio.ch;
4700N/A
4700N/Aimport java.nio.channels.*;
4700N/Aimport java.nio.channels.spi.AsynchronousChannelProvider;
4700N/Aimport java.util.concurrent.ExecutorService;
4700N/Aimport java.util.concurrent.ThreadFactory;
4700N/Aimport java.io.IOException;
4700N/A
4700N/Apublic class BsdAsynchronousChannelProvider
4700N/A extends AsynchronousChannelProvider
4700N/A{
4700N/A private static volatile KQueuePort defaultPort;
4700N/A
4700N/A private KQueuePort defaultEventPort() throws IOException {
4700N/A if (defaultPort == null) {
4700N/A synchronized (BsdAsynchronousChannelProvider.class) {
4700N/A if (defaultPort == null) {
4700N/A defaultPort = new KQueuePort(this, ThreadPool.getDefault()).start();
4700N/A }
4700N/A }
4700N/A }
4700N/A return defaultPort;
4700N/A }
4700N/A
4700N/A public BsdAsynchronousChannelProvider() {
4700N/A }
4700N/A
4700N/A @Override
4700N/A public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factory)
4700N/A throws IOException
4700N/A {
4700N/A return new KQueuePort(this, ThreadPool.create(nThreads, factory)).start();
4700N/A }
4700N/A
4700N/A @Override
4700N/A public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize)
4700N/A throws IOException
4700N/A {
4700N/A return new KQueuePort(this, ThreadPool.wrap(executor, initialSize)).start();
4700N/A }
4700N/A
4700N/A private Port toPort(AsynchronousChannelGroup group) throws IOException {
4700N/A if (group == null) {
4700N/A return defaultEventPort();
4700N/A } else {
4700N/A if (!(group instanceof KQueuePort))
4700N/A throw new IllegalChannelGroupException();
4700N/A return (Port)group;
4700N/A }
4700N/A }
4700N/A
4700N/A @Override
4700N/A public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(AsynchronousChannelGroup group)
4700N/A throws IOException
4700N/A {
4700N/A return new UnixAsynchronousServerSocketChannelImpl(toPort(group));
4700N/A }
4700N/A
4700N/A @Override
4700N/A public AsynchronousSocketChannel openAsynchronousSocketChannel(AsynchronousChannelGroup group)
4700N/A throws IOException
4700N/A {
4700N/A return new UnixAsynchronousSocketChannelImpl(toPort(group));
4700N/A }
4700N/A}