001/* 002 * #%L 003 * Netarchivesuite - harvester 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023 024package dk.netarkivet.harvester.harvesting.distribute; 025 026import java.io.Serializable; 027 028import dk.netarkivet.common.distribute.Channels; 029import dk.netarkivet.common.exceptions.ArgumentNotValid; 030import dk.netarkivet.harvester.datamodel.JobStatus; 031import dk.netarkivet.harvester.distribute.HarvesterChannels; 032import dk.netarkivet.harvester.distribute.HarvesterMessage; 033import dk.netarkivet.harvester.distribute.HarvesterMessageVisitor; 034import dk.netarkivet.harvester.harvesting.report.HarvestReport; 035 036/** 037 * Instances of this class are sent by a HarvestControllerServer to the THE_SCHED queue to indicate the progress of a 038 * heritrix crawl. They are collected and processed by the HarvestSchedulerMonitorServer. 039 * <p> 040 * This class is immutable 041 */ 042@SuppressWarnings({"serial"}) 043public class CrawlStatusMessage extends HarvesterMessage implements Serializable { 044 045 /** the id for the crawlJob, for which this message reports. */ 046 private long jobID; 047 /** The current state of the crawl-job. */ 048 private JobStatus statusCode; 049 /** A harvestReport created at the end of the crawl. */ 050 private HarvestReport harvestReport; 051 /** harvest errors encountered. */ 052 private String harvestErrors; 053 /** harvest errors encountered with details. */ 054 private String harvestErrorDetails; 055 /** upload errors encountered. */ 056 private String uploadErrors; 057 /** upload errors encountered with details. */ 058 private String uploadErrorDetails; 059 060 /** 061 * Creates an instance of this class corresponding to a job. 062 * 063 * @param jobID the unique identifier for the crawl job to which this message refers 064 * @param statusCode All values are accepted, except null 065 * @param harvestReport A calculated domain harvest report produced by the crawl. May be null for no domain harvest 066 * report. 067 * @throws ArgumentNotValid If invalid arguments: jobID < 0L statusCode == null 068 */ 069 public CrawlStatusMessage(long jobID, JobStatus statusCode, HarvestReport harvestReport) { 070 super(HarvesterChannels.getTheSched(), Channels.getError()); 071 ArgumentNotValid.checkNotNegative(jobID, "jobID"); 072 ArgumentNotValid.checkNotNull(statusCode, "statusCode"); 073 this.jobID = jobID; 074 this.statusCode = statusCode; 075 this.harvestReport = harvestReport; 076 } 077 078 /** 079 * Alternate constructor, which does not have the DomainHarvestreport as argument. 080 * 081 * @param jobID (see description for the other constructor) 082 * @param statusCode (see description for the other constructor) 083 * @see CrawlStatusMessage#CrawlStatusMessage(long, JobStatus, HarvestReport) 084 */ 085 public CrawlStatusMessage(long jobID, JobStatus statusCode) { 086 this(jobID, statusCode, null); 087 } 088 089 /** 090 * Returns the jobID of this crawl job. 091 * 092 * @return the jobID 093 */ 094 public long getJobID() { 095 return jobID; 096 } 097 098 /** 099 * Returns the status code of this crawl job. 100 * 101 * @return the status code 102 */ 103 public JobStatus getStatusCode() { 104 return statusCode; 105 } 106 107 /** 108 * Returns the generated domain harvest report object by this crawl job. May be null on non-finished status, or job 109 * finished with no log file 110 * 111 * @return the hosts report. 112 */ 113 public HarvestReport getDomainHarvestReport() { 114 return harvestReport; 115 } 116 117 /** 118 * Should be implemented as a part of the visitor pattern. fx.: public void accept(HarvesterMessageVisitor v) { 119 * v.visit(this); } 120 * 121 * @param v A message visitor 122 */ 123 public void accept(HarvesterMessageVisitor v) { 124 v.visit(this); 125 } 126 127 /** 128 * Human readable version of object. 129 * 130 * @return Human readable version of object. 131 */ 132 public String toString() { 133 String dhr = ""; 134 if (harvestReport != null) { 135 dhr = harvestReport.toString(); 136 } 137 138 return "CrawlStatusMessage:\n" + "JobID: " + jobID + '\n' + "StatusCode: " + statusCode + '\n' + dhr + '\n' 139 + super.toString(); 140 } 141 142 /** 143 * Get-method for private field harvestErrors. 144 * 145 * @return harvestErrors 146 */ 147 public String getHarvestErrors() { 148 return harvestErrors; 149 } 150 151 /** 152 * Set-method for private field harvestErrors. 153 * 154 * @param harvestErrors The value for harvest errors. 155 * @throws ArgumentNotValid if null argument 156 */ 157 public void setHarvestErrors(String harvestErrors) { 158 ArgumentNotValid.checkNotNull(harvestErrors, "String harvestErrors"); 159 this.harvestErrors = harvestErrors; 160 } 161 162 /** 163 * Get-method for private field harvestErrorDetails. 164 * 165 * @return harvestErrorDetails 166 */ 167 public String getHarvestErrorDetails() { 168 return harvestErrorDetails; 169 } 170 171 /** 172 * Set-method for private field harvestErrorDetails. 173 * 174 * @param harvestErrorDetails The value for harvest error details. 175 * @throws ArgumentNotValid if null argument 176 */ 177 public void setHarvestErrorDetails(String harvestErrorDetails) { 178 ArgumentNotValid.checkNotNull(harvestErrorDetails, "String harvestErrorDetails"); 179 this.harvestErrorDetails = harvestErrorDetails; 180 } 181 182 /** 183 * Get-method for private field uploadErrors. 184 * 185 * @return uploadErrors 186 */ 187 public String getUploadErrors() { 188 return uploadErrors; 189 } 190 191 /** 192 * Set-method for private field uploadErrors. 193 * 194 * @param uploadErrors The value for upload errors. 195 * @throws ArgumentNotValid if null argument 196 */ 197 public void setUploadErrors(String uploadErrors) { 198 ArgumentNotValid.checkNotNull(uploadErrors, "String uploadErrors"); 199 this.uploadErrors = uploadErrors; 200 } 201 202 /** 203 * Get-method for private field uploadErrorDetails. 204 * 205 * @return uploadErrorDetails 206 */ 207 public String getUploadErrorDetails() { 208 return uploadErrorDetails; 209 } 210 211 /** 212 * Set-method for private field uploadErrorDetails. 213 * 214 * @param uploadErrorDetails The value for upload error details. 215 * @throws ArgumentNotValid if null argument 216 */ 217 public void setUploadErrorDetails(String uploadErrorDetails) { 218 ArgumentNotValid.checkNotNull(uploadErrorDetails, "String uploadErrorDetails"); 219 this.uploadErrorDetails = uploadErrorDetails; 220 } 221 222}