Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c937b4b4
提交
c937b4b4
authored
7月 13, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prepare release
上级
e8c85730
全部展开
显示空白字符变更
内嵌
并排
正在显示
19 个修改的文件
包含
1041 行增加
和
868 行删除
+1041
-868
changelog.html
h2/src/docsrc/html/changelog.html
+8
-4
_docs_en.utf8.txt
h2/src/docsrc/text/_docs_en.utf8.txt
+278
-269
_docs_ja.utf8.txt
h2/src/docsrc/text/_docs_ja.utf8.txt
+294
-285
_docs_en.properties
h2/src/docsrc/textbase/_docs_en.properties
+272
-269
Constants.java
h2/src/main/org/h2/engine/Constants.java
+2
-2
Chunk.java
h2/src/main/org/h2/mvstore/Chunk.java
+1
-1
ConcurrentLinkedList.java
h2/src/main/org/h2/mvstore/ConcurrentLinkedList.java
+46
-8
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+8
-3
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+1
-1
Page.java
h2/src/main/org/h2/mvstore/Page.java
+8
-0
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+8
-4
RegularTable.java
h2/src/main/org/h2/table/RegularTable.java
+7
-3
newsfeed.sql
h2/src/test/org/h2/samples/newsfeed.sql
+1
-0
TestCluster.java
h2/src/test/org/h2/test/db/TestCluster.java
+3
-3
TestConcurrentLinkedList.java
h2/src/test/org/h2/test/store/TestConcurrentLinkedList.java
+4
-4
TestMVStoreTool.java
h2/src/test/org/h2/test/store/TestMVStoreTool.java
+2
-2
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
ConcurrentLinkedListWithTail.java
...c/tools/org/h2/dev/util/ConcurrentLinkedListWithTail.java
+43
-4
ConcurrentRing.java
h2/src/tools/org/h2/dev/util/ConcurrentRing.java
+54
-5
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
c937b4b4
...
@@ -17,6 +17,10 @@ Change Log
...
@@ -17,6 +17,10 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
-
</li></ul>
<h2>
Version 1.4.180 Beta (2014-07-13)
</h2>
<ul><li>
MVStore: the store is now auto-compacted automatically up to some point,
<ul><li>
MVStore: the store is now auto-compacted automatically up to some point,
to avoid very large file sizes. This area is still work in progress.
to avoid very large file sizes. This area is still work in progress.
</li><li>
Sequences of temporary tables (auto-increment or identity columns)
</li><li>
Sequences of temporary tables (auto-increment or identity columns)
...
@@ -27,11 +31,11 @@ Change Log
...
@@ -27,11 +31,11 @@ Change Log
</li><li>
The LIRS cache now re-sizes the internal hash map if needed.
</li><li>
The LIRS cache now re-sizes the internal hash map if needed.
</li><li>
Optionally persist session history in the H2 console. (patch from Martin Grajcar)
</li><li>
Optionally persist session history in the H2 console. (patch from Martin Grajcar)
</li><li>
Add client-info property to get the number of servers currently in the cluster
</li><li>
Add client-info property to get the number of servers currently in the cluster
and which servers that are available. (patch from Nikolaj Fogh)
and which servers that are available. (patch from Nikolaj Fogh)
</li><li>
Fix bug in changing encrypted DB password that kept the file handle
</li><li>
Fix bug in changing encrypted DB password that kept the file handle
open when the wrong password was supplied. (test case from Jens Hohmuth).
open when the wrong password was supplied. (test case from Jens Hohmuth).
</li><li>
Issue 567:
h
2 hangs for a long time then (sometimes) recovers.
</li><li>
Issue 567:
H
2 hangs for a long time then (sometimes) recovers.
Introduce a queue when doing table locking to prevent session starvation.
Introduce a queue when doing table locking to prevent session starvation.
</li></ul>
</li></ul>
<h2>
Version 1.4.179 Beta (2014-06-23)
</h2>
<h2>
Version 1.4.179 Beta (2014-06-23)
</h2>
...
...
h2/src/docsrc/text/_docs_en.utf8.txt
浏览文件 @
c937b4b4
差异被折叠。
点击展开。
h2/src/docsrc/text/_docs_ja.utf8.txt
浏览文件 @
c937b4b4
差异被折叠。
点击展开。
h2/src/docsrc/textbase/_docs_en.properties
浏览文件 @
c937b4b4
差异被折叠。
点击展开。
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
c937b4b4
...
@@ -16,7 +16,7 @@ public class Constants {
...
@@ -16,7 +16,7 @@ public class Constants {
/**
/**
* The build date is updated for each public release.
* The build date is updated for each public release.
*/
*/
public
static
final
String
BUILD_DATE
=
"2014-0
6-2
3"
;
public
static
final
String
BUILD_DATE
=
"2014-0
7-1
3"
;
/**
/**
* The build date of the last stable release.
* The build date of the last stable release.
...
@@ -26,7 +26,7 @@ public class Constants {
...
@@ -26,7 +26,7 @@ public class Constants {
/**
/**
* The build id is incremented for each public release.
* The build id is incremented for each public release.
*/
*/
public
static
final
int
BUILD_ID
=
1
79
;
public
static
final
int
BUILD_ID
=
1
80
;
/**
/**
* The build id of the last stable release.
* The build id of the last stable release.
...
...
h2/src/main/org/h2/mvstore/Chunk.java
浏览文件 @
c937b4b4
h2/src/main/org/h2/mvstore/ConcurrentLinkedList.java
浏览文件 @
c937b4b4
...
@@ -17,16 +17,32 @@ import java.util.Iterator;
...
@@ -17,16 +17,32 @@ import java.util.Iterator;
*/
*/
public
class
ConcurrentLinkedList
<
K
>
{
public
class
ConcurrentLinkedList
<
K
>
{
/**
* The sentinel entry.
*/
static
final
Entry
<?>
NULL
=
new
Entry
<
Object
>(
null
,
null
);
static
final
Entry
<?>
NULL
=
new
Entry
<
Object
>(
null
,
null
);
/**
* The head entry.
*/
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
volatile
Entry
<
K
>
head
=
(
Entry
<
K
>)
NULL
;
volatile
Entry
<
K
>
head
=
(
Entry
<
K
>)
NULL
;
/**
* Get the first element, or null if none.
*
* @return the first element
*/
public
K
peekFirst
()
{
public
K
peekFirst
()
{
Entry
<
K
>
x
=
head
;
Entry
<
K
>
x
=
head
;
return
x
.
obj
;
return
x
.
obj
;
}
}
/**
* Get the last element, or null if none.
*
* @return the last element
*/
public
K
peekLast
()
{
public
K
peekLast
()
{
Entry
<
K
>
x
=
head
;
Entry
<
K
>
x
=
head
;
while
(
x
!=
NULL
&&
x
.
next
!=
NULL
)
{
while
(
x
!=
NULL
&&
x
.
next
!=
NULL
)
{
...
@@ -35,10 +51,21 @@ public class ConcurrentLinkedList<K> {
...
@@ -35,10 +51,21 @@ public class ConcurrentLinkedList<K> {
return
x
.
obj
;
return
x
.
obj
;
}
}
/**
* Add an element at the end.
*
* @param obj the element
*/
public
synchronized
void
add
(
K
obj
)
{
public
synchronized
void
add
(
K
obj
)
{
head
=
Entry
.
append
(
head
,
obj
);
head
=
Entry
.
append
(
head
,
obj
);
}
}
/**
* Remove the first element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
synchronized
boolean
removeFirst
(
K
obj
)
{
public
synchronized
boolean
removeFirst
(
K
obj
)
{
if
(
head
.
obj
!=
obj
)
{
if
(
head
.
obj
!=
obj
)
{
return
false
;
return
false
;
...
@@ -47,6 +74,12 @@ public class ConcurrentLinkedList<K> {
...
@@ -47,6 +74,12 @@ public class ConcurrentLinkedList<K> {
return
true
;
return
true
;
}
}
/**
* Remove the last element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
synchronized
boolean
removeLast
(
K
obj
)
{
public
synchronized
boolean
removeLast
(
K
obj
)
{
if
(
peekLast
()
!=
obj
)
{
if
(
peekLast
()
!=
obj
)
{
return
false
;
return
false
;
...
@@ -55,6 +88,11 @@ public class ConcurrentLinkedList<K> {
...
@@ -55,6 +88,11 @@ public class ConcurrentLinkedList<K> {
return
true
;
return
true
;
}
}
/**
* Get an iterator over all entries.
*
* @return the iterator
*/
public
Iterator
<
K
>
iterator
()
{
public
Iterator
<
K
>
iterator
()
{
return
new
Iterator
<
K
>()
{
return
new
Iterator
<
K
>()
{
...
...
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
c937b4b4
...
@@ -1251,6 +1251,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -1251,6 +1251,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
this
.
writeVersion
=
writeVersion
;
this
.
writeVersion
=
writeVersion
;
}
}
/**
* Copy a map. All pages are copied.
*
* @param sourceMap the source map
*/
void
copyFrom
(
MVMap
<
K
,
V
>
sourceMap
)
{
void
copyFrom
(
MVMap
<
K
,
V
>
sourceMap
)
{
;
// TODO work in progress
;
// TODO work in progress
root
=
copy
(
sourceMap
.
root
,
null
);
root
=
copy
(
sourceMap
.
root
,
null
);
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
c937b4b4
h2/src/main/org/h2/mvstore/Page.java
浏览文件 @
c937b4b4
...
@@ -164,6 +164,14 @@ public class Page {
...
@@ -164,6 +164,14 @@ public class Page {
return
p
;
return
p
;
}
}
/**
* Create a copy of a page.
*
* @param map the map
* @param version the version
* @param source the source page
* @return the page
*/
public
static
Page
create
(
MVMap
<?,
?>
map
,
long
version
,
Page
source
)
{
public
static
Page
create
(
MVMap
<?,
?>
map
,
long
version
,
Page
source
)
{
Page
p
=
new
Page
(
map
,
version
);
Page
p
=
new
Page
(
map
,
version
);
// the position is 0
// the position is 0
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
c937b4b4
...
@@ -52,8 +52,10 @@ public class MVTable extends TableBase {
...
@@ -52,8 +52,10 @@ public class MVTable extends TableBase {
private
long
lastModificationId
;
private
long
lastModificationId
;
private
volatile
Session
lockExclusiveSession
;
private
volatile
Session
lockExclusiveSession
;
private
final
HashSet
<
Session
>
lockSharedSessions
=
New
.
hashSet
();
private
final
HashSet
<
Session
>
lockSharedSessions
=
New
.
hashSet
();
/**
/**
* FIFO queue to prevent starvation, since Java's synchronized locking is biased.
* The queue of sessions waiting to lock the table. It is a FIFO queue to
* prevent starvation, since Java's synchronized locking is biased.
*/
*/
private
final
ArrayDeque
<
Session
>
waitingSessions
=
new
ArrayDeque
<
Session
>();
private
final
ArrayDeque
<
Session
>
waitingSessions
=
new
ArrayDeque
<
Session
>();
private
final
Trace
traceLock
;
private
final
Trace
traceLock
;
...
@@ -96,7 +98,8 @@ public class MVTable extends TableBase {
...
@@ -96,7 +98,8 @@ public class MVTable extends TableBase {
}
}
@Override
@Override
public
void
lock
(
Session
session
,
boolean
exclusive
,
boolean
forceLockEvenInMvcc
)
{
public
void
lock
(
Session
session
,
boolean
exclusive
,
boolean
forceLockEvenInMvcc
)
{
int
lockMode
=
database
.
getLockMode
();
int
lockMode
=
database
.
getLockMode
();
if
(
lockMode
==
Constants
.
LOCK_MODE_OFF
)
{
if
(
lockMode
==
Constants
.
LOCK_MODE_OFF
)
{
return
;
return
;
...
@@ -196,7 +199,8 @@ public class MVTable extends TableBase {
...
@@ -196,7 +199,8 @@ public class MVTable extends TableBase {
session
.
addLock
(
this
);
session
.
addLock
(
this
);
lockExclusiveSession
=
session
;
lockExclusiveSession
=
session
;
return
true
;
return
true
;
}
else
if
(
lockSharedSessions
.
size
()
==
1
&&
lockSharedSessions
.
contains
(
session
))
{
}
else
if
(
lockSharedSessions
.
size
()
==
1
&&
lockSharedSessions
.
contains
(
session
))
{
traceLock
(
session
,
exclusive
,
"add (upgraded) for "
);
traceLock
(
session
,
exclusive
,
"add (upgraded) for "
);
lockExclusiveSession
=
session
;
lockExclusiveSession
=
session
;
return
true
;
return
true
;
...
...
h2/src/main/org/h2/table/RegularTable.java
浏览文件 @
c937b4b4
...
@@ -55,8 +55,10 @@ public class RegularTable extends TableBase {
...
@@ -55,8 +55,10 @@ public class RegularTable extends TableBase {
private
long
rowCount
;
private
long
rowCount
;
private
volatile
Session
lockExclusiveSession
;
private
volatile
Session
lockExclusiveSession
;
private
HashSet
<
Session
>
lockSharedSessions
=
New
.
hashSet
();
private
HashSet
<
Session
>
lockSharedSessions
=
New
.
hashSet
();
/**
/**
* FIFO queue to prevent starvation, since Java's synchronized locking is biased.
* The queue of sessions waiting to lock the table. It is a FIFO queue to
* prevent starvation, since Java's synchronized locking is biased.
*/
*/
private
final
ArrayDeque
<
Session
>
waitingSessions
=
new
ArrayDeque
<
Session
>();
private
final
ArrayDeque
<
Session
>
waitingSessions
=
new
ArrayDeque
<
Session
>();
private
final
Trace
traceLock
;
private
final
Trace
traceLock
;
...
@@ -437,7 +439,8 @@ public class RegularTable extends TableBase {
...
@@ -437,7 +439,8 @@ public class RegularTable extends TableBase {
}
}
@Override
@Override
public
void
lock
(
Session
session
,
boolean
exclusive
,
boolean
forceLockEvenInMvcc
)
{
public
void
lock
(
Session
session
,
boolean
exclusive
,
boolean
forceLockEvenInMvcc
)
{
int
lockMode
=
database
.
getLockMode
();
int
lockMode
=
database
.
getLockMode
();
if
(
lockMode
==
Constants
.
LOCK_MODE_OFF
)
{
if
(
lockMode
==
Constants
.
LOCK_MODE_OFF
)
{
return
;
return
;
...
@@ -532,7 +535,8 @@ public class RegularTable extends TableBase {
...
@@ -532,7 +535,8 @@ public class RegularTable extends TableBase {
session
.
addLock
(
this
);
session
.
addLock
(
this
);
lockExclusiveSession
=
session
;
lockExclusiveSession
=
session
;
return
true
;
return
true
;
}
else
if
(
lockSharedSessions
.
size
()
==
1
&&
lockSharedSessions
.
contains
(
session
))
{
}
else
if
(
lockSharedSessions
.
size
()
==
1
&&
lockSharedSessions
.
contains
(
session
))
{
traceLock
(
session
,
exclusive
,
"add (upgraded) for "
);
traceLock
(
session
,
exclusive
,
"add (upgraded) for "
);
lockExclusiveSession
=
session
;
lockExclusiveSession
=
session
;
return
true
;
return
true
;
...
...
h2/src/test/org/h2/samples/newsfeed.sql
浏览文件 @
c937b4b4
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
CREATE
TABLE
VERSION
(
ID
INT
PRIMARY
KEY
,
VERSION
VARCHAR
,
CREATED
VARCHAR
);
CREATE
TABLE
VERSION
(
ID
INT
PRIMARY
KEY
,
VERSION
VARCHAR
,
CREATED
VARCHAR
);
INSERT
INTO
VERSION
VALUES
INSERT
INTO
VERSION
VALUES
(
130
,
'1.4.180'
,
'2014-07-13'
),
(
129
,
'1.4.179'
,
'2014-06-23'
),
(
129
,
'1.4.179'
,
'2014-06-23'
),
(
128
,
'1.4.178'
,
'2014-05-02'
),
(
128
,
'1.4.178'
,
'2014-05-02'
),
(
127
,
'1.4.177'
,
'2014-04-12'
),
(
127
,
'1.4.177'
,
'2014-04-12'
),
...
...
h2/src/test/org/h2/test/db/TestCluster.java
浏览文件 @
c937b4b4
h2/src/test/org/h2/test/store/TestConcurrentLinkedList.java
浏览文件 @
c937b4b4
h2/src/test/org/h2/test/store/TestMVStoreTool.java
浏览文件 @
c937b4b4
...
@@ -32,7 +32,8 @@ public class TestMVStoreTool extends TestBase {
...
@@ -32,7 +32,8 @@ public class TestMVStoreTool extends TestBase {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testCompress
();
;
// TODO work in progress
// testCompress();
}
}
private
void
testCompress
()
{
private
void
testCompress
()
{
...
@@ -51,7 +52,6 @@ public class TestMVStoreTool extends TestBase {
...
@@ -51,7 +52,6 @@ public class TestMVStoreTool extends TestBase {
}
}
}
}
s
.
close
();
s
.
close
();
;
// TODO testing
// MVStoreTool.dump(fileName);
// MVStoreTool.dump(fileName);
// MVStoreTool.dump(fileName + ".new");
// MVStoreTool.dump(fileName + ".new");
MVStoreTool
.
compress
(
fileName
,
fileName
+
".new"
);
MVStoreTool
.
compress
(
fileName
,
fileName
+
".new"
);
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
c937b4b4
...
@@ -760,4 +760,4 @@ inaccuracies detector logos launcher rewrite monitors equivalents trademarks
...
@@ -760,4 +760,4 @@ inaccuracies detector logos launcher rewrite monitors equivalents trademarks
reinstated uninteresting dead defendant doctrines beat factual fair suspended
reinstated uninteresting dead defendant doctrines beat factual fair suspended
exploit noise ongoing disclaimers shrinks remedy party desirable timely construe
exploit noise ongoing disclaimers shrinks remedy party desirable timely construe
deque synchronizers affero kevent nikolaj hohmuth grajcar jens fogh hostnames
deque synchronizers affero kevent nikolaj hohmuth grajcar jens fogh hostnames
operate resized
operate resized
jni yjp ownable starvation reaper biased introduce epoll hangs
h2/src/tools/org/h2/dev/util/ConcurrentLinkedListWithTail.java
浏览文件 @
c937b4b4
...
@@ -16,19 +16,41 @@ import org.h2.mvstore.DataUtils;
...
@@ -16,19 +16,41 @@ import org.h2.mvstore.DataUtils;
*/
*/
public
class
ConcurrentLinkedListWithTail
<
K
>
{
public
class
ConcurrentLinkedListWithTail
<
K
>
{
/**
* The first entry (if any).
*/
volatile
Entry
<
K
>
head
;
volatile
Entry
<
K
>
head
;
/**
* The last entry (if any).
*/
private
volatile
Entry
<
K
>
tail
;
private
volatile
Entry
<
K
>
tail
;
/**
* Get the first element, or null if none.
*
* @return the first element
*/
public
K
peekFirst
()
{
public
K
peekFirst
()
{
Entry
<
K
>
x
=
head
;
Entry
<
K
>
x
=
head
;
return
x
==
null
?
null
:
x
.
obj
;
return
x
==
null
?
null
:
x
.
obj
;
}
}
/**
* Get the last element, or null if none.
*
* @return the last element
*/
public
K
peekLast
()
{
public
K
peekLast
()
{
Entry
<
K
>
x
=
tail
;
Entry
<
K
>
x
=
tail
;
return
x
==
null
?
null
:
x
.
obj
;
return
x
==
null
?
null
:
x
.
obj
;
}
}
/**
* Add an element at the end.
*
* @param obj the element
*/
public
void
add
(
K
obj
)
{
public
void
add
(
K
obj
)
{
Entry
<
K
>
x
=
new
Entry
<
K
>(
obj
);
Entry
<
K
>
x
=
new
Entry
<
K
>(
obj
);
Entry
<
K
>
t
=
tail
;
Entry
<
K
>
t
=
tail
;
...
@@ -41,6 +63,12 @@ public class ConcurrentLinkedListWithTail<K> {
...
@@ -41,6 +63,12 @@ public class ConcurrentLinkedListWithTail<K> {
}
}
}
}
/**
* Remove the first element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
boolean
removeFirst
(
K
obj
)
{
public
boolean
removeFirst
(
K
obj
)
{
Entry
<
K
>
x
=
head
;
Entry
<
K
>
x
=
head
;
if
(
x
==
null
||
x
.
obj
!=
obj
)
{
if
(
x
==
null
||
x
.
obj
!=
obj
)
{
...
@@ -53,6 +81,12 @@ public class ConcurrentLinkedListWithTail<K> {
...
@@ -53,6 +81,12 @@ public class ConcurrentLinkedListWithTail<K> {
return
true
;
return
true
;
}
}
/**
* Remove the last element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
boolean
removeLast
(
K
obj
)
{
public
boolean
removeLast
(
K
obj
)
{
Entry
<
K
>
x
=
head
;
Entry
<
K
>
x
=
head
;
if
(
x
==
null
)
{
if
(
x
==
null
)
{
...
@@ -76,6 +110,11 @@ public class ConcurrentLinkedListWithTail<K> {
...
@@ -76,6 +110,11 @@ public class ConcurrentLinkedListWithTail<K> {
return
true
;
return
true
;
}
}
/**
* Get an iterator over all entries.
*
* @return the iterator
*/
public
Iterator
<
K
>
iterator
()
{
public
Iterator
<
K
>
iterator
()
{
return
new
Iterator
<
K
>()
{
return
new
Iterator
<
K
>()
{
...
...
h2/src/tools/org/h2/dev/util/ConcurrentRing.java
浏览文件 @
c937b4b4
...
@@ -16,8 +16,19 @@ import org.h2.mvstore.DataUtils;
...
@@ -16,8 +16,19 @@ import org.h2.mvstore.DataUtils;
*/
*/
public
class
ConcurrentRing
<
K
>
{
public
class
ConcurrentRing
<
K
>
{
/**
* The ring buffer.
*/
K
[]
buffer
;
K
[]
buffer
;
/**
* The read position.
*/
volatile
int
readPos
;
volatile
int
readPos
;
/**
* The write position.
*/
volatile
int
writePos
;
volatile
int
writePos
;
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
@@ -25,14 +36,29 @@ public class ConcurrentRing<K> {
...
@@ -25,14 +36,29 @@ public class ConcurrentRing<K> {
buffer
=
(
K
[])
new
Object
[
4
];
buffer
=
(
K
[])
new
Object
[
4
];
}
}
/**
* Get the first element, or null if none.
*
* @return the first element
*/
public
K
peekFirst
()
{
public
K
peekFirst
()
{
return
buffer
[
getIndex
(
readPos
)];
return
buffer
[
getIndex
(
readPos
)];
}
}
/**
* Get the last element, or null if none.
*
* @return the last element
*/
public
K
peekLast
()
{
public
K
peekLast
()
{
return
buffer
[
getIndex
(
writePos
-
1
)];
return
buffer
[
getIndex
(
writePos
-
1
)];
}
}
/**
* Add an element at the end.
*
* @param obj the element
*/
public
void
add
(
K
obj
)
{
public
void
add
(
K
obj
)
{
buffer
[
getIndex
(
writePos
)]
=
obj
;
buffer
[
getIndex
(
writePos
)]
=
obj
;
writePos
++;
writePos
++;
...
@@ -49,6 +75,12 @@ public class ConcurrentRing<K> {
...
@@ -49,6 +75,12 @@ public class ConcurrentRing<K> {
}
}
}
}
/**
* Remove the first element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
boolean
removeFirst
(
K
obj
)
{
public
boolean
removeFirst
(
K
obj
)
{
int
p
=
readPos
;
int
p
=
readPos
;
int
idx
=
getIndex
(
p
);
int
idx
=
getIndex
(
p
);
...
@@ -60,6 +92,12 @@ public class ConcurrentRing<K> {
...
@@ -60,6 +92,12 @@ public class ConcurrentRing<K> {
return
true
;
return
true
;
}
}
/**
* Remove the last element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
boolean
removeLast
(
K
obj
)
{
public
boolean
removeLast
(
K
obj
)
{
int
p
=
writePos
;
int
p
=
writePos
;
int
idx
=
getIndex
(
p
-
1
);
int
idx
=
getIndex
(
p
-
1
);
...
@@ -71,10 +109,21 @@ public class ConcurrentRing<K> {
...
@@ -71,10 +109,21 @@ public class ConcurrentRing<K> {
return
true
;
return
true
;
}
}
/**
* Get the index in the array of the given position.
*
* @param pos the position
* @return the index
*/
int
getIndex
(
int
pos
)
{
int
getIndex
(
int
pos
)
{
return
pos
&
(
buffer
.
length
-
1
);
return
pos
&
(
buffer
.
length
-
1
);
}
}
/**
* Get an iterator over all entries.
*
* @return the iterator
*/
public
Iterator
<
K
>
iterator
()
{
public
Iterator
<
K
>
iterator
()
{
return
new
Iterator
<
K
>()
{
return
new
Iterator
<
K
>()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论