Commit f6bd61a8 authored by Elf's avatar Elf

扩散算法(伪)

parent 60aee3cd
......@@ -48,6 +48,8 @@ public class FileService{
"sate22","sate23","sate24","sate25","sate26","sate27","sate28","sate29"};//获取卫星名字
private String[] ipList = new String[29];
private List <Integer> index = new ArrayList<Integer>() {} ;
/* @PostConstruct
public void init() {
*//* ipList = getIpList(11113l,"dbc_server");
......@@ -103,25 +105,29 @@ public class FileService{
System.out.println(ipList.length);
System.out.println(Arrays.toString(ipList));
int sliceNum = 10;
index = this.getIndex(ipList.length);
int sliceNum = 5;
// todo 这里需要制定文件的fileId
SplitResult splitResult = distributedComService.fileSplit(bufferedImage, sliceNum);
int ipIndex = 0;
//int ipIndex = 0;
int i = 0;
for (FileSlice slice : splitResult.getFileSliceList()) {
slice.setFileId(fileId);
//异常处理
while(true){
try {
sendFileSlice(ipList[ipIndex], slice);
sendFileSlice(ipList[index.get(i)], slice);
//
System.out.println("send "+ipList[ipIndex]+"success");
ipIndex = (ipIndex + 1) % ipList.length;
System.out.println("send "+wxName_list[index.get(i)]+" success");
i = i+1;
//ipIndex = (ipIndex + 1) % ipList.length;
break;
}catch (Exception e){
ipIndex = (ipIndex + 1) % ipList.length;
//ipIndex = (ipIndex + 1) % ipList.length;
//
System.out.println("send "+ipList[ipIndex]+"failed");
System.out.println("send "+wxName_list[index.get(i)]+" failed");
}
}
}
......@@ -160,7 +166,7 @@ public class FileService{
for (int i = 0; i < wxName_list.length; i++){
ipList[i] = getIpByAppName(clusterId,wxName_list[i]);//通过卫星名字获取卫星ip
}
int sliceNum = 10;
int sliceNum = 5;
//int sliceNum = ipList.length;
Set<FileSlice> result = new HashSet<>();
/* for (String ip : ipList) {
......@@ -169,9 +175,10 @@ public class FileService{
}*/
//异常处理
for (int index = 0; index < 10; index++) {
for (int k = 0; k < 5; k++) {
try {
Set<FileSlice> fileSliceSet = getFileSlice(ipList[index], fileId);
Set<FileSlice> fileSliceSet = getFileSlice(ipList[index.get(k)], fileId);
System.out.println("recive "+wxName_list[index.get(k)]+" success");
result.addAll(fileSliceSet);
}catch (Exception e){
......@@ -222,6 +229,21 @@ public class FileService{
}
public List <Integer> getIndex(int num){
Random r = new Random();
List <Integer> v = new ArrayList<Integer>() {} ;
int count = 0;
while(count < 5){
int number = r.nextInt(num) + 1;
if(!v.contains(number)){
//不在集合中,就添加
v.add(number);
count++;
}
}
return v;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment