Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Create CallBackTask.java
- Loading branch information
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
//package multicore; | ||
|
||
//import spliced.Utilities; | ||
|
||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.lang.management.ThreadMXBean; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
|
||
public class CallBackTask implements Callable { | ||
private CallBackTest callBackTest; | ||
private int seq; | ||
public Utilities utilities; | ||
public int start, end; | ||
|
||
public CallBackTask() { | ||
} | ||
|
||
public CallBackTask(int i, int start, int end, Utilities utilities) { | ||
this.utilities = utilities; | ||
seq = i; | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
public static long getCpuTime() { | ||
ThreadMXBean bean = ManagementFactory.getThreadMXBean(); | ||
return bean.isCurrentThreadCpuTimeSupported() ? bean.getCurrentThreadCpuTime() : 0L; | ||
} | ||
|
||
public Object call() throws IOException { | ||
|
||
long startCpuTimeNano = getCpuTime(); | ||
|
||
long begTest = new java.util.Date().getTime(); | ||
System.out.println("STARTING TASK: " + seq); | ||
|
||
List<Utilities.Information> final_list = new ArrayList<Utilities.Information>(25000); | ||
|
||
try { | ||
|
||
int count = 0, hamming_distance, index, min_length; | ||
|
||
for (int i = start; i <= end; i++) { | ||
|
||
if(i == Utilities.union_list.size()){ | ||
break; | ||
} | ||
|
||
index = Utilities.union_list.get(i); | ||
String read = Utilities.reads.get(index); | ||
|
||
Utilities.reads.set(index, ""); | ||
|
||
if (Utilities.hash_map_one.containsKey(index) && Utilities.hash_map_two.containsKey(index)) { | ||
|
||
List<Utilities.Information> info_list = utilities.processUMR(index, read.length()); | ||
|
||
final_list.addAll(info_list); | ||
|
||
info_list.clear(); | ||
|
||
} else { | ||
|
||
hamming_distance = 0; | ||
min_length = 10; | ||
|
||
List<Utilities.UMRInfo> list = utilities.PreProcessUMR(index, read); | ||
|
||
if (list.size() > 0) { | ||
|
||
List<Utilities.Information> info_list = utilities.processUMR(list, hamming_distance, | ||
min_length, index, read.length()); | ||
|
||
if (info_list.size() <= 0) { | ||
|
||
min_length = 8; | ||
|
||
info_list = utilities.processUMR(list, hamming_distance, min_length, index, read.length()); | ||
} | ||
|
||
final_list.addAll(info_list); | ||
} | ||
} | ||
|
||
count++; | ||
|
||
if (count % 1000 == 0) { | ||
|
||
System.out.println("COMPLETED " + count + " BY " + seq + " [" + final_list.size() + "]"); | ||
|
||
long taskCpuTimeNano = getCpuTime() - startCpuTimeNano; | ||
double time_in_seconds = (double) taskCpuTimeNano / 1000000000.0; | ||
|
||
Double secs = (new java.util.Date().getTime() - begTest) * 0.001; | ||
System.out.println("TASK - " + seq + " TOOK " + time_in_seconds + " SECONDS"); | ||
} | ||
} | ||
} catch (Exception x) { | ||
x.printStackTrace(); | ||
System.out.println(x.getMessage()); | ||
} | ||
|
||
callBackTest.callBack(seq, final_list); | ||
|
||
long taskCpuTimeNano = getCpuTime() - startCpuTimeNano; | ||
double time_in_seconds = (double) taskCpuTimeNano / 1000000000.0; | ||
|
||
Double secs = (new java.util.Date().getTime() - begTest) * 0.001; | ||
System.out.println("TASK - " + seq + " TOOK " + time_in_seconds + " SECONDS"); | ||
return null; | ||
} | ||
|
||
public void setCaller(CallBackTest callBackTest) { | ||
this.callBackTest = callBackTest; | ||
} | ||
|
||
public CallBackTest getCaller() { | ||
return callBackTest; | ||
} | ||
} |