Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Yuta HIGUCHI
2014-11-05 14:31:20 -0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
47eb0d48e2967f959d799c2d2fb01e8f0681373d
47eb0d48
1 parent
9ed96d9a
Factory methods for WriteRequest
Change-Id: If6fae76bd09b3068a8fb60ce27b7cde64cd8dc86
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
10 deletions
core/store/dist/src/main/java/org/onlab/onos/store/service/WriteRequest.java
core/store/dist/src/main/java/org/onlab/onos/store/service/WriteRequest.java
View file @
47eb0d4
...
...
@@ -17,24 +17,59 @@ public class WriteRequest {
private
final
long
previousVersion
;
private
final
byte
[]
oldValue
;
// put regardless of previous value
public
WriteRequest
(
String
tableName
,
String
key
,
byte
[]
newValue
)
{
this
(
tableName
,
key
,
newValue
,
-
1
,
null
);
/**
* Creates a write request, which will
* put the specified value to the table regardless of the previous value.
*
* @param tableName name of the table
* @param key key in the table
* @param newValue value to write
* @return WriteRequest
*/
public
static
WriteRequest
put
(
String
tableName
,
String
key
,
byte
[]
newValue
)
{
return
new
WriteRequest
(
tableName
,
key
,
newValue
,
-
1
,
null
);
}
// put if version matches
public
WriteRequest
(
String
tableName
,
String
key
,
byte
[]
newValue
,
long
previousVersion
)
{
this
(
tableName
,
key
,
newValue
,
previousVersion
,
null
);
// FIXME: Is there a special version value to realize putIfAbsent?
/**
* Creates a write request, which will
* put the specified value to the table if the previous version matches.
*
* @param tableName name of the table
* @param key key in the table
* @param newValue value to write
* @param previousVersion previous version expected
* @return WriteRequest
*/
public
static
WriteRequest
putIfVersionMatches
(
String
tableName
,
String
key
,
byte
[]
newValue
,
long
previousVersion
)
{
checkArgument
(
previousVersion
>=
0
);
return
new
WriteRequest
(
tableName
,
key
,
newValue
,
previousVersion
,
null
);
}
// put if value matches
public
WriteRequest
(
String
tableName
,
String
key
,
byte
[]
newValue
,
byte
[]
oldValue
)
{
this
(
tableName
,
key
,
newValue
,
-
1
,
oldValue
);
// FIXME: What is the behavior of oldValue=null? putIfAbsent?
/**
* Creates a write request, which will
* put the specified value to the table if the previous value matches.
*
* @param tableName name of the table
* @param key key in the table
* @param newValue value to write
* @param oldValue previous value expected
* @return WriteRequest
*/
public
static
WriteRequest
putIfValueMatches
(
String
tableName
,
String
key
,
byte
[]
newValue
,
byte
[]
oldValue
)
{
return
new
WriteRequest
(
tableName
,
key
,
newValue
,
-
1
,
oldValue
);
}
// FIXME: How do we remove value? newValue=null?
// hidden constructor
pr
ivate
WriteRequest
(
String
tableName
,
String
key
,
byte
[]
newValue
,
long
previousVersion
,
byte
[]
oldValue
)
{
pr
otected
WriteRequest
(
String
tableName
,
String
key
,
byte
[]
newValue
,
long
previousVersion
,
byte
[]
oldValue
)
{
checkArgument
(
tableName
!=
null
);
checkArgument
(
key
!=
null
);
...
...
Please
register
or
login
to post a comment