Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JDChain
Bftsmart
提交
31ceb8fe
B
Bftsmart
项目概览
JDChain
/
Bftsmart
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Bftsmart
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
31ceb8fe
编写于
5月 16, 2011
作者:
B
bessani@gmail.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
No commit message
No commit message
上级
85e5cf24
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
111 addition
and
807 deletion
+111
-807
src/navigators/smart/tom/demo/BFTMAPUtil.java
src/navigators/smart/tom/demo/BFTMAPUtil.java
+0
-102
src/navigators/smart/tom/demo/BFTMap.java
src/navigators/smart/tom/demo/BFTMap.java
+0
-266
src/navigators/smart/tom/demo/BFTMapImpl.java
src/navigators/smart/tom/demo/BFTMapImpl.java
+0
-212
src/navigators/smart/tom/demo/CounterServer.java
src/navigators/smart/tom/demo/CounterServer.java
+2
-2
src/navigators/smart/tom/demo/KVClient.java
src/navigators/smart/tom/demo/KVClient.java
+0
-200
src/navigators/smart/tom/demo/KVServer.java
src/navigators/smart/tom/demo/KVServer.java
+0
-24
src/navigators/smart/tom/demo/RWCounterClient.java
src/navigators/smart/tom/demo/RWCounterClient.java
+108
-0
src/navigators/smart/tom/demo/RandomServer.java
src/navigators/smart/tom/demo/RandomServer.java
+1
-1
未找到文件。
src/navigators/smart/tom/demo/BFTMAPUtil.java
已删除
100644 → 0
浏览文件 @
85e5cf24
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
navigators.smart.tom.demo
;
import
java.util.HashMap
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.util.Scanner
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
navigators.smart.tom.ServiceProxy
;
import
java.io.Console
;
import
java.io.Serializable
;
/**
*
* @author sweta
*/
public
class
BFTMAPUtil
implements
Serializable
{
static
final
int
TAB_CREATE
=
1
;
static
final
int
TAB_REMOVE
=
2
;
static
final
int
SIZE_TABLE
=
3
;
static
final
int
TAB_CREATE_CHECK
=
10
;
static
final
int
PUT
=
4
;
static
final
int
GET
=
5
;
static
final
int
SIZE
=
6
;
static
final
int
REMOVE
=
7
;
static
final
int
CHECK
=
8
;
static
final
int
GET_TABLE
=
9
;
//private HashMap<String,byte[]> info = null;
private
HashMap
<
String
,
HashMap
<
String
,
byte
[]>>
info1
=
null
;
//private HashMap<String,byte[]> info = null;
public
BFTMAPUtil
()
{
info1
=
new
HashMap
<
String
,
HashMap
<
String
,
byte
[]>>();
}
public
HashMap
<
String
,
byte
[]>
addTable
(
String
key
,
HashMap
data
)
{
return
info1
.
put
(
key
,
data
);
}
public
byte
[]
addData
(
String
tableName
,
String
key
,
byte
[]
value
)
{
System
.
out
.
println
(
"Table name"
+
tableName
);
System
.
out
.
println
(
"Table id"
+
key
);
System
.
out
.
println
(
"Value"
+
new
String
(
value
));
HashMap
<
String
,
byte
[]>
info
=
info1
.
get
(
tableName
);
if
(
info
==
null
)
System
.
out
.
println
(
"This is null"
);
System
.
out
.
println
(
"Table"
+
info
);
byte
[]
ret
=
info
.
put
(
key
,
value
);
// byte[] ret = info.get(key);
// System.out.println("Value"+ new String(ret));
return
ret
;
}
public
HashMap
<
String
,
byte
[]>
getName
(
String
id
)
{
return
info1
.
get
(
id
);
}
public
byte
[]
getEntry
(
String
tableName
,
String
id
)
{
System
.
out
.
println
(
"Table name"
+
tableName
);
System
.
out
.
println
(
"Table id"
+
id
);
HashMap
<
String
,
byte
[]>
info
=
info1
.
get
(
tableName
);
System
.
out
.
println
(
"Table"
+
info
);
return
info
.
get
(
id
);
}
public
int
getSizeofTable
()
{
return
info1
.
size
();
}
public
int
getSize
(
String
tableName
)
{
HashMap
<
String
,
byte
[]>
info
=
info1
.
get
(
tableName
);
return
info
.
size
();
}
public
HashMap
<
String
,
byte
[]>
removeTable
(
String
tableName
)
{
return
info1
.
remove
(
tableName
);
}
public
byte
[]
removeEntry
(
String
tableName
,
String
key
)
{
HashMap
<
String
,
byte
[]>
info
=
info1
.
get
(
tableName
);
return
info
.
remove
(
key
);
}
}
src/navigators/smart/tom/demo/BFTMap.java
已删除
100644 → 0
浏览文件 @
85e5cf24
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
navigators.smart.tom.demo
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Scanner
;
import
java.util.Set
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
navigators.smart.tom.ServiceProxy
;
import
java.io.Console
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
*
* @author sweta
*/
public
class
BFTMap
implements
Map
<
String
,
HashMap
<
String
,
byte
[]>>
{
BFTMAPUtil
bft
=
null
;
ServiceProxy
KVProxy
=
null
;
BFTMap
(
int
id
)
{
bft
=
new
BFTMAPUtil
();
KVProxy
=
new
ServiceProxy
(
id
);
}
ByteArrayOutputStream
out
=
null
;
public
HashMap
<
String
,
byte
[]>
get
(
String
tableName
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
GET
);
new
DataOutputStream
(
out
).
writeUTF
(
tableName
);
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
true
);
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
rep
)
;
ObjectInputStream
in
=
new
ObjectInputStream
(
bis
)
;
HashMap
<
String
,
byte
[]>
table
=
(
HashMap
<
String
,
byte
[]>)
in
.
readObject
();
in
.
close
();
return
table
;
}
catch
(
ClassNotFoundException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
}
public
byte
[]
getEntry
(
String
tableName
,
String
key
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
GET
);
new
DataOutputStream
(
out
).
writeUTF
(
tableName
);
new
DataOutputStream
(
out
).
writeUTF
(
key
);
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
true
);
return
rep
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
}
public
HashMap
<
String
,
byte
[]>
put
(
String
key
,
HashMap
<
String
,
byte
[]>
value
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
TAB_CREATE
);
new
DataOutputStream
(
out
).
writeUTF
(
key
);
//ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
ObjectOutputStream
out1
=
new
ObjectOutputStream
(
out
)
;
out1
.
writeObject
(
value
);
out1
.
close
();
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
true
);
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
rep
)
;
ObjectInputStream
in
=
new
ObjectInputStream
(
bis
)
;
HashMap
<
String
,
byte
[]>
table
=
(
HashMap
<
String
,
byte
[]>)
in
.
readObject
();
in
.
close
();
return
table
;
}
catch
(
ClassNotFoundException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
}
public
byte
[]
put1
(
String
tableName
,
String
key
,
byte
[]
value
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
PUT
);
new
DataOutputStream
(
out
).
writeUTF
(
tableName
);
new
DataOutputStream
(
out
).
writeUTF
(
key
);
new
DataOutputStream
(
out
).
writeUTF
(
new
String
(
value
));
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
true
);
return
rep
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
}
public
HashMap
<
String
,
byte
[]>
remove
(
Object
key
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
TAB_REMOVE
);
new
DataOutputStream
(
out
).
writeUTF
((
String
)
key
);
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
false
);
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
rep
)
;
ObjectInputStream
in
=
new
ObjectInputStream
(
bis
)
;
HashMap
<
String
,
byte
[]>
table
=
(
HashMap
<
String
,
byte
[]>)
in
.
readObject
();
in
.
close
();
return
table
;
}
catch
(
ClassNotFoundException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
}
public
byte
[]
removeEntry
(
String
tableName
,
String
key
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
REMOVE
);
new
DataOutputStream
(
out
).
writeUTF
((
String
)
tableName
);
new
DataOutputStream
(
out
).
writeUTF
((
String
)
key
);
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
false
);
return
rep
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
}
public
int
size
()
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
SIZE_TABLE
);
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
false
);
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
rep
);
int
size
=
new
DataInputStream
(
in
).
readInt
();
return
size
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
-
1
;
}
}
public
int
size1
(
String
tableName
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
SIZE
);
new
DataOutputStream
(
out
).
writeUTF
(
tableName
);
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
false
);
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
rep
);
int
size
=
new
DataInputStream
(
in
).
readInt
();
return
size
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
0
;
}
}
public
boolean
containsKey
(
String
key
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
TAB_CREATE_CHECK
);
new
DataOutputStream
(
out
).
writeUTF
((
String
)
key
);
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
true
);
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
rep
);
boolean
res
=
new
DataInputStream
(
in
).
readBoolean
();
return
res
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
false
;
}
}
public
boolean
containsKey1
(
String
tableName
,
String
key
)
{
try
{
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
BFTMAPUtil
.
CHECK
);
new
DataOutputStream
(
out
).
writeUTF
((
String
)
tableName
);
new
DataOutputStream
(
out
).
writeUTF
((
String
)
key
);
byte
[]
rep
=
KVProxy
.
invoke
(
out
.
toByteArray
(),
true
);
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
rep
);
boolean
res
=
new
DataInputStream
(
in
).
readBoolean
();
return
res
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMap
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
false
;
}
}
public
boolean
isEmpty
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
boolean
containsValue
(
Object
value
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
putAll
(
Map
m
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
clear
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
Set
keySet
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
Collection
values
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
Set
entrySet
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
boolean
containsKey
(
Object
key
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
HashMap
<
String
,
byte
[]>
get
(
Object
key
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
}
src/navigators/smart/tom/demo/BFTMapImpl.java
已删除
100644 → 0
浏览文件 @
85e5cf24
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
navigators.smart.tom.demo
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.ObjectInput
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutput
;
import
java.io.ObjectOutputStream
;
import
java.lang.String
;
import
java.util.HashMap
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
navigators.smart.tom.ServiceReplica
;
import
navigators.smart.tom.util.DebugInfo
;
/**
*
* @author sweta
*/
//This class extends ServiceReplica and overrides its functions serializeState(), deserializeState() and executeCommand().
public
class
BFTMapImpl
extends
ServiceReplica
{
//The constructor passes the id of the server to the super class
public
BFTMapImpl
(
int
id
)
{
super
(
id
);
}
HashMap
<
String
,
byte
[]>
info2
=
new
HashMap
<
String
,
byte
[]>();
BFTMAPUtil
bftReplica
=
new
BFTMAPUtil
();
@Override
protected
byte
[]
serializeState
()
{
try
{
//save to file (not needed for now)
ObjectOutput
out
=
new
ObjectOutputStream
(
new
FileOutputStream
(
"MyObject.ser"
));
out
.
writeObject
(
bftReplica
);
out
.
close
();
// serialize to byte array and return
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
()
;
out
=
new
ObjectOutputStream
(
bos
)
;
out
.
writeObject
(
bftReplica
);
out
.
close
();
return
bos
.
toByteArray
();
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMapImpl
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
new
byte
[
0
];
}
}
@Override
protected
void
deserializeState
(
byte
[]
state
)
{
try
{
//save to file (not needed for now)
ObjectInput
in
=
new
ObjectInputStream
(
new
FileInputStream
(
"MyObject.ser"
));
bftReplica
=
(
BFTMAPUtil
)
in
.
readObject
();
in
.
close
();
// serialize to byte array and return
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
state
)
;
in
=
new
ObjectInputStream
(
bis
)
;
bftReplica
=
(
BFTMAPUtil
)
in
.
readObject
();
in
.
close
();
}
catch
(
ClassNotFoundException
ex
)
{
Logger
.
getLogger
(
BFTMapImpl
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMapImpl
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
@Override
@SuppressWarnings
(
"static-access"
)
public
byte
[]
executeCommand
(
int
clientId
,
long
timestamp
,
byte
[]
nonces
,
byte
[]
command
,
DebugInfo
info
)
{
try
{
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
command
);
ByteArrayOutputStream
out
=
null
;
byte
[]
reply
=
null
;
int
cmd
=
new
DataInputStream
(
in
).
readInt
();
switch
(
cmd
)
{
//operations on the hashmap
case
BFTMAPUtil
.
PUT
:
String
tableName
=
new
DataInputStream
(
in
).
readUTF
();
String
key
=
new
DataInputStream
(
in
).
readUTF
();
String
value
=
new
DataInputStream
(
in
).
readUTF
();
byte
[]
b
=
value
.
getBytes
();
System
.
out
.
println
(
"Key received"
+
key
);
byte
[]
ret
=
bftReplica
.
addData
(
tableName
,
key
,
b
);
if
(
ret
==
null
)
{
System
.
out
.
println
(
"inside if"
);
ret
=
new
byte
[
0
];
}
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeBytes
(
new
String
(
ret
));
reply
=
out
.
toByteArray
();
break
;
case
BFTMAPUtil
.
GET
:
String
tableName1
=
new
DataInputStream
(
in
).
readUTF
();
System
.
out
.
println
(
"tablename"
+
tableName1
);
String
id1
=
new
DataInputStream
(
in
).
readUTF
();
System
.
out
.
println
(
"ID received"
+
id1
);
byte
[]
b1
=
bftReplica
.
getEntry
(
tableName1
,
id1
);
String
value1
=
new
String
(
b1
);
System
.
out
.
println
(
"The value to be get is"
+
value1
);
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeBytes
(
value1
);
reply
=
out
.
toByteArray
();
break
;
case
BFTMAPUtil
.
SIZE
:
String
tableName2
=
new
DataInputStream
(
in
).
readUTF
();
int
size
=
bftReplica
.
getSize
(
tableName2
);
System
.
out
.
println
(
"Size "
+
size
);
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
size
);
reply
=
out
.
toByteArray
();
break
;
case
BFTMAPUtil
.
SIZE_TABLE
:
int
size1
=
bftReplica
.
getSizeofTable
();
System
.
out
.
println
(
"Size "
+
size1
);
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeInt
(
size1
);
reply
=
out
.
toByteArray
();
break
;
case
BFTMAPUtil
.
REMOVE
:
String
tableName4
=
new
DataInputStream
(
in
).
readUTF
();
String
id2
=
new
DataInputStream
(
in
).
readUTF
();
System
.
out
.
println
(
"ID received"
+
id2
);
byte
[]
b2
=
bftReplica
.
removeEntry
(
tableName4
,
id2
);
String
value2
=
new
String
(
b2
);
System
.
out
.
println
(
"Value removed is : "
+
value2
);
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeBytes
(
value2
);
reply
=
out
.
toByteArray
();
break
;
case
BFTMAPUtil
.
TAB_CREATE_CHECK
:
String
id3
=
new
DataInputStream
(
in
).
readUTF
();
System
.
out
.
println
(
"Table of Table Key received"
+
id3
);
HashMap
<
String
,
byte
[]>
b3
=
bftReplica
.
getName
(
id3
);
boolean
tableExists
=
b3
!=
null
;
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeBoolean
(
tableExists
);
reply
=
out
.
toByteArray
();
break
;
case
BFTMAPUtil
.
CHECK
:
String
tableName7
=
new
DataInputStream
(
in
).
readUTF
();
String
id4
=
new
DataInputStream
(
in
).
readUTF
();
System
.
out
.
println
(
"Table Key received"
+
id4
);
byte
[]
b5
=
bftReplica
.
getEntry
(
tableName7
,
id4
);
boolean
tableExists1
=
b5
!=
null
;
out
=
new
ByteArrayOutputStream
();
new
DataOutputStream
(
out
).
writeBoolean
(
tableExists1
);
reply
=
out
.
toByteArray
();
break
;
case
BFTMAPUtil
.
TAB_CREATE
:
String
table4
=
new
DataInputStream
(
in
).
readUTF
();
//ByteArrayInputStream in1 = new ByteArrayInputStream(command);
ObjectInputStream
in2
=
new
ObjectInputStream
(
in
)
;
HashMap
<
String
,
byte
[]>
table
=
null
;
try
{
table
=
(
HashMap
<
String
,
byte
[]>)
in2
.
readObject
();
}
catch
(
ClassNotFoundException
ex
)
{
Logger
.
getLogger
(
BFTMapImpl
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
HashMap
<
String
,
byte
[]>
table1
=
bftReplica
.
addTable
(
table4
,
table
);
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
()
;
ObjectOutputStream
out1
=
new
ObjectOutputStream
(
bos
)
;
out1
.
writeObject
(
table1
);
out1
.
close
();
in
.
close
();
reply
=
bos
.
toByteArray
();
break
;
case
BFTMAPUtil
.
TAB_REMOVE
:
String
tableName3
=
new
DataInputStream
(
in
).
readUTF
();
HashMap
<
String
,
byte
[]>
info4
=
bftReplica
.
removeTable
(
tableName3
);
ByteArrayOutputStream
bos2
=
new
ByteArrayOutputStream
()
;
ObjectOutputStream
out3
=
new
ObjectOutputStream
(
bos2
)
;
out3
.
writeObject
(
info4
);
out3
.
close
();
out3
.
close
();
reply
=
bos2
.
toByteArray
();
break
;
}
return
reply
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BFTMapImpl
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
null
;
}
}
}
src/navigators/smart/tom/demo/CounterServer.java
浏览文件 @
31ceb8fe
...
...
@@ -51,13 +51,13 @@ public class CounterServer extends ServiceReplica {
@Override
public
byte
[]
executeCommand
(
int
clientId
,
long
timestamp
,
byte
[]
nonces
,
byte
[]
command
,
DebugInfo
info
)
{
public
byte
[]
executeCommand
(
int
clientId
,
long
timestamp
,
byte
[]
nonces
,
byte
[]
command
,
boolean
readOnly
,
DebugInfo
info
)
{
//System.out.println("Valor de counter execute "+this.counter);
iterations
++;
try
{
int
increment
=
new
DataInputStream
(
new
ByteArrayInputStream
(
command
)).
readInt
();
System
.
out
.
println
(
"read-only request: "
+
readOnly
);
counter
+=
increment
;
if
(
info
==
null
)
System
.
out
.
println
(
"[server] ("
+
iterations
+
") Counter incremented: "
+
counter
);
else
System
.
out
.
println
(
"[server] ("
+
iterations
+
" / "
+
info
.
eid
+
") Counter incremented: "
+
counter
);
...
...
src/navigators/smart/tom/demo/KVClient.java
已删除
100644 → 0
浏览文件 @
85e5cf24
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
navigators.smart.tom.demo
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.util.Scanner
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
navigators.smart.tom.ServiceProxy
;
import
java.io.Console
;
import
java.util.HashMap
;
import
java.io.ObjectInput
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutput
;
import
java.io.ObjectOutputStream
;
/**
*
* @author sweta
*/
public
class
KVClient
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
if
(
args
.
length
<
1
)
{
System
.
out
.
println
(
"Usage: java KVClient <process id> "
);
System
.
exit
(-
1
);
}
BFTMap
bftMap
=
new
BFTMap
(
Integer
.
parseInt
(
args
[
0
]));
Console
console
=
System
.
console
();
Scanner
sc
=
new
Scanner
(
System
.
in
);
boolean
res
=
false
;
ObjectOutput
out
=
null
;
while
(
true
)
{
System
.
out
.
println
(
"select a command : 1. CREATE A NEW TABLE OF TABLES"
);
System
.
out
.
println
(
"select a command : 2. REMOVE AN EXISTING TABLE OF TABLES"
);
System
.
out
.
println
(
"select a command : 3. GET THE SIZE OF THE TABLE OF TABLES"
);
System
.
out
.
println
(
"select a command : 4. PUT VALUES INTO A TABLE"
);
System
.
out
.
println
(
"select a command : 5. GET VALUES FROM A TABLE"
);
System
.
out
.
println
(
"select a command : 6. GET THE SIZE OF A TABLE"
);
System
.
out
.
println
(
"select a command : 7. REMOVE AN EXISTING TABLE"
);
int
cmd
=
sc
.
nextInt
();
switch
(
cmd
)
{
//operations on the table
case
BFTMAPUtil
.
TAB_CREATE
:
boolean
result4
=
false
;
do
{
String
tableKey
=
console
.
readLine
(
"Enter the HashMap name"
);
result4
=
bftMap
.
containsKey
(
tableKey
);
if
(!
result4
)
{
//if the table name does not exist then create the table
bftMap
.
put
(
tableKey
,
new
HashMap
<
String
,
byte
[]>());
}
}
while
(
result4
);
break
;
case
BFTMAPUtil
.
SIZE_TABLE
:
//obtain the size of the table of tables.
System
.
out
.
println
(
"Computing the size of the table"
);
int
size
=
bftMap
.
size
();
System
.
out
.
println
(
"The size of the table of tables is "
+
size
);
break
;
case
BFTMAPUtil
.
TAB_REMOVE
:
//Remove the table entry
boolean
result11
=
false
;
HashMap
<
String
,
byte
[]>
info
=
null
;
String
tableKey5
=
null
;
System
.
out
.
println
(
"Executing remove operation on table of tables"
);
do
{
tableKey5
=
console
.
readLine
(
"Enter the valid table name you want to remove"
);
result11
=
bftMap
.
containsKey
(
tableKey5
);
}
while
(!
result11
);
info
=
bftMap
.
remove
(
tableKey5
);
System
.
out
.
println
(
"Table removed"
);
break
;
//operations on the hashmap
case
BFTMAPUtil
.
PUT
:
System
.
out
.
println
(
"Execute put function"
);
boolean
result5
=
false
;
String
value
=
null
;
String
tableKey
=
null
;
String
key
=
null
;
do
{
tableKey
=
console
.
readLine
(
"Enter the valid table name in which you want to enter the data"
);
result4
=
bftMap
.
containsKey
(
tableKey
);
if
(
result4
)
{
//if the table name does not exist then create the table
key
=
console
.
readLine
(
"Enter the key"
);
value
=
console
.
readLine
(
"Enter the value"
);
}
}
while
(!
result4
);
byte
[]
b
=
value
.
getBytes
();
byte
[]
result
=
bftMap
.
put1
(
tableKey
,
key
,
b
);
System
.
out
.
println
(
"Result : "
+
new
String
(
result
));
break
;
case
BFTMAPUtil
.
GET
:
System
.
out
.
println
(
"Execute get function"
);
boolean
result6
=
false
;
boolean
result7
=
false
;
String
value2
=
null
;
String
tableName1
=
null
;
String
key1
=
null
;
do
{
tableName1
=
console
.
readLine
(
"Enter the valid table name from which you want to get the values"
);
result6
=
bftMap
.
containsKey
(
tableName1
);
if
(
result6
)
{
do
{
key1
=
console
.
readLine
(
"Enter the valid key: "
);
result7
=
bftMap
.
containsKey1
(
tableName1
,
key1
);
if
(
result7
)
{
byte
[]
result1
=
bftMap
.
getEntry
(
tableName1
,
key1
);
System
.
out
.
println
(
"The value received from GET is"
+
new
String
(
result1
));
}
}
while
(!
result7
);
}
}
while
(!
result6
);
break
;
case
BFTMAPUtil
.
SIZE
:
System
.
out
.
println
(
"Execute get function"
);
boolean
result8
=
false
;
String
value3
=
null
;
String
tableName2
=
null
;
String
key2
=
null
;
int
size1
=
-
1
;
do
{
tableName2
=
console
.
readLine
(
"Enter the valid table whose size you want to detemine"
);
result8
=
bftMap
.
containsKey
(
tableName2
);
if
(
result8
)
{
size1
=
bftMap
.
size1
(
tableName2
);
System
.
out
.
println
(
"The size is : "
+
size1
);
}
}
while
(!
result8
);
break
;
case
BFTMAPUtil
.
REMOVE
:
System
.
out
.
println
(
"Execute get function"
);
boolean
result9
=
false
;
boolean
result10
=
false
;
String
value4
=
null
;
String
tableName3
=
null
;
String
key3
=
null
;
do
{
tableName3
=
console
.
readLine
(
"Enter the valid table name which you want to remove"
);
result9
=
bftMap
.
containsKey
(
tableName3
);
if
(
result9
)
{
do
{
key3
=
console
.
readLine
(
"Enter the valid key: "
);
result10
=
bftMap
.
containsKey1
(
tableName3
,
key3
);
if
(
result10
)
{
byte
[]
result2
=
bftMap
.
removeEntry
(
tableName3
,
key3
);
System
.
out
.
println
(
"The previous value was : "
+
new
String
(
result2
));
}
}
while
(!
result10
);
}
}
while
(!
result10
);
break
;
}
}
}
}
src/navigators/smart/tom/demo/KVServer.java
已删除
100644 → 0
浏览文件 @
85e5cf24
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
navigators.smart.tom.demo
;
/**
*
* @author sweta
*/
public
class
KVServer
{
public
static
void
main
(
String
[]
args
){
if
(
args
.
length
<
1
)
{
System
.
out
.
println
(
"Use: java KVServer <processId>"
);
System
.
exit
(-
1
);
}
BFTMapImpl
bftServer
=
new
BFTMapImpl
(
Integer
.
parseInt
(
args
[
0
]));
}
}
src/navigators/smart/tom/demo/RWCounterClient.java
0 → 100644
浏览文件 @
31ceb8fe
/**
* Copyright (c) 2007-2009 Alysson Bessani, Eduardo Alchieri, Paulo Sousa, and the authors indicated in the @author tags
*
* This file is part of SMaRt.
*
* SMaRt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SMaRt 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 for more details.
*
* You should have received a copy of the GNU General Public License along with SMaRt. If not, see <http://www.gnu.org/licenses/>.
*/
package
navigators.smart.tom.demo
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.util.Comparator
;
import
navigators.smart.tom.ServiceProxy
;
import
navigators.smart.tom.core.messages.TOMMessage
;
import
navigators.smart.tom.util.Extractor
;
/**
* Example client that updates a BFT replicated service (a counter).
* In this case in particular, the client increments the counter by 1 in
* the odd iterations (1,3,...) and read its value (using the read-only
* optimization) in the even iteractions.
*
* This example also shows how to use a Comparator and Extractor to implement
* custom processing of the reply voting.
*
* This client should be used with the CounterServer.
*
* @author alysson
*/
public
class
RWCounterClient
{
@SuppressWarnings
(
"static-access"
)
public
static
void
main
(
String
[]
args
)
throws
IOException
{
if
(
args
.
length
<
2
)
{
System
.
err
.
println
(
"Usage: java ROClient <process id> <iteractions>"
);
System
.
exit
(-
1
);
}
ServiceProxy
counterProxy
=
new
ServiceProxy
(
Integer
.
parseInt
(
args
[
0
]),
"config"
,
new
VerboseComparator
(),
new
VerboseExtractor
());
int
iteractions
=
Integer
.
parseInt
(
args
[
1
]);
for
(
int
i
=
0
;
i
<
iteractions
;
i
++)
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
(
4
);
new
DataOutputStream
(
out
).
writeInt
(
i
%
2
);
System
.
out
.
println
(((
i
%
2
==
0
)?
"(read-only)"
:
""
)+
" requesting operation "
+
i
+
" on counter."
);
byte
[]
reply
=
counterProxy
.
invoke
(
out
.
toByteArray
(),
(
i
%
2
==
0
));
int
newValue
=
new
DataInputStream
(
new
ByteArrayInputStream
(
reply
)).
readInt
();
System
.
out
.
println
(
"Counter value: "
+
newValue
);
}
System
.
exit
(
0
);
}
static
class
VerboseComparator
implements
Comparator
<
byte
[]>
{
@Override
public
int
compare
(
byte
[]
o1
,
byte
[]
o2
)
{
try
{
int
o1v
=
new
DataInputStream
(
new
ByteArrayInputStream
(
o1
)).
readInt
();
int
o2v
=
new
DataInputStream
(
new
ByteArrayInputStream
(
o2
)).
readInt
();
System
.
out
.
println
(
"comparing "
+
o1v
+
" and "
+
o2v
);
return
o1v
==
o2v
?
0
:-
1
;
}
catch
(
IOException
ioe
)
{
return
-
1
;
}
}
}
static
class
VerboseExtractor
implements
Extractor
{
@Override
public
TOMMessage
extractResponse
(
TOMMessage
[]
replies
,
int
sameContent
,
int
lastReceived
)
{
System
.
out
.
print
(
"Received replies = { "
);
for
(
TOMMessage
reply:
replies
)
{
if
(
reply
==
null
)
continue
;
try
{
int
v
=
new
DataInputStream
(
new
ByteArrayInputStream
(
reply
.
getContent
())).
readInt
();
System
.
out
.
print
(
v
+
" "
);
}
catch
(
IOException
ioe
)
{}
}
System
.
out
.
println
(
"}"
);
System
.
out
.
println
(
"# replies with the same content = "
+
sameContent
);
return
replies
[
lastReceived
];
}
}
}
src/navigators/smart/tom/demo/RandomServer.java
浏览文件 @
31ceb8fe
...
...
@@ -57,7 +57,7 @@ public class RandomServer extends ServiceReplica {
}
@Override
public
byte
[]
executeCommand
(
int
clientId
,
long
timestamp
,
byte
[]
nonces
,
byte
[]
command
,
DebugInfo
info
)
{
public
byte
[]
executeCommand
(
int
clientId
,
long
timestamp
,
byte
[]
nonces
,
byte
[]
command
,
boolean
readOnly
,
DebugInfo
info
)
{
/**********ISTO E CODIGO MARTELADO, PARA FAZER AVALIACOES **************/
//System.out.println(currentTime);
if
(
initialTime
>
-
1
)
currentTime
=
System
.
currentTimeMillis
()
-
initialTime
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录