Changeset 1144 for OAIHarvester
- Timestamp:
- 02/24/11 13:57:42 (13 years ago)
- Location:
- OAIHarvester/trunk/OAIHarvester/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/HarvestJob.java
r1137 r1144 11 11 ERROR, 12 12 CANCELED 13 }; 13 } // enum State 14 15 public interface Statistics { 16 public String getPrefix(); 17 18 public long getRecordCount(); 19 20 public long getRequestCount(); 21 22 public long getResumptionCount(); 23 24 public long getBytesTransferred(); 25 26 public Date getLatestDatestamp(); 27 } // interface Statistics 14 28 15 29 public long getId(); … … 19 33 public boolean isRunning(); 20 34 21 public long get RecordCount();35 public long getTotelRecordCount(); 22 36 23 public long get RequestCount();37 public long getTotelRequestCount(); 24 38 25 public long getResumptionCount(); 26 27 public long getBytesTransferred(); 39 public long getTotalBytesTransferred(); 28 40 29 41 public long getTotalTime(); … … 53 65 public void setMetadataPrefixes(List<String> prefixes); 54 66 67 public Statistics getStatistics(String prefix); 68 69 public List<Statistics> getStatistics(); 70 55 71 public void run() throws HarvesterException; 56 72 -
OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/HarvestJobImpl.java
r1140 r1144 28 28 HARVEST_RECORDS 29 29 } 30 private static final class StatisticsImpl implements Statistics { 31 private final String prefix; 32 private long recordCount = 0; 33 private long requestCount = 0; 34 private long resumptionCount = 0; 35 private long bytedTransferred = 0; 36 private Date latestDatestamp = null; 37 38 private StatisticsImpl(String prefix) { 39 this.prefix = prefix; 40 } 41 42 @Override 43 public String getPrefix() { 44 return prefix; 45 } 46 47 @Override 48 public long getRecordCount() { 49 return recordCount; 50 } 51 52 private void incRecordCount() { 53 this.recordCount++; 54 } 55 56 @Override 57 public long getRequestCount() { 58 return requestCount; 59 } 60 61 private void incRequestCount() { 62 this.requestCount++; 63 } 64 65 @Override 66 public long getResumptionCount() { 67 return resumptionCount; 68 } 69 70 private void incResumptionCount() { 71 this.resumptionCount++; 72 } 73 74 @Override 75 public long getBytesTransferred() { 76 return bytedTransferred; 77 } 78 79 private void incBytesTransferred(long bytes) { 80 this.bytedTransferred += bytes; 81 } 82 83 @Override 84 public Date getLatestDatestamp() { 85 return latestDatestamp; 86 } 87 88 private void updateLatestDatestmp(Date latestDatestamp) { 89 if (this.latestDatestamp == null) { 90 this.latestDatestamp = latestDatestamp; 91 } else { 92 if (latestDatestamp.compareTo(this.latestDatestamp) > 0) { 93 this.latestDatestamp = latestDatestamp; 94 } 95 } 96 } 97 } // inner class Statistics 30 98 private final AbstractHarvester harvester; 31 99 private final long id; … … 46 114 private int compressionMask; 47 115 private List<MetadataFormat> metadataFormats; 48 private long recordCount = 0; 49 private long requestCount = 0; 50 private long resumptionCount = 0; 51 private long bytedTransferred = 0; 116 private long totalRecordCount = 0; 117 private long totalRequestCount = 0; 118 private long totalBytesTransferred = 0; 52 119 private long timeTotal = 0; 53 120 private long timeNetwork = 0; … … 55 122 private long timeProcessing = 0; 56 123 private long startTimestamp; 124 private List<Statistics> statistics = null; 57 125 private Task task = Task.IDENTIFY_REPOSITORY; 58 126 private long delayUntil = 0; … … 60 128 private List<String> prefixWorklist = null; 61 129 private String resumptionToken = null; 62 private Date latestDatestamp = null;63 130 64 131 HarvestJobImpl(AbstractHarvester harvester, long id, URI repositoryURI, … … 86 153 87 154 @Override 88 public long getRecordCount() { 89 return recordCount; 90 } 91 92 @Override 93 public long getRequestCount() { 94 return requestCount; 95 } 96 97 @Override 98 public long getResumptionCount() { 99 return resumptionCount; 100 } 101 102 @Override 103 public long getBytesTransferred() { 104 return bytedTransferred; 155 public long getTotelRecordCount() { 156 return totalRecordCount; 157 } 158 159 @Override 160 public long getTotelRequestCount() { 161 return totalRequestCount; 162 } 163 164 @Override 165 public long getTotalBytesTransferred() { 166 return totalBytesTransferred; 105 167 } 106 168 … … 188 250 } else { 189 251 this.metadataPrefixes = null; 252 } 253 } 254 255 @Override 256 public Statistics getStatistics(String prefix) { 257 if (prefix == null) { 258 throw new NullPointerException("prefix == null"); 259 } 260 if ((state == State.NEW) || (state == State.RUNNING)) { 261 throw new IllegalStateException("invalid state"); 262 } 263 for (Statistics stats : statistics) { 264 if (prefix.equals(stats.getPrefix())) { 265 return stats; 266 } 267 } 268 return null; 269 } 270 271 @Override 272 public List<Statistics> getStatistics() { 273 if ((state == State.NEW) || (state == State.RUNNING)) { 274 throw new IllegalStateException("invalid state"); 275 } 276 if ((statistics != null) && !statistics.isEmpty()) { 277 return Collections.unmodifiableList(statistics); 278 } else { 279 return null; 190 280 } 191 281 } … … 290 380 291 381 void incRequestCount() { 292 requestCount++; 382 totalRequestCount++; 383 final StatisticsImpl stats = getCurrentStatistics(); 384 if (stats != null) { 385 stats.incRequestCount(); 386 } 293 387 } 294 388 295 389 void incResumptionCount() { 296 resumptionCount++; 390 final StatisticsImpl stats = getCurrentStatistics(); 391 if (stats != null) { 392 stats.incResumptionCount(); 393 } 297 394 } 298 395 … … 303 400 void finishRequest(long bytesTransferred, long timeProcessingDelta) { 304 401 timeProcessing += timeProcessingDelta; 305 bytedTransferred += bytesTransferred; 402 totalBytesTransferred += bytesTransferred; 403 final StatisticsImpl stats = getCurrentStatistics(); 404 if (stats != null) { 405 stats.incBytesTransferred(bytesTransferred); 406 } 306 407 } 307 408 … … 370 471 371 472 void onStartListingRecords() { 372 if (handler != null) { 373 handler.onStartListingRecords(getCurrentPrefix()); 473 final String prefix = getCurrentPrefix(); 474 if (statistics == null) { 475 statistics = new ArrayList<Statistics>(); 476 } 477 statistics.add(0, new StatisticsImpl(prefix)); 478 479 if (handler != null) { 480 handler.onStartListingRecords(prefix); 374 481 } 375 482 } 376 483 377 484 void onFinishListingRecords() { 485 Date latestDatestamp = null; 486 487 final StatisticsImpl stats = getCurrentStatistics(); 488 if (stats != null) { 489 latestDatestamp = stats.getLatestDatestamp(); 490 } 378 491 if (handler != null) { 379 492 handler.onFinishListingRecords(getCurrentPrefix(), latestDatestamp); … … 381 494 // reset ... 382 495 resumptionToken = null; 383 latestDatestamp = null;384 496 } 385 497 386 498 void onRecord(Header header) { 387 recordCount++; 388 if (latestDatestamp == null) { 389 latestDatestamp = header.getDatestamp(); 390 } else { 391 if (latestDatestamp.compareTo(header.getDatestamp()) < 0) { 392 latestDatestamp = header.getDatestamp(); 393 } 499 totalRecordCount++; 500 StatisticsImpl stats = getCurrentStatistics(); 501 if (stats != null) { 502 stats.incRecordCount(); 503 stats.updateLatestDatestmp(header.getDatestamp()); 394 504 } 395 505 if (handler != null) { … … 472 582 } 473 583 584 private StatisticsImpl getCurrentStatistics() { 585 if ((statistics != null) && !statistics.isEmpty()) { 586 return (StatisticsImpl) statistics.get(0); 587 } 588 return null; 589 } 590 474 591 } // class HarvestJobImpl -
OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/HeaderImpl.java
r1128 r1144 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collections; 4 5 import java.util.Date; 5 6 import java.util.List; … … 44 45 @Override 45 46 public List<String> getSets() { 46 return sets.isEmpty() ? null : sets;47 return sets.isEmpty() ? null : Collections.unmodifiableList(sets); 47 48 } 48 49 -
OAIHarvester/trunk/OAIHarvester/src/test/java/eu/clarin/cmdi/oai/harvester/HarvesterTest.java
r1140 r1144 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.util.Arrays;9 8 import java.util.Date; 10 9 import java.util.List; … … 196 195 // cal.set(2010, Calendar.DECEMBER, 15); 197 196 // job.setFrom(cal.getTime()); 198 job.setMetadataPrefixes(Arrays.asList("oai_dc"));197 // job.setMetadataPrefixes(Arrays.asList("oai_dc", "cmdi")); 199 198 job.run(); 200 199 … … 207 206 208 207 System.err.println("==> " + job.getState() + ": "+ 209 job.get RecordCount() + " record(s) [resumed:" +210 job.get ResumptionCount() + " time(s)]/ " +211 job.get RequestCount() + " request(s) / "+212 job.getBytesTransferred() + "bytes transferred");208 job.getTotelRecordCount() + " total record(s) / " + 209 job.getTotelRequestCount() + " total request(s) / " + 210 job.getTotalBytesTransferred() + 211 " total bytes transferred"); 213 212 System.err.println(" " + 214 213 (job.getTotalTime() / 1000f) + " total / " + … … 216 215 (job.getWaitTime() / 1000f) + " wait / " + 217 216 (job.getProcessingTime() / 1000f) + " processing"); 217 for (HarvestJob.Statistics stats : job.getStatistics()) { 218 System.err.println(" " + stats.getPrefix() + ": " + 219 stats.getRecordCount() + " record(s) / " + 220 stats.getRequestCount() + " requsts(s) [" + 221 stats.getResumptionCount() + " time(s) resumed] / " + 222 "latestDatestamp = " + stats.getLatestDatestamp()); 223 } 218 224 } catch (HarvesterProtocolErrorException e) { 219 225 System.err.println("Protocol error: ");
Note: See TracChangeset
for help on using the changeset viewer.