Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
5c06ae9b
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5c06ae9b
编写于
11月 02, 2010
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6993126: (aio) remove AsynchronousDatagramChannel
Reviewed-by: chegar
上级
676d64f3
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
4 addition
and
1733 deletion
+4
-1733
make/java/nio/FILES_java.gmk
make/java/nio/FILES_java.gmk
+0
-2
src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java
...lasses/java/nio/channels/AsynchronousDatagramChannel.java
+0
-572
src/share/classes/java/nio/channels/package-info.java
src/share/classes/java/nio/channels/package-info.java
+0
-2
src/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java
...es/java/nio/channels/spi/AsynchronousChannelProvider.java
+0
-23
src/share/classes/sun/nio/ch/SimpleAsynchronousDatagramChannelImpl.java
...ses/sun/nio/ch/SimpleAsynchronousDatagramChannelImpl.java
+0
-667
src/solaris/classes/sun/nio/ch/LinuxAsynchronousChannelProvider.java
.../classes/sun/nio/ch/LinuxAsynchronousChannelProvider.java
+0
-9
src/solaris/classes/sun/nio/ch/SolarisAsynchronousChannelProvider.java
...lasses/sun/nio/ch/SolarisAsynchronousChannelProvider.java
+0
-9
src/windows/classes/sun/nio/ch/WindowsAsynchronousChannelProvider.java
...lasses/sun/nio/ch/WindowsAsynchronousChannelProvider.java
+0
-9
test/java/nio/channels/AsynchronousChannelGroup/Basic.java
test/java/nio/channels/AsynchronousChannelGroup/Basic.java
+4
-14
test/java/nio/channels/AsynchronousDatagramChannel/Basic.java
.../java/nio/channels/AsynchronousDatagramChannel/Basic.java
+0
-410
test/java/nio/channels/spi/AsynchronousChannelProvider/Provider1.java
...o/channels/spi/AsynchronousChannelProvider/Provider1.java
+0
-8
test/java/nio/channels/spi/AsynchronousChannelProvider/Provider2.java
...o/channels/spi/AsynchronousChannelProvider/Provider2.java
+0
-8
未找到文件。
make/java/nio/FILES_java.gmk
浏览文件 @
5c06ae9b
...
...
@@ -33,7 +33,6 @@ FILES_src = \
java/nio/channels/AsynchronousByteChannel.java \
java/nio/channels/AsynchronousChannel.java \
java/nio/channels/AsynchronousChannelGroup.java \
java/nio/channels/AsynchronousDatagramChannel.java \
java/nio/channels/AsynchronousFileChannel.java \
java/nio/channels/AsynchronousServerSocketChannel.java \
java/nio/channels/AsynchronousSocketChannel.java \
...
...
@@ -207,7 +206,6 @@ FILES_src = \
sun/nio/ch/SelChImpl.java \
sun/nio/ch/ServerSocketAdaptor.java \
sun/nio/ch/ServerSocketChannelImpl.java \
sun/nio/ch/SimpleAsynchronousDatagramChannelImpl.java \
sun/nio/ch/SinkChannelImpl.java \
sun/nio/ch/SocketAdaptor.java \
sun/nio/ch/SocketChannelImpl.java \
...
...
src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java
已删除
100644 → 0
浏览文件 @
676d64f3
此差异已折叠。
点击以展开。
src/share/classes/java/nio/channels/package-info.java
浏览文件 @
5c06ae9b
...
...
@@ -232,8 +232,6 @@
* <td>An asynchronous channel to a stream-oriented connecting socket</td></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousServerSocketChannel} </tt></td>
* <td>An asynchronous channel to a stream-oriented listening socket</td></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousDatagramChannel}</tt></td>
* <td>An asynchronous channel to a datagram-oriented socket</td></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.CompletionHandler}</tt></td>
* <td>A handler for consuming the result of an asynchronous operation</td></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousChannelGroup}</tt></td>
...
...
src/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java
浏览文件 @
5c06ae9b
...
...
@@ -26,7 +26,6 @@
package
java.nio.channels.spi
;
import
java.nio.channels.*
;
import
java.net.ProtocolFamily
;
import
java.io.IOException
;
import
java.util.Iterator
;
import
java.util.ServiceLoader
;
...
...
@@ -239,26 +238,4 @@ public abstract class AsynchronousChannelProvider {
*/
public
abstract
AsynchronousSocketChannel
openAsynchronousSocketChannel
(
AsynchronousChannelGroup
group
)
throws
IOException
;
/**
* Opens an asynchronous datagram channel.
*
* @param family
* The protocol family, or {@code null} for the default protocol
* family
* @param group
* The group to which the channel is bound, or {@code null} to
* bind to the default group
*
* @return The new channel
*
* @throws IllegalChannelGroupException
* If the provider that created the group differs from this provider
* @throws ShutdownChannelGroupException
* The group is shutdown
* @throws IOException
* If an I/O error occurs
*/
public
abstract
AsynchronousDatagramChannel
openAsynchronousDatagramChannel
(
ProtocolFamily
family
,
AsynchronousChannelGroup
group
)
throws
IOException
;
}
src/share/classes/sun/nio/ch/SimpleAsynchronousDatagramChannelImpl.java
已删除
100644 → 0
浏览文件 @
676d64f3
此差异已折叠。
点击以展开。
src/solaris/classes/sun/nio/ch/LinuxAsynchronousChannelProvider.java
浏览文件 @
5c06ae9b
...
...
@@ -29,7 +29,6 @@ import java.nio.channels.*;
import
java.nio.channels.spi.AsynchronousChannelProvider
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ThreadFactory
;
import
java.net.ProtocolFamily
;
import
java.io.IOException
;
public
class
LinuxAsynchronousChannelProvider
...
...
@@ -88,12 +87,4 @@ public class LinuxAsynchronousChannelProvider
{
return
new
UnixAsynchronousSocketChannelImpl
(
toPort
(
group
));
}
@Override
public
AsynchronousDatagramChannel
openAsynchronousDatagramChannel
(
ProtocolFamily
family
,
AsynchronousChannelGroup
group
)
throws
IOException
{
return
new
SimpleAsynchronousDatagramChannelImpl
(
family
,
toPort
(
group
));
}
}
src/solaris/classes/sun/nio/ch/SolarisAsynchronousChannelProvider.java
浏览文件 @
5c06ae9b
...
...
@@ -29,7 +29,6 @@ import java.nio.channels.*;
import
java.nio.channels.spi.AsynchronousChannelProvider
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ThreadFactory
;
import
java.net.ProtocolFamily
;
import
java.io.IOException
;
public
class
SolarisAsynchronousChannelProvider
...
...
@@ -91,12 +90,4 @@ public class SolarisAsynchronousChannelProvider
{
return
new
UnixAsynchronousSocketChannelImpl
(
toEventPort
(
group
));
}
@Override
public
AsynchronousDatagramChannel
openAsynchronousDatagramChannel
(
ProtocolFamily
family
,
AsynchronousChannelGroup
group
)
throws
IOException
{
return
new
SimpleAsynchronousDatagramChannelImpl
(
family
,
toEventPort
(
group
));
}
}
src/windows/classes/sun/nio/ch/WindowsAsynchronousChannelProvider.java
浏览文件 @
5c06ae9b
...
...
@@ -29,7 +29,6 @@ import java.nio.channels.*;
import
java.nio.channels.spi.AsynchronousChannelProvider
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ThreadFactory
;
import
java.net.ProtocolFamily
;
import
java.io.IOException
;
public
class
WindowsAsynchronousChannelProvider
...
...
@@ -90,12 +89,4 @@ public class WindowsAsynchronousChannelProvider
{
return
new
WindowsAsynchronousSocketChannelImpl
(
toIocp
(
group
));
}
@Override
public
AsynchronousDatagramChannel
openAsynchronousDatagramChannel
(
ProtocolFamily
family
,
AsynchronousChannelGroup
group
)
throws
IOException
{
return
new
SimpleAsynchronousDatagramChannelImpl
(
family
,
toIocp
(
group
));
}
}
test/java/nio/channels/AsynchronousChannelGroup/Basic.java
浏览文件 @
5c06ae9b
...
...
@@ -89,10 +89,9 @@ public class Basic {
}
// create channel that is bound to group
AsynchronousChannel
ch
;
switch
(
rand
.
nextInt
(
3
))
{
switch
(
rand
.
nextInt
(
2
))
{
case
0
:
ch
=
AsynchronousSocketChannel
.
open
(
group
);
break
;
case
1
:
ch
=
AsynchronousServerSocketChannel
.
open
(
group
);
break
;
case
2
:
ch
=
AsynchronousDatagramChannel
.
open
(
null
,
group
);
break
;
default
:
throw
new
AssertionError
();
}
group
.
shutdown
();
...
...
@@ -128,18 +127,9 @@ public class Basic {
}
// I/O in progress
AsynchronousChannel
ch
;
if
(
rand
.
nextBoolean
())
{
AsynchronousServerSocketChannel
listener
=
AsynchronousServerSocketChannel
.
open
(
group
).
bind
(
new
InetSocketAddress
(
0
));
listener
.
accept
();
ch
=
listener
;
}
else
{
AsynchronousDatagramChannel
adc
=
AsynchronousDatagramChannel
.
open
(
null
,
group
);
adc
.
receive
(
ByteBuffer
.
allocate
(
100
));
ch
=
adc
;
}
AsynchronousServerSocketChannel
ch
=
AsynchronousServerSocketChannel
.
open
(
group
).
bind
(
new
InetSocketAddress
(
0
));
ch
.
accept
();
// forceful shutdown
group
.
shutdownNow
();
...
...
test/java/nio/channels/AsynchronousDatagramChannel/Basic.java
已删除
100644 → 0
浏览文件 @
676d64f3
/*
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 4527345 6842687
* @summary Unit test for AsynchronousDatagramChannel
*/
import
java.nio.ByteBuffer
;
import
java.nio.channels.*
;
import
java.net.*
;
import
java.util.concurrent.*
;
import
java.util.concurrent.atomic.*
;
public
class
Basic
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
doReceiveTests
();
doReadTests
();
doSendTests
();
doWriteTests
();
doCancelTests
();
doMulticastTests
();
}
// basic receive tests
static
void
doReceiveTests
()
throws
Exception
{
final
byte
[]
msg
=
"hello"
.
getBytes
();
AsynchronousDatagramChannel
ch
=
AsynchronousDatagramChannel
.
open
()
.
bind
(
new
InetSocketAddress
(
0
));
int
port
=
((
InetSocketAddress
)(
ch
.
getLocalAddress
())).
getPort
();
InetAddress
rh
=
InetAddress
.
getLocalHost
();
final
SocketAddress
sa
=
new
InetSocketAddress
(
rh
,
port
);
DatagramChannel
sender
=
DatagramChannel
.
open
();
ByteBuffer
dst
=
ByteBuffer
.
allocateDirect
(
100
);
// Test: datagram packet received immediately
sender
.
send
(
ByteBuffer
.
wrap
(
msg
),
sa
);
dst
.
clear
();
ch
.
receive
(
dst
).
get
(
1
,
TimeUnit
.
SECONDS
);
if
(
dst
.
flip
().
remaining
()
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes read"
);
// Test: datagram packet not received immediately
dst
.
clear
();
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
ch
.
receive
(
dst
,
(
Void
)
null
,
new
CompletionHandler
<
SocketAddress
,
Void
>()
{
public
void
completed
(
SocketAddress
source
,
Void
att
)
{
latch
.
countDown
();
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
}
});
Thread
.
sleep
(
2000
);
sender
.
send
(
ByteBuffer
.
wrap
(
msg
),
sa
);
latch
.
await
(
2
,
TimeUnit
.
SECONDS
);
// wait for completion handler
// Test: timeout
dst
.
clear
();
final
AtomicReference
<
Throwable
>
exception
=
new
AtomicReference
<
Throwable
>();
ch
.
receive
(
dst
,
2
,
TimeUnit
.
SECONDS
,
(
Void
)
null
,
new
CompletionHandler
<
SocketAddress
,
Void
>()
{
public
void
completed
(
SocketAddress
source
,
Void
att
)
{
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
exception
.
set
(
exc
);
}
});
Throwable
result
;
while
((
result
=
exception
.
get
())
==
null
)
{
Thread
.
sleep
(
100
);
}
if
(!(
result
instanceof
InterruptedByTimeoutException
))
throw
new
RuntimeException
(
"InterruptedByTimeoutException expected"
);
// AsynchronousCloseException
dst
=
ByteBuffer
.
allocateDirect
(
100
);
exception
.
set
(
null
);
ch
.
receive
(
dst
,
(
Void
)
null
,
new
CompletionHandler
<
SocketAddress
,
Void
>()
{
public
void
completed
(
SocketAddress
source
,
Void
att
)
{
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
exception
.
set
(
exc
);
}
});
ch
.
close
();
while
((
result
=
exception
.
get
())
==
null
)
{
Thread
.
sleep
(
100
);
}
if
(!(
result
instanceof
AsynchronousCloseException
))
throw
new
RuntimeException
(
"AsynchronousCloseException expected"
);
// done
sender
.
close
();
}
// basic read tests
static
void
doReadTests
()
throws
Exception
{
final
byte
[]
msg
=
"hello"
.
getBytes
();
AsynchronousDatagramChannel
ch
=
AsynchronousDatagramChannel
.
open
()
.
bind
(
new
InetSocketAddress
(
0
));
int
port
=
((
InetSocketAddress
)(
ch
.
getLocalAddress
())).
getPort
();
InetAddress
lh
=
InetAddress
.
getLocalHost
();
final
SocketAddress
sa
=
new
InetSocketAddress
(
lh
,
port
);
DatagramChannel
sender
=
DatagramChannel
.
open
();
ByteBuffer
dst
=
ByteBuffer
.
allocateDirect
(
100
);
// Test: not connected
try
{
ch
.
read
(
dst
);
throw
new
RuntimeException
(
"NotYetConnectedException expected"
);
}
catch
(
NotYetConnectedException
e
)
{
}
// connect the channel
sender
.
bind
(
new
InetSocketAddress
(
0
));
ch
.
connect
(
new
InetSocketAddress
(
lh
,
((
InetSocketAddress
)(
sender
.
getLocalAddress
())).
getPort
()));
// Test: datagram packet received immediately
sender
.
send
(
ByteBuffer
.
wrap
(
msg
),
sa
);
dst
.
clear
();
ch
.
read
(
dst
).
get
(
1
,
TimeUnit
.
SECONDS
);
if
(
dst
.
flip
().
remaining
()
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes read"
);
// Test: datagram packet not received immediately
dst
.
clear
();
final
CountDownLatch
l1
=
new
CountDownLatch
(
1
);
ch
.
read
(
dst
,
(
Void
)
null
,
new
CompletionHandler
<
Integer
,
Void
>()
{
public
void
completed
(
Integer
bytesRead
,
Void
att
)
{
l1
.
countDown
();
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
}
});
Thread
.
sleep
(
2000
);
sender
.
send
(
ByteBuffer
.
wrap
(
msg
),
sa
);
l1
.
await
(
2
,
TimeUnit
.
SECONDS
);
// Test: timeout
dst
.
clear
();
final
AtomicReference
<
Throwable
>
exception
=
new
AtomicReference
<
Throwable
>();
ch
.
read
(
dst
,
2
,
TimeUnit
.
SECONDS
,
(
Void
)
null
,
new
CompletionHandler
<
Integer
,
Void
>()
{
public
void
completed
(
Integer
bytesRead
,
Void
att
)
{
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
exception
.
set
(
exc
);
}
});
Throwable
result
;
while
((
result
=
exception
.
get
())
==
null
)
{
Thread
.
sleep
(
100
);
}
if
(!(
result
instanceof
InterruptedByTimeoutException
))
throw
new
RuntimeException
(
"InterruptedByTimeoutException expected"
);
// AsynchronousCloseException
dst
.
clear
();
exception
.
set
(
null
);
ch
.
read
(
dst
,
(
Void
)
null
,
new
CompletionHandler
<
Integer
,
Void
>()
{
public
void
completed
(
Integer
bytesRead
,
Void
att
)
{
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
exception
.
set
(
exc
);
}
});
ch
.
close
();
while
((
result
=
exception
.
get
())
==
null
)
{
Thread
.
sleep
(
100
);
}
if
(!(
result
instanceof
AsynchronousCloseException
))
throw
new
RuntimeException
(
"AsynchronousCloseException expected"
);
// done
sender
.
close
();
}
// basic send tests
static
void
doSendTests
()
throws
Exception
{
final
byte
[]
msg
=
"hello"
.
getBytes
();
DatagramChannel
reader
=
DatagramChannel
.
open
()
.
bind
(
new
InetSocketAddress
(
0
));
int
port
=
((
InetSocketAddress
)(
reader
.
getLocalAddress
())).
getPort
();
InetAddress
rh
=
InetAddress
.
getLocalHost
();
SocketAddress
sa
=
new
InetSocketAddress
(
rh
,
port
);
AsynchronousDatagramChannel
ch
=
AsynchronousDatagramChannel
.
open
();
// Test: send datagram packet to reader
int
bytesSent
=
ch
.
send
(
ByteBuffer
.
wrap
(
msg
),
sa
).
get
();
if
(
bytesSent
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes sent"
);
// check received
ByteBuffer
dst
=
ByteBuffer
.
allocateDirect
(
100
);
reader
.
receive
(
dst
);
dst
.
flip
();
if
(
dst
.
remaining
()
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes received"
);
// Test: send datagram packet to reader and check completion handler
// is invoked
final
CountDownLatch
l2
=
new
CountDownLatch
(
1
);
ch
.
send
(
ByteBuffer
.
wrap
(
msg
),
sa
,
(
Void
)
null
,
new
CompletionHandler
<
Integer
,
Void
>()
{
public
void
completed
(
Integer
bytesSent
,
Void
att
)
{
if
(
bytesSent
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes received"
);
l2
.
countDown
();
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
}
});
l2
.
await
(
5
,
TimeUnit
.
SECONDS
);
// check received
dst
.
clear
();
reader
.
receive
(
dst
);
dst
.
flip
();
if
(
dst
.
remaining
()
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes received"
);
// Test: check that failed method is invoked
ch
.
close
();
final
CountDownLatch
l3
=
new
CountDownLatch
(
1
);
ch
.
send
(
ByteBuffer
.
wrap
(
msg
),
sa
,
(
Void
)
null
,
new
CompletionHandler
<
Integer
,
Void
>()
{
public
void
completed
(
Integer
bytesSent
,
Void
att
)
{
throw
new
RuntimeException
(
"completed method invoked"
);
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
if
(
exc
instanceof
ClosedChannelException
)
{
l3
.
countDown
();
}
else
{
throw
new
RuntimeException
(
exc
);
}
}
});
l3
.
await
(
5
,
TimeUnit
.
SECONDS
);
// done
reader
.
close
();
}
// basic write tests
static
void
doWriteTests
()
throws
Exception
{
final
byte
[]
msg
=
"hello"
.
getBytes
();
DatagramChannel
reader
=
DatagramChannel
.
open
()
.
bind
(
new
InetSocketAddress
(
0
));
int
port
=
((
InetSocketAddress
)(
reader
.
getLocalAddress
())).
getPort
();
InetAddress
rh
=
InetAddress
.
getLocalHost
();
SocketAddress
sa
=
new
InetSocketAddress
(
rh
,
port
);
AsynchronousDatagramChannel
ch
=
AsynchronousDatagramChannel
.
open
();
// Test: unconnected
try
{
ch
.
write
(
ByteBuffer
.
wrap
(
msg
)).
get
();
throw
new
RuntimeException
(
"NotYetConnectedException expected"
);
}
catch
(
NotYetConnectedException
e
)
{
}
// Test: connect, and write datagram
ch
.
connect
(
sa
);
int
bytesSent
=
ch
.
write
(
ByteBuffer
.
wrap
(
msg
)).
get
();
if
(
bytesSent
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes sent"
);
// check received
ByteBuffer
dst
=
ByteBuffer
.
allocateDirect
(
100
);
reader
.
receive
(
dst
);
dst
.
flip
();
if
(
dst
.
remaining
()
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes received"
);
// Test: write datagram and check completion handler is invoked
final
CountDownLatch
l2
=
new
CountDownLatch
(
1
);
ch
.
write
(
ByteBuffer
.
wrap
(
msg
),
(
Void
)
null
,
new
CompletionHandler
<
Integer
,
Void
>()
{
public
void
completed
(
Integer
bytesSent
,
Void
att
)
{
if
(
bytesSent
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes received"
);
l2
.
countDown
();
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
}
});
l2
.
await
(
5
,
TimeUnit
.
SECONDS
);
// check received
dst
.
clear
();
reader
.
receive
(
dst
);
dst
.
flip
();
if
(
dst
.
remaining
()
!=
msg
.
length
)
throw
new
RuntimeException
(
"Unexpected number of bytes received"
);
// done
ch
.
close
();
reader
.
close
();
}
static
void
cancelAndCheck
(
Future
<?>
result
)
throws
InterruptedException
{
boolean
cancelled
=
result
.
cancel
(
false
);
if
(!
cancelled
)
throw
new
RuntimeException
(
"Not cancelled"
);
if
(!
result
.
isDone
())
throw
new
RuntimeException
(
"Should be done"
);
try
{
result
.
get
();
throw
new
RuntimeException
(
"Result not expected"
);
}
catch
(
CancellationException
e
)
{
// expected
}
catch
(
ExecutionException
e
)
{
throw
new
RuntimeException
(
"Should not fail"
);
}
}
// basic cancel tests
static
void
doCancelTests
()
throws
Exception
{
InetAddress
lh
=
InetAddress
.
getLocalHost
();
// receive
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
AsynchronousDatagramChannel
ch
=
AsynchronousDatagramChannel
.
open
().
bind
(
new
InetSocketAddress
(
0
));
Future
<
SocketAddress
>
remote
=
ch
.
receive
(
ByteBuffer
.
allocate
(
100
));
cancelAndCheck
(
remote
);
ch
.
close
();
}
// read
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
AsynchronousDatagramChannel
ch
=
AsynchronousDatagramChannel
.
open
().
bind
(
new
InetSocketAddress
(
0
));
ch
.
connect
(
new
InetSocketAddress
(
lh
,
((
InetSocketAddress
)(
ch
.
getLocalAddress
())).
getPort
()));
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
long
timeout
=
(
i
==
0
)
?
0L
:
60L
;
Future
<
Integer
>
result
=
ch
.
read
(
ByteBuffer
.
allocate
(
100
));
cancelAndCheck
(
result
);
ch
.
close
();
}
}
// basic multicast test
static
void
doMulticastTests
()
throws
Exception
{
final
byte
[]
msg
=
"hello"
.
getBytes
();
InetAddress
lh
=
InetAddress
.
getLocalHost
();
NetworkInterface
interf
=
NetworkInterface
.
getByInetAddress
(
lh
);
if
(
interf
.
isLoopback
()
||
!
interf
.
supportsMulticast
())
{
System
.
out
.
println
(
"Multicasting not tested"
);
return
;
}
AsynchronousDatagramChannel
ch
=
AsynchronousDatagramChannel
.
open
(
StandardProtocolFamily
.
INET
,
null
)
.
setOption
(
StandardSocketOption
.
SO_REUSEADDR
,
true
)
.
bind
(
new
InetSocketAddress
(
0
));
int
port
=
((
InetSocketAddress
)(
ch
.
getLocalAddress
())).
getPort
();
// join group
InetAddress
group
=
InetAddress
.
getByName
(
"225.4.5.6"
);
MembershipKey
key
=
ch
.
join
(
group
,
interf
);
// check key
if
(
key
.
channel
()
!=
ch
)
throw
new
RuntimeException
(
"Not the expected channel"
);
// send message to group
DatagramChannel
sender
=
DatagramChannel
.
open
();
sender
.
send
(
ByteBuffer
.
wrap
(
msg
),
new
InetSocketAddress
(
group
,
port
));
sender
.
close
();
// check message received
ByteBuffer
dst
=
ByteBuffer
.
allocate
(
200
);
SocketAddress
source
=
ch
.
receive
(
dst
).
get
(
2
,
TimeUnit
.
SECONDS
);
if
(!((
InetSocketAddress
)
source
).
getAddress
().
equals
(
lh
))
throw
new
RuntimeException
(
"Unexpected source"
);
// done
ch
.
close
();
}
}
test/java/nio/channels/spi/AsynchronousChannelProvider/Provider1.java
浏览文件 @
5c06ae9b
...
...
@@ -23,7 +23,6 @@
import
java.nio.channels.spi.AsynchronousChannelProvider
;
import
java.nio.channels.*
;
import
java.net.ProtocolFamily
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ThreadFactory
;
import
java.io.IOException
;
...
...
@@ -59,11 +58,4 @@ public class Provider1 extends AsynchronousChannelProvider {
{
throw
new
RuntimeException
();
}
@Override
public
AsynchronousDatagramChannel
openAsynchronousDatagramChannel
(
ProtocolFamily
family
,
AsynchronousChannelGroup
group
)
throws
IOException
{
throw
new
RuntimeException
();
}
}
test/java/nio/channels/spi/AsynchronousChannelProvider/Provider2.java
浏览文件 @
5c06ae9b
...
...
@@ -23,7 +23,6 @@
import
java.nio.channels.spi.AsynchronousChannelProvider
;
import
java.nio.channels.*
;
import
java.net.ProtocolFamily
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ThreadFactory
;
import
java.io.IOException
;
...
...
@@ -59,11 +58,4 @@ public class Provider2 extends AsynchronousChannelProvider {
{
throw
new
RuntimeException
();
}
@Override
public
AsynchronousDatagramChannel
openAsynchronousDatagramChannel
(
ProtocolFamily
family
,
AsynchronousChannelGroup
group
)
throws
IOException
{
throw
new
RuntimeException
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录