Changeset 1144 for OAIHarvester


Ignore:
Timestamp:
02/24/11 13:57:42 (13 years ago)
Author:
oschonef
Message:
  • add per prefix statistics
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  
    1111        ERROR,
    1212        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
    1428
    1529    public long getId();
     
    1933    public boolean isRunning();
    2034
    21     public long getRecordCount();
     35    public long getTotelRecordCount();
    2236
    23     public long getRequestCount();
     37    public long getTotelRequestCount();
    2438
    25     public long getResumptionCount();
    26 
    27     public long getBytesTransferred();
     39    public long getTotalBytesTransferred();
    2840
    2941    public long getTotalTime();
     
    5365    public void setMetadataPrefixes(List<String> prefixes);
    5466
     67    public Statistics getStatistics(String prefix);
     68   
     69    public List<Statistics> getStatistics();
     70
    5571    public void run() throws HarvesterException;
    5672
  • OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/HarvestJobImpl.java

    r1140 r1144  
    2828        HARVEST_RECORDS
    2929    }
     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
    3098    private final AbstractHarvester harvester;
    3199    private final long id;
     
    46114    private int compressionMask;
    47115    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;
    52119    private long timeTotal = 0;
    53120    private long timeNetwork = 0;
     
    55122    private long timeProcessing = 0;
    56123    private long startTimestamp;
     124    private List<Statistics> statistics = null;
    57125    private Task task = Task.IDENTIFY_REPOSITORY;
    58126    private long delayUntil = 0;
     
    60128    private List<String> prefixWorklist = null;
    61129    private String resumptionToken = null;
    62     private Date latestDatestamp = null;
    63130
    64131    HarvestJobImpl(AbstractHarvester harvester, long id, URI repositoryURI,
     
    86153
    87154    @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;
    105167    }
    106168
     
    188250        } else {
    189251            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;
    190280        }
    191281    }
     
    290380
    291381    void incRequestCount() {
    292         requestCount++;
     382        totalRequestCount++;
     383        final StatisticsImpl stats = getCurrentStatistics();
     384        if (stats != null) {
     385            stats.incRequestCount();
     386        }
    293387    }
    294388
    295389    void incResumptionCount() {
    296         resumptionCount++;
     390        final StatisticsImpl stats = getCurrentStatistics();
     391        if (stats != null) {
     392            stats.incResumptionCount();
     393        }
    297394    }
    298395
     
    303400    void finishRequest(long bytesTransferred, long timeProcessingDelta) {
    304401        timeProcessing += timeProcessingDelta;
    305         bytedTransferred += bytesTransferred;
     402        totalBytesTransferred += bytesTransferred;
     403        final StatisticsImpl stats = getCurrentStatistics();
     404        if (stats != null) {
     405            stats.incBytesTransferred(bytesTransferred);
     406        }
    306407    }
    307408
     
    370471
    371472    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);
    374481        }
    375482    }
    376483
    377484    void onFinishListingRecords() {
     485        Date latestDatestamp = null;
     486
     487        final StatisticsImpl stats = getCurrentStatistics();
     488        if (stats != null) {
     489            latestDatestamp = stats.getLatestDatestamp();
     490        }
    378491        if (handler != null) {
    379492            handler.onFinishListingRecords(getCurrentPrefix(), latestDatestamp);
     
    381494        // reset ...
    382495        resumptionToken = null;
    383         latestDatestamp = null;
    384496    }
    385497
    386498    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());
    394504        }
    395505        if (handler != null) {
     
    472582    }
    473583
     584    private StatisticsImpl getCurrentStatistics() {
     585        if ((statistics != null) && !statistics.isEmpty()) {
     586            return (StatisticsImpl) statistics.get(0);
     587        }
     588        return null;
     589    }
     590
    474591} // class HarvestJobImpl
  • OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/HeaderImpl.java

    r1128 r1144  
    22
    33import java.util.ArrayList;
     4import java.util.Collections;
    45import java.util.Date;
    56import java.util.List;
     
    4445    @Override
    4546    public List<String> getSets() {
    46         return sets.isEmpty() ? null : sets;
     47        return sets.isEmpty() ? null : Collections.unmodifiableList(sets);
    4748    }
    4849
  • OAIHarvester/trunk/OAIHarvester/src/test/java/eu/clarin/cmdi/oai/harvester/HarvesterTest.java

    r1140 r1144  
    66import java.io.IOException;
    77import java.io.InputStream;
    8 import java.util.Arrays;
    98import java.util.Date;
    109import java.util.List;
     
    196195//            cal.set(2010, Calendar.DECEMBER, 15);
    197196//            job.setFrom(cal.getTime());
    198             job.setMetadataPrefixes(Arrays.asList("oai_dc"));
     197//            job.setMetadataPrefixes(Arrays.asList("oai_dc", "cmdi"));
    199198            job.run();
    200199
     
    207206
    208207            System.err.println("==> " + job.getState() + ": "+
    209                     job.getRecordCount() + " record(s) [resumed: " +
    210                     job.getResumptionCount() + " time(s)] / " +
    211                     job.getRequestCount() + " 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");
    213212            System.err.println("          " +
    214213                    (job.getTotalTime() / 1000f) + " total / " +
     
    216215                    (job.getWaitTime() / 1000f) + " wait / " +
    217216                    (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            }
    218224        } catch (HarvesterProtocolErrorException e) {
    219225            System.err.println("Protocol error: ");
Note: See TracChangeset for help on using the changeset viewer.