Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
7c4e4465
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7c4e4465
编写于
1月 09, 2010
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6907760: (file) OVERFLOW event should cause pending events to be purged
Reviewed-by: chegar
上级
12d023bd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
137 addition
and
17 deletion
+137
-17
src/share/classes/sun/nio/fs/AbstractWatchKey.java
src/share/classes/sun/nio/fs/AbstractWatchKey.java
+15
-17
test/java/nio/file/WatchService/OverflowEventIsLoner.java
test/java/nio/file/WatchService/OverflowEventIsLoner.java
+122
-0
未找到文件。
src/share/classes/sun/nio/fs/AbstractWatchKey.java
浏览文件 @
7c4e4465
...
...
@@ -88,27 +88,25 @@ abstract class AbstractWatchKey extends WatchKey {
final
void
signalEvent
(
WatchEvent
.
Kind
<?>
kind
,
Object
context
)
{
synchronized
(
this
)
{
int
size
=
events
.
size
();
if
(
size
>
1
)
{
// don't let list get too big
if
(
size
>
0
)
{
// if the previous event is an OVERFLOW event or this is a
// repeated event then we simply increment the counter
WatchEvent
<?>
prev
=
events
.
get
(
size
-
1
);
if
((
prev
.
kind
()
==
StandardWatchEventKind
.
OVERFLOW
)
||
((
kind
==
prev
.
kind
()
&&
Objects
.
equals
(
context
,
prev
.
context
()))))
{
((
Event
<?>)
prev
).
increment
();
return
;
}
// if the list has reached the limit then drop pending events
// and queue an OVERFLOW event
if
(
size
>=
MAX_EVENT_LIST_SIZE
)
{
events
.
clear
();
kind
=
StandardWatchEventKind
.
OVERFLOW
;
context
=
null
;
}
// repeated event
WatchEvent
<?>
prev
=
events
.
get
(
size
-
1
);
if
(
kind
==
prev
.
kind
())
{
boolean
isRepeat
;
if
(
context
==
null
)
{
isRepeat
=
(
prev
.
context
()
==
null
);
}
else
{
isRepeat
=
context
.
equals
(
prev
.
context
());
}
if
(
isRepeat
)
{
((
Event
<?>)
prev
).
increment
();
return
;
}
}
}
// non-repeated event
...
...
test/java/nio/file/WatchService/OverflowEventIsLoner.java
0 → 100644
浏览文件 @
7c4e4465
/*
* Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
* @bug 6907760
* @summary Check that the OVERFLOW event is not retrieved with other events
* @library ..
*/
import
java.nio.file.*
;
import
static
java
.
nio
.
file
.
StandardWatchEventKind
.*;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
public
class
OverflowEventIsLoner
{
static
void
drainEvents
(
WatchService
watcher
,
WatchEvent
.
Kind
<?>
expectedKind
,
int
count
)
throws
IOException
,
InterruptedException
{
// wait for key to be signalled - the timeout is long to allow for
// polling implementations
WatchKey
key
=
watcher
.
poll
(
15
,
TimeUnit
.
SECONDS
);
if
(
key
!=
null
&&
count
==
0
)
throw
new
RuntimeException
(
"Key was signalled (unexpected)"
);
if
(
key
==
null
&&
count
>
0
)
throw
new
RuntimeException
(
"Key not signalled (unexpected)"
);
int
nread
=
0
;
boolean
gotOverflow
=
false
;
do
{
List
<
WatchEvent
<?>>
events
=
key
.
pollEvents
();
for
(
WatchEvent
<?>
event:
events
)
{
WatchEvent
.
Kind
<?>
kind
=
event
.
kind
();
if
(
kind
==
expectedKind
)
{
// expected event kind
if
(++
nread
>
count
)
throw
new
RuntimeException
(
"More events than expected!!"
);
}
else
if
(
kind
==
OVERFLOW
)
{
// overflow event should not be retrieved with other events
if
(
events
.
size
()
>
1
)
throw
new
RuntimeException
(
"Overflow retrieved with other events"
);
gotOverflow
=
true
;
}
else
{
throw
new
RuntimeException
(
"Unexpected event '"
+
kind
+
"'"
);
}
}
if
(!
key
.
reset
())
throw
new
RuntimeException
(
"Key is no longer valid"
);
key
=
watcher
.
poll
(
2
,
TimeUnit
.
SECONDS
);
}
while
(
key
!=
null
);
// check that all expected events were received or there was an overflow
if
(
nread
<
count
&&
!
gotOverflow
)
throw
new
RuntimeException
(
"Insufficient events"
);
}
static
void
test
(
Path
dir
)
throws
IOException
,
InterruptedException
{
WatchService
watcher
=
dir
.
getFileSystem
().
newWatchService
();
try
{
WatchKey
key
=
dir
.
register
(
watcher
,
ENTRY_CREATE
,
ENTRY_DELETE
);
// create a lot of files
int
n
=
1024
;
Path
[]
files
=
new
Path
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
files
[
i
]
=
dir
.
resolve
(
"foo"
+
i
).
createFile
();
}
// give time for events to accumulate (improve chance of overflow)
Thread
.
sleep
(
1000
);
// check that we see the create events (or overflow)
drainEvents
(
watcher
,
ENTRY_CREATE
,
n
);
// delete the files
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
files
[
i
].
delete
();
}
// give time for events to accumulate (improve chance of overflow)
Thread
.
sleep
(
1000
);
// check that we see the delete events (or overflow)
drainEvents
(
watcher
,
ENTRY_DELETE
,
n
);
}
finally
{
watcher
.
close
();
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Path
dir
=
TestUtil
.
createTemporaryDirectory
();
try
{
test
(
dir
);
}
finally
{
TestUtil
.
removeAll
(
dir
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录