jdk/src/aix/classes/sun/nio/ch/AixAsynchronousChannelProvider.java
author simonis
Tue, 26 Nov 2013 16:40:31 +0100
changeset 22597 7515a991bb37
permissions -rw-r--r--
8024854: PPC64: Basic changes and files to build the class library on AIX Reviewed-by: alanb, prr, sla, chegar, michaelm, mullan, art Contributed-by: luchsh@linux.vnet.ibm.com, spoole@linux.vnet.ibm.com, thomas.stuefe@sap.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     1
/*
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     2
 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     3
 * Copyright 2012 SAP AG. All rights reserved.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     5
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     8
 * published by the Free Software Foundation.  Oracle designates this
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     9
 * particular file as subject to the "Classpath" exception as provided
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    10
 * by Oracle in the LICENSE file that accompanied this code.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    11
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    12
 * This code is distributed in the hope that it will be useful, but WITHOUT
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    15
 * version 2 for more details (a copy is included in the LICENSE file that
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    16
 * accompanied this code).
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    17
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License version
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    19
 * 2 along with this work; if not, write to the Free Software Foundation,
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    20
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    21
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    22
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    23
 * or visit www.oracle.com if you need additional information or have any
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    24
 * questions.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    25
 */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    26
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    27
package sun.nio.ch;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    28
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    29
import java.nio.channels.*;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    30
import java.nio.channels.spi.AsynchronousChannelProvider;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    31
import java.util.concurrent.ExecutorService;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    32
import java.util.concurrent.ThreadFactory;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    33
import java.io.IOException;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    34
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    35
public class AixAsynchronousChannelProvider
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    36
    extends AsynchronousChannelProvider
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    37
{
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    38
    private static volatile AixPollPort defaultPort;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    39
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    40
    private AixPollPort defaultEventPort() throws IOException {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    41
        if (defaultPort == null) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    42
            synchronized (AixAsynchronousChannelProvider.class) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    43
                if (defaultPort == null) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    44
                    defaultPort = new AixPollPort(this, ThreadPool.getDefault()).start();
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    45
                }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    46
            }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    47
        }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    48
        return defaultPort;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    49
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    50
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    51
    public AixAsynchronousChannelProvider() {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    52
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    53
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    54
    @Override
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    55
    public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factory)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    56
        throws IOException
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    57
    {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    58
        return new AixPollPort(this, ThreadPool.create(nThreads, factory)).start();
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    59
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    60
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    61
    @Override
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    62
    public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    63
        throws IOException
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    64
    {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    65
        return new AixPollPort(this, ThreadPool.wrap(executor, initialSize)).start();
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    66
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    67
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    68
    private Port toPort(AsynchronousChannelGroup group) throws IOException {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    69
        if (group == null) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    70
            return defaultEventPort();
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    71
        } else {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    72
            if (!(group instanceof AixPollPort))
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    73
                throw new IllegalChannelGroupException();
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    74
            return (Port)group;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    75
        }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    76
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    77
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    78
    @Override
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    79
    public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(AsynchronousChannelGroup group)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    80
        throws IOException
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    81
    {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    82
        return new UnixAsynchronousServerSocketChannelImpl(toPort(group));
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    83
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    84
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    85
    @Override
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    86
    public AsynchronousSocketChannel openAsynchronousSocketChannel(AsynchronousChannelGroup group)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    87
        throws IOException
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    88
    {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    89
        return new UnixAsynchronousSocketChannelImpl(toPort(group));
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    90
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    91
}