23 |
|
|
24 |
|
|
25 |
public class AfstandAndenRuteTask extends Task { |
public class AfstandAndenRuteTask extends Task { |
26 |
|
|
27 |
|
|
28 |
private TaskLogger logger = TaskLogger.getInstance(); |
private TaskLogger logger = TaskLogger.getInstance(); |
29 |
|
|
30 |
final boolean verbose = false;// |
final static boolean VERBOSE = false;// |
31 |
|
|
32 |
|
public final static String INCREMENTAL = "INCREMENTAL"; |
33 |
|
public final static String FULL = "FULL"; |
34 |
|
|
35 |
|
|
36 |
static boolean test_mode; |
static boolean test_mode; |
45 |
|
|
46 |
ThreadPoolExecutor threadPool; |
ThreadPoolExecutor threadPool; |
47 |
|
|
48 |
|
boolean isIncremental; |
49 |
|
|
50 |
|
|
51 |
public AfstandAndenRuteTask(String distributor) { |
public AfstandAndenRuteTask(String distributor, String type) { |
52 |
this.distributor = distributor; |
this.distributor = distributor; |
53 |
|
|
54 |
|
type = type.toUpperCase(); |
55 |
|
switch(type) { |
56 |
|
case FULL: |
57 |
|
isIncremental = false; |
58 |
|
break; |
59 |
|
case INCREMENTAL: |
60 |
|
isIncremental = true; |
61 |
|
break; |
62 |
|
default: |
63 |
|
throw new RuntimeException("Unknown type" + type); |
64 |
|
} |
65 |
} |
} |
66 |
|
|
67 |
|
|
68 |
@Override |
@Override |
69 |
protected void taskRun() throws Exception { |
protected void taskRun() throws Exception { |
70 |
|
|
|
|
|
|
|
|
|
|
|
|
//Setup j.u.l Logger |
|
|
//Logger root = Logger.getLogger(""); |
|
|
//FileHandler fhandler = new FileHandler("fulddaekning.log"); // Ingen max størrelse, ingen rotation og ingen append |
|
|
//fhandler.setFormatter( new SimpleFormatter() ); |
|
|
//root.addHandler( fhandler ); |
|
|
|
|
|
|
|
71 |
|
|
72 |
Constants.init(distributor); |
Constants.init(distributor); |
73 |
Constants consts = Constants.getInstance(); |
Constants consts = Constants.getInstance(); |
86 |
} |
} |
87 |
logger.info("Starting with MAX_WORKERS:" + max_workers); |
logger.info("Starting with MAX_WORKERS:" + max_workers); |
88 |
setupThreadPool(max_workers); |
setupThreadPool(max_workers); |
89 |
|
|
90 |
|
logger.info("Starting with INCREMENTAL:" + isIncremental); |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
try (Connection conn = DBConnection.getConnection() ) { |
try (Connection conn = DBConnection.getConnection() ) { |
95 |
Database db = new Database(conn); |
DatabaseRouteDistance db = new DatabaseRouteDistance(conn, isIncremental); |
96 |
|
|
97 |
|
db.prepareIncrementalSearch(); |
98 |
|
|
99 |
Queue<Address> ikkeDaekkede = db.hentAlleIkkedaekkedeAdresser(consts.getMinPostnr(), consts.getMaxPostnr() ); |
Queue<Address> ikkeDaekkede = db.hentAlleIkkedaekkedeAdresser(consts.getMinPostnr(), consts.getMaxPostnr() ); |
100 |
antalIkkeDaekkede = ikkeDaekkede.size(); |
antalIkkeDaekkede = ikkeDaekkede.size(); |
156 |
CyclicBarrier barrier = new CyclicBarrier(max_workers + 1); |
CyclicBarrier barrier = new CyclicBarrier(max_workers + 1); |
157 |
|
|
158 |
for (int i=0; i<max_workers; i++) { |
for (int i=0; i<max_workers; i++) { |
159 |
LookupWorker worker = new LookupWorker(i, this, barrier, ikkeDaekkede, hoTrees,antalFundne,antalBeregnet,db,verbose,consts); |
LookupWorker worker = new LookupWorker(i, this, barrier, ikkeDaekkede, hoTrees,antalFundne,antalBeregnet,db,VERBOSE,consts); |
160 |
threadPool.submit( worker ); |
threadPool.submit( worker ); |
161 |
} |
} |
162 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
} else { |
} /*else { |
185 |
/// Test |
/// Test |
186 |
/* |
|
187 |
db.resetResultTable(); |
db.resetResultTable(); |
188 |
|
|
189 |
|
|
192 |
|
|
193 |
short post = (short) 2700; |
short post = (short) 2700; |
194 |
Lookup lookup = new Lookup(post, db, threadPool); |
Lookup lookup = new Lookup(post, db, threadPool); |
195 |
lookup.doLookup();*/ |
lookup.doLookup(); |
196 |
} |
} */ |
197 |
|
|
198 |
|
|
199 |
long now = System.currentTimeMillis(); |
long now = System.currentTimeMillis(); |
208 |
logger.info("Heraf, antal fundne : " + antalFundne ); |
logger.info("Heraf, antal fundne : " + antalFundne ); |
209 |
|
|
210 |
logger.info( String.format("Fandt adresser til : %.2f %%", (antalFundne.get() *100.0)/antalIkkeDaekkede ) ); |
logger.info( String.format("Fandt adresser til : %.2f %%", (antalFundne.get() *100.0)/antalIkkeDaekkede ) ); |
|
//logger.info("Fandt adresser til : " + (antalFundne*100.0)/ikkeDaekkede.length + "%" ); |
|
|
|
|
211 |
} |
} |
212 |
} |
} |
213 |
|
|
249 |
|
|
250 |
@Override |
@Override |
251 |
public String getDetail() { |
public String getDetail() { |
252 |
// TODO Auto-generated method stub |
if (isIncremental) { |
253 |
return ""; |
return "Type: incremental"; |
254 |
|
} else { |
255 |
|
return "Type: full"; |
256 |
|
} |
257 |
} |
} |
258 |
|
|
259 |
|
|