src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaPollSelectorProvider.java
author chegar
Tue, 29 Jan 2019 17:25:43 +0000
branchrsocket-branch
changeset 57120 64301e5a0da8
parent 57115 512e7cc6ccce
child 57123 919516f93dcf
permissions -rw-r--r--
rsocket-branch: cleanup in selector provider and friends
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     1
/*
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     4
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    10
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    16
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    20
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    23
 * questions.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    24
 */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    25
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    26
package jdk.internal.net.rdma;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    27
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    28
import java.io.IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    29
import java.net.ProtocolFamily;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    30
import java.nio.channels.DatagramChannel;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    31
import java.nio.channels.Pipe;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    32
import java.nio.channels.ServerSocketChannel;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    33
import java.nio.channels.SocketChannel;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    34
import java.nio.channels.spi.AbstractSelector;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    35
import java.nio.channels.spi.SelectorProvider;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    36
import java.security.AccessController;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    37
import java.security.PrivilegedAction;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    38
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    39
public class RdmaPollSelectorProvider
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    40
    extends SelectorProvider
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    41
{
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    42
    private static final Object lock = new Object();
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    43
    private static RdmaPollSelectorProvider provider;
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    44
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    45
    public static RdmaPollSelectorProvider provider() {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    46
        synchronized (lock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    47
            if (provider != null)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    48
                return provider;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    49
            return AccessController.doPrivileged(
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    50
                new PrivilegedAction<>() {
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    51
                    public RdmaPollSelectorProvider run() {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    52
                            provider = new RdmaPollSelectorProvider();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    53
                            return provider;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    54
                        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    55
                    });
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    56
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    57
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    58
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    59
    @Override
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    60
    public AbstractSelector openSelector() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    61
        return new RdmaPollSelectorImpl(this);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    62
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    63
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    64
    @Override
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    65
    public SocketChannel openSocketChannel() {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    66
        throw new UnsupportedOperationException();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    67
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    68
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    69
    public SocketChannel openSocketChannel(ProtocolFamily family)
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    70
        throws IOException
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    71
    {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    72
        return new RdmaSocketChannelImpl(this, family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    73
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    74
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    75
    @Override
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    76
    public ServerSocketChannel openServerSocketChannel() {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    77
        throw new UnsupportedOperationException();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    78
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    79
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    80
    public ServerSocketChannel openServerSocketChannel(ProtocolFamily family)
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    81
        throws IOException
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    82
    {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    83
        return new RdmaServerSocketChannelImpl(this, family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    84
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    85
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    86
    @Override
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    87
    public DatagramChannel openDatagramChannel() {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    88
        throw new UnsupportedOperationException();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    89
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    90
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    91
    @Override
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    92
    public DatagramChannel openDatagramChannel(ProtocolFamily family) {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    93
        throw new UnsupportedOperationException();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    94
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    95
57120
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    96
    @Override
64301e5a0da8 rsocket-branch: cleanup in selector provider and friends
chegar
parents: 57115
diff changeset
    97
    public Pipe openPipe() {
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    98
        throw new UnsupportedOperationException();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    99
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   100
}