Path: blob/master/src/java.base/aix/classes/sun/nio/ch/AixAsynchronousChannelProvider.java
41139 views
/*1* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation. Oracle designates this8* particular file as subject to the "Classpath" exception as provided9* by Oracle in the LICENSE file that accompanied this code.10*11* This code is distributed in the hope that it will be useful, but WITHOUT12* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or13* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License14* version 2 for more details (a copy is included in the LICENSE file that15* accompanied this code).16*17* You should have received a copy of the GNU General Public License version18* 2 along with this work; if not, write to the Free Software Foundation,19* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.20*21* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA22* or visit www.oracle.com if you need additional information or have any23* questions.24*/2526package sun.nio.ch;2728import java.nio.channels.*;29import java.nio.channels.spi.AsynchronousChannelProvider;30import java.util.concurrent.ExecutorService;31import java.util.concurrent.ThreadFactory;32import java.io.IOException;3334public class AixAsynchronousChannelProvider35extends AsynchronousChannelProvider36{37private static volatile AixPollPort defaultPort;3839private AixPollPort defaultEventPort() throws IOException {40if (defaultPort == null) {41synchronized (AixAsynchronousChannelProvider.class) {42if (defaultPort == null) {43defaultPort = new AixPollPort(this, ThreadPool.getDefault()).start();44}45}46}47return defaultPort;48}4950public AixAsynchronousChannelProvider() {51}5253@Override54public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factory)55throws IOException56{57return new AixPollPort(this, ThreadPool.create(nThreads, factory)).start();58}5960@Override61public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize)62throws IOException63{64return new AixPollPort(this, ThreadPool.wrap(executor, initialSize)).start();65}6667private Port toPort(AsynchronousChannelGroup group) throws IOException {68if (group == null) {69return defaultEventPort();70} else {71if (!(group instanceof AixPollPort))72throw new IllegalChannelGroupException();73return (Port)group;74}75}7677@Override78public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(AsynchronousChannelGroup group)79throws IOException80{81return new UnixAsynchronousServerSocketChannelImpl(toPort(group));82}8384@Override85public AsynchronousSocketChannel openAsynchronousSocketChannel(AsynchronousChannelGroup group)86throws IOException87{88return new UnixAsynchronousSocketChannelImpl(toPort(group));89}90}919293