Commit f6bd61a8 authored by Elf's avatar Elf

扩散算法(伪)

parent 60aee3cd
...@@ -48,6 +48,8 @@ public class FileService{ ...@@ -48,6 +48,8 @@ public class FileService{
"sate22","sate23","sate24","sate25","sate26","sate27","sate28","sate29"};//获取卫星名字 "sate22","sate23","sate24","sate25","sate26","sate27","sate28","sate29"};//获取卫星名字
private String[] ipList = new String[29]; private String[] ipList = new String[29];
private List <Integer> index = new ArrayList<Integer>() {} ;
/* @PostConstruct /* @PostConstruct
public void init() { public void init() {
*//* ipList = getIpList(11113l,"dbc_server"); *//* ipList = getIpList(11113l,"dbc_server");
...@@ -103,25 +105,29 @@ public class FileService{ ...@@ -103,25 +105,29 @@ public class FileService{
System.out.println(ipList.length); System.out.println(ipList.length);
System.out.println(Arrays.toString(ipList)); System.out.println(Arrays.toString(ipList));
int sliceNum = 10; index = this.getIndex(ipList.length);
int sliceNum = 5;
// todo 这里需要制定文件的fileId // todo 这里需要制定文件的fileId
SplitResult splitResult = distributedComService.fileSplit(bufferedImage, sliceNum); SplitResult splitResult = distributedComService.fileSplit(bufferedImage, sliceNum);
int ipIndex = 0; //int ipIndex = 0;
int i = 0;
for (FileSlice slice : splitResult.getFileSliceList()) { for (FileSlice slice : splitResult.getFileSliceList()) {
slice.setFileId(fileId); slice.setFileId(fileId);
//异常处理 //异常处理
while(true){ while(true){
try { try {
sendFileSlice(ipList[ipIndex], slice); sendFileSlice(ipList[index.get(i)], slice);
// //
System.out.println("send "+ipList[ipIndex]+"success"); System.out.println("send "+wxName_list[index.get(i)]+" success");
ipIndex = (ipIndex + 1) % ipList.length; i = i+1;
//ipIndex = (ipIndex + 1) % ipList.length;
break; break;
}catch (Exception e){ }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{ ...@@ -160,7 +166,7 @@ public class FileService{
for (int i = 0; i < wxName_list.length; i++){ for (int i = 0; i < wxName_list.length; i++){
ipList[i] = getIpByAppName(clusterId,wxName_list[i]);//通过卫星名字获取卫星ip ipList[i] = getIpByAppName(clusterId,wxName_list[i]);//通过卫星名字获取卫星ip
} }
int sliceNum = 10; int sliceNum = 5;
//int sliceNum = ipList.length; //int sliceNum = ipList.length;
Set<FileSlice> result = new HashSet<>(); Set<FileSlice> result = new HashSet<>();
/* for (String ip : ipList) { /* for (String ip : ipList) {
...@@ -169,9 +175,10 @@ public class FileService{ ...@@ -169,9 +175,10 @@ public class FileService{
}*/ }*/
//异常处理 //异常处理
for (int index = 0; index < 10; index++) { for (int k = 0; k < 5; k++) {
try { 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); result.addAll(fileSliceSet);
}catch (Exception e){ }catch (Exception e){
...@@ -222,6 +229,21 @@ public class FileService{ ...@@ -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