author | neliasso |
Fri, 29 Nov 2019 11:26:25 +0100 | |
changeset 59324 | 5e8f9713e343 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
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.lang.annotation.Native; |
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 |
* Represents the service level properties for the platform specific socket |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
32 |
* option {@link ExtendedSocketOptions#SO_FLOW_SLA}. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
33 |
* <p> |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
34 |
* The priority and bandwidth parameters must be set before |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
35 |
* setting the socket option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
36 |
* <p> |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
37 |
* When the {@code SO_FLOW_SLA} option is set then it may not take effect |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
38 |
* immediately. If the value of the socket option is obtained with |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
39 |
* {@code getOption()} then the status may be returned as {@code INPROGRESS} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
40 |
* until it takes effect. The priority and bandwidth values are only valid when |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
41 |
* the status is returned as OK. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
42 |
* <p> |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
43 |
* When a security manager is installed, a {@link NetworkPermission} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
44 |
* is required to set or get this option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
45 |
* |
24713
5451c8499988
8044766: New jdk.net classes have @since 1.9 tags in 8u20
michaelm
parents:
23879
diff
changeset
|
46 |
* @since 1.8 |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
47 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
48 |
public class SocketFlow { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
49 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
50 |
@Native public static final int UNSET = -1; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
51 |
@Native public static final int NORMAL_PRIORITY = 1; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
52 |
@Native public static final int HIGH_PRIORITY = 2; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
53 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
54 |
@Native private static final int NO_STATUS_VALUE = 0; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
55 |
@Native private static final int OK_VALUE = 1; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
56 |
@Native private static final int NO_PERMISSION_VALUE = 2; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
57 |
@Native private static final int NOT_CONNECTED_VALUE = 3; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
58 |
@Native private static final int NOT_SUPPORTED_VALUE = 4; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
59 |
@Native private static final int ALREADY_CREATED_VALUE = 5; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
60 |
@Native private static final int IN_PROGRESS_VALUE = 6; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
61 |
@Native private static final int OTHER_VALUE = 7; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
62 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
63 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
64 |
* Enumeration of the return values from the SO_FLOW_SLA |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
65 |
* socket option. Both setting and getting the option return |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
66 |
* one of these statuses, which reflect the state of socket's |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
67 |
* flow. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
68 |
* |
24713
5451c8499988
8044766: New jdk.net classes have @since 1.9 tags in 8u20
michaelm
parents:
23879
diff
changeset
|
69 |
* @since 1.8 |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
70 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
71 |
public enum Status { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
72 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
73 |
* Set or get socket option has not been called yet. Status |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
74 |
* values can only be retrieved after calling set or get. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
75 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
76 |
NO_STATUS(NO_STATUS_VALUE), |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
77 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
78 |
* Flow successfully created. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
79 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
80 |
OK(OK_VALUE), |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
81 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
82 |
* Caller has no permission to create flow. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
83 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
84 |
NO_PERMISSION(NO_PERMISSION_VALUE), |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
85 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
86 |
* Flow can not be created because socket is not connected. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
87 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
88 |
NOT_CONNECTED(NOT_CONNECTED_VALUE), |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
89 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
90 |
* Flow creation not supported for this socket. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
91 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
92 |
NOT_SUPPORTED(NOT_SUPPORTED_VALUE), |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
93 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
94 |
* A flow already exists with identical attributes. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
95 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
96 |
ALREADY_CREATED(ALREADY_CREATED_VALUE), |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
97 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
98 |
* A flow is being created. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
99 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
100 |
IN_PROGRESS(IN_PROGRESS_VALUE), |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
101 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
102 |
* Some other unspecified error. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
103 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
104 |
OTHER(OTHER_VALUE); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
105 |
|
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
106 |
private final int value; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
107 |
Status(int value) { this.value = value; } |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
108 |
|
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
109 |
static Status from(int value) { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
110 |
if (value == NO_STATUS.value) return NO_STATUS; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
111 |
else if (value == OK.value) return OK; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
112 |
else if (value == NO_PERMISSION.value) return NO_PERMISSION; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
113 |
else if (value == NOT_CONNECTED.value) return NOT_CONNECTED; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
114 |
else if (value == NOT_SUPPORTED.value) return NOT_SUPPORTED; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
115 |
else if (value == ALREADY_CREATED.value) return ALREADY_CREATED; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
116 |
else if (value == IN_PROGRESS.value) return IN_PROGRESS; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
117 |
else if (value == OTHER.value) return OTHER; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
118 |
else throw new InternalError("Unknown value: " + value); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
119 |
} |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
120 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
121 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
122 |
private int priority = NORMAL_PRIORITY; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
123 |
private long bandwidth = UNSET; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
124 |
private Status status = Status.NO_STATUS; |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
125 |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
126 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
127 |
* Creates a new SocketFlow that can be used to set the SO_FLOW_SLA |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
128 |
* socket option and create a socket flow. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
129 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
130 |
public static SocketFlow create() { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
131 |
return new SocketFlow(); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
132 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
133 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
134 |
private SocketFlow() { } |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
135 |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
136 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
137 |
* Sets this SocketFlow's priority. Must be either NORMAL_PRIORITY |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
138 |
* HIGH_PRIORITY. If not set, a flow's priority is normal. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
139 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
140 |
* @throws IllegalArgumentException if priority is not NORMAL_PRIORITY or |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
141 |
* HIGH_PRIORITY. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
142 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
143 |
public SocketFlow priority(int priority) { |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
144 |
if (priority != NORMAL_PRIORITY && priority != HIGH_PRIORITY) |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
145 |
throw new IllegalArgumentException("invalid priority :" + priority); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
146 |
this.priority = priority; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
147 |
return this; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
148 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
149 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
150 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
151 |
* Sets this SocketFlow's bandwidth. Must be greater than or equal to zero. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
152 |
* A value of zero drops all packets for the socket. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
153 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
154 |
* @throws IllegalArgumentException if bandwidth is less than zero. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
155 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
156 |
public SocketFlow bandwidth(long bandwidth) { |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
157 |
if (bandwidth < 0) |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
158 |
throw new IllegalArgumentException("invalid bandwidth: " + bandwidth); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
159 |
this.bandwidth = bandwidth; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
160 |
return this; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
161 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
162 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
163 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
164 |
* Returns this SocketFlow's priority. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
165 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
166 |
public int priority() { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
167 |
return priority; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
168 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
169 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
170 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
171 |
* Returns this SocketFlow's bandwidth. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
172 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
173 |
* @return this SocketFlow's bandwidth, or {@code -1} if status is not OK. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
174 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
175 |
public long bandwidth() { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
176 |
return bandwidth; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
177 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
178 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
179 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
180 |
* Returns the Status value of this SocketFlow. NO_STATUS is returned |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
181 |
* if the object was not used in a call to set or get the option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
182 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
183 |
public Status status() { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
184 |
return status; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
185 |
} |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
186 |
|
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
187 |
void status(int status) { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
188 |
this.status = Status.from(status); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
189 |
} |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
190 |
|
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
191 |
@Override |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
192 |
public String toString() { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
193 |
StringBuilder sb = new StringBuilder(super.toString()); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
194 |
sb.append(" [ priority=").append(priority()) |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
195 |
.append(", bandwidth=").append(bandwidth()) |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
196 |
.append(", status=").append(status()) |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
197 |
.append(" ]"); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
198 |
return sb.toString(); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34894
diff
changeset
|
199 |
} |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
200 |
} |