jdk/src/share/classes/jdk/net/ExtendedSocketOptions.java
author michaelm
Sat, 12 Apr 2014 20:21:09 +0100
changeset 23879 284802a2d355
child 24713 5451c8499988
permissions -rw-r--r--
8036979: Support java.net.SocketOption<> in java.net socket types Reviewed-by: alanb, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     1
/*
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     4
 *
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    10
 *
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    15
 * accompanied this code).
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    16
 *
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    20
 *
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    23
 * questions.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    24
 */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    25
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    26
package jdk.net;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    27
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    28
import java.net.SocketOption;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    29
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    30
/**
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    31
 * Defines extended socket options, beyond those defined in
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    32
 * {@link java.net.StandardSocketOptions}. These options may be platform
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    33
 * specific.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    34
 *
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    35
 * @since 1.9
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    36
 */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    37
@jdk.Exported
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    38
public final class ExtendedSocketOptions {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    39
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    40
    private static class ExtSocketOption<T> implements SocketOption<T> {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    41
        private final String name;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    42
        private final Class<T> type;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    43
        ExtSocketOption(String name, Class<T> type) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    44
            this.name = name;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    45
            this.type = type;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    46
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    47
        @Override public String name() { return name; }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    48
        @Override public Class<T> type() { return type; }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    49
        @Override public String toString() { return name; }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    50
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    51
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    52
    private ExtendedSocketOptions() {}
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    53
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    54
    /**
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    55
     * Service level properties. When a security manager is installed,
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    56
     * setting or getting this option requires a {@link NetworkPermission}
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    57
     * {@code ("setOption.SO_FLOW_SLA")} or {@code "getOption.SO_FLOW_SLA"}
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    58
     * respectively.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    59
     */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    60
    public static final SocketOption<SocketFlow> SO_FLOW_SLA = new
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    61
        ExtSocketOption<SocketFlow>("SO_FLOW_SLA", SocketFlow.class);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    62
}