author | alanb |
Wed, 06 Apr 2011 20:51:55 +0100 | |
changeset 9237 | cbb5753e87e7 |
parent 5506 | 202f599c92aa |
child 23894 | 7500e0f62a4a |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
25 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
package sun.nio.ch; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
27 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
28 |
import java.nio.channels.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
29 |
import java.util.concurrent.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
30 |
import java.security.AccessController; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
31 |
import sun.security.action.GetIntegerAction; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
* Defines static methods to invoke a completion handler or arbitrary task. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
36 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
class Invoker { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
private Invoker() { } |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
// maximum number of completion handlers that may be invoked on the current |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
// thread before it re-directs invocations to the thread pool. This helps |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
42 |
// avoid stack overflow and lessens the risk of starvation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
43 |
private static final int maxHandlerInvokeCount = AccessController.doPrivileged( |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
new GetIntegerAction("sun.nio.ch.maxCompletionHandlersOnStack", 16)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
45 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
// Per-thread object with reference to channel group and a counter for |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
// the number of completion handlers invoked. This should be reset to 0 |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
// when all completion handlers have completed. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
49 |
static class GroupAndInvokeCount { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
private final AsynchronousChannelGroupImpl group; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
51 |
private int handlerInvokeCount; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
52 |
GroupAndInvokeCount(AsynchronousChannelGroupImpl group) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
53 |
this.group = group; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
54 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
55 |
AsynchronousChannelGroupImpl group() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
56 |
return group; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
57 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
int invokeCount() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
59 |
return handlerInvokeCount; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
60 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
61 |
void setInvokeCount(int value) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
62 |
handlerInvokeCount = value; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
63 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
64 |
void resetInvokeCount() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
65 |
handlerInvokeCount = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
66 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
67 |
void incrementInvokeCount() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
68 |
handlerInvokeCount++; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
69 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
70 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
71 |
private static final ThreadLocal<GroupAndInvokeCount> myGroupAndInvokeCount = |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
72 |
new ThreadLocal<GroupAndInvokeCount>() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
73 |
@Override protected GroupAndInvokeCount initialValue() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
74 |
return null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
75 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
76 |
}; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
77 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
78 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
79 |
* Binds this thread to the given group |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
80 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
81 |
static void bindToGroup(AsynchronousChannelGroupImpl group) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
82 |
myGroupAndInvokeCount.set(new GroupAndInvokeCount(group)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
83 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
84 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
86 |
* Returns the GroupAndInvokeCount object for this thread. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
87 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
88 |
static GroupAndInvokeCount getGroupAndInvokeCount() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
89 |
return myGroupAndInvokeCount.get(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
90 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
91 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
92 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
93 |
* Returns true if the current thread is in a channel group's thread pool |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
94 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
95 |
static boolean isBoundToAnyGroup() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
return myGroupAndInvokeCount.get() != null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
98 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
99 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
100 |
* Returns true if the current thread is in the given channel's thread |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
101 |
* pool and we haven't exceeded the maximum number of handler frames on |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
102 |
* the stack. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
103 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
104 |
static boolean mayInvokeDirect(GroupAndInvokeCount myGroupAndInvokeCount, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
105 |
AsynchronousChannelGroupImpl group) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
106 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
107 |
if ((myGroupAndInvokeCount != null) && |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
108 |
(myGroupAndInvokeCount.group() == group) && |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
109 |
(myGroupAndInvokeCount.invokeCount() < maxHandlerInvokeCount)) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
110 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
111 |
return true; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
112 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
113 |
return false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
114 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
115 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
116 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
117 |
* Invoke handler without checking the thread identity or number of handlers |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
118 |
* on the thread stack. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
119 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
120 |
static <V,A> void invokeUnchecked(CompletionHandler<V,? super A> handler, |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
121 |
A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
122 |
V value, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
123 |
Throwable exc) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
124 |
{ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
125 |
if (exc == null) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
126 |
handler.completed(value, attachment); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
127 |
} else { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
128 |
handler.failed(exc, attachment); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
129 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
130 |
|
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
131 |
// clear interrupt |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
132 |
Thread.interrupted(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
133 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
134 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
/** |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
136 |
* Invoke handler assuming thread identity already checked |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
137 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
138 |
static <V,A> void invokeDirect(GroupAndInvokeCount myGroupAndInvokeCount, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
139 |
CompletionHandler<V,? super A> handler, |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
140 |
A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
141 |
V result, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
142 |
Throwable exc) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
143 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
144 |
myGroupAndInvokeCount.incrementInvokeCount(); |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
145 |
Invoker.invokeUnchecked(handler, attachment, result, exc); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
146 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
147 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
148 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
149 |
* Invokes the handler. If the current thread is in the channel group's |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
150 |
* thread pool then the handler is invoked directly, otherwise it is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
151 |
* invoked indirectly. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
152 |
*/ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
153 |
static <V,A> void invoke(AsynchronousChannel channel, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
154 |
CompletionHandler<V,? super A> handler, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
155 |
A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
156 |
V result, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
157 |
Throwable exc) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
158 |
{ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
159 |
boolean invokeDirect = false; |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
160 |
boolean identityOkay = false; |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
161 |
GroupAndInvokeCount thisGroupAndInvokeCount = myGroupAndInvokeCount.get(); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
162 |
if (thisGroupAndInvokeCount != null) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
163 |
if ((thisGroupAndInvokeCount.group() == ((Groupable)channel).group())) |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
164 |
identityOkay = true; |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
165 |
if (identityOkay && |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
166 |
(thisGroupAndInvokeCount.invokeCount() < maxHandlerInvokeCount)) |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
167 |
{ |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
168 |
// group match |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
169 |
invokeDirect = true; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
170 |
} |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
171 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
172 |
if (invokeDirect) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
173 |
invokeDirect(thisGroupAndInvokeCount, handler, attachment, result, exc); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
174 |
} else { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
175 |
try { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
176 |
invokeIndirectly(channel, handler, attachment, result, exc); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
177 |
} catch (RejectedExecutionException ree) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
178 |
// channel group shutdown; fallback to invoking directly |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
179 |
// if the current thread has the right identity. |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
180 |
if (identityOkay) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
181 |
invokeDirect(thisGroupAndInvokeCount, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
182 |
handler, attachment, result, exc); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
183 |
} else { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
184 |
throw new ShutdownChannelGroupException(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
185 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
186 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
187 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
188 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
189 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
190 |
/** |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
191 |
* Invokes the handler indirectly via the channel group's thread pool. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
192 |
*/ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
193 |
static <V,A> void invokeIndirectly(AsynchronousChannel channel, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
194 |
final CompletionHandler<V,? super A> handler, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
195 |
final A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
196 |
final V result, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
197 |
final Throwable exc) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
198 |
{ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
199 |
try { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
200 |
((Groupable)channel).group().executeOnPooledThread(new Runnable() { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
201 |
public void run() { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
202 |
GroupAndInvokeCount thisGroupAndInvokeCount = |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
203 |
myGroupAndInvokeCount.get(); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
204 |
if (thisGroupAndInvokeCount != null) |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
205 |
thisGroupAndInvokeCount.setInvokeCount(1); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
206 |
invokeUnchecked(handler, attachment, result, exc); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
207 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
208 |
}); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
209 |
} catch (RejectedExecutionException ree) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
210 |
throw new ShutdownChannelGroupException(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
211 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
212 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
213 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
214 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
215 |
* Invokes the handler "indirectly" in the given Executor |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
216 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
217 |
static <V,A> void invokeIndirectly(final CompletionHandler<V,? super A> handler, |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
218 |
final A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
219 |
final V value, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
220 |
final Throwable exc, |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
221 |
Executor executor) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
222 |
{ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
223 |
try { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
224 |
executor.execute(new Runnable() { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
225 |
public void run() { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
226 |
invokeUnchecked(handler, attachment, value, exc); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
227 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
228 |
}); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
229 |
} catch (RejectedExecutionException ree) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
230 |
throw new ShutdownChannelGroupException(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
231 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
232 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
233 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
234 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
235 |
* Invokes the given task on the thread pool associated with the given |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
236 |
* channel. If the current thread is in the thread pool then the task is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
237 |
* invoked directly. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
238 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
239 |
static void invokeOnThreadInThreadPool(Groupable channel, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
240 |
Runnable task) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
241 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
242 |
boolean invokeDirect; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
243 |
GroupAndInvokeCount thisGroupAndInvokeCount = myGroupAndInvokeCount.get(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
244 |
AsynchronousChannelGroupImpl targetGroup = channel.group(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
245 |
if (thisGroupAndInvokeCount == null) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
246 |
invokeDirect = false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
247 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
248 |
invokeDirect = (thisGroupAndInvokeCount.group == targetGroup); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
249 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
250 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
251 |
if (invokeDirect) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
252 |
task.run(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
253 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
254 |
targetGroup.executeOnPooledThread(task); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
255 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
256 |
} catch (RejectedExecutionException ree) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
257 |
throw new ShutdownChannelGroupException(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
258 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
259 |
} |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
260 |
|
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
261 |
/** |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
262 |
* Invoke handler with completed result. This method does not check the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
263 |
* thread identity or the number of handlers on the thread stack. |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
264 |
*/ |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
265 |
static <V,A> void invokeUnchecked(PendingFuture<V,A> future) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
266 |
assert future.isDone(); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
267 |
CompletionHandler<V,? super A> handler = future.handler(); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
268 |
if (handler != null) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
269 |
invokeUnchecked(handler, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
270 |
future.attachment(), |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
271 |
future.value(), |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
272 |
future.exception()); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
273 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
274 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
275 |
|
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
276 |
/** |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
277 |
* Invoke handler with completed result. If the current thread is in the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
278 |
* channel group's thread pool then the handler is invoked directly, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
279 |
* otherwise it is invoked indirectly. |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
280 |
*/ |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
281 |
static <V,A> void invoke(PendingFuture<V,A> future) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
282 |
assert future.isDone(); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
283 |
CompletionHandler<V,? super A> handler = future.handler(); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
284 |
if (handler != null) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
285 |
invoke(future.channel(), |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
286 |
handler, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
287 |
future.attachment(), |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
288 |
future.value(), |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
289 |
future.exception()); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
290 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
291 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
292 |
|
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
293 |
/** |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
294 |
* Invoke handler with completed result. The handler is invoked indirectly, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
295 |
* via the channel group's thread pool. |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
296 |
*/ |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
297 |
static <V,A> void invokeIndirectly(PendingFuture<V,A> future) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
298 |
assert future.isDone(); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
299 |
CompletionHandler<V,? super A> handler = future.handler(); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
300 |
if (handler != null) { |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
301 |
invokeIndirectly(future.channel(), |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
302 |
handler, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
303 |
future.attachment(), |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
304 |
future.value(), |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
305 |
future.exception()); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
306 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
307 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
308 |
} |