001/* 002 * #%L 003 * Netarchivesuite - harvester 004 * %% 005 * Copyright (C) 2005 - 2018 The Royal Danish 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 */ 023package dk.netarkivet.harvester.harvesting.distribute; 024 025import java.io.IOException; 026import java.io.ObjectInputStream; 027import java.io.ObjectOutputStream; 028import java.io.Serializable; 029import java.util.List; 030 031import dk.netarkivet.common.distribute.ChannelID; 032import dk.netarkivet.common.distribute.Channels; 033import dk.netarkivet.common.exceptions.ArgumentNotValid; 034import dk.netarkivet.harvester.datamodel.HarvestDefinitionInfo; 035import dk.netarkivet.harvester.datamodel.Job; 036import dk.netarkivet.harvester.distribute.HarvesterMessage; 037import dk.netarkivet.harvester.distribute.HarvesterMessageVisitor; 038import dk.netarkivet.harvester.harvesting.metadata.MetadataEntry; 039 040/** 041 * Container for doOneCrawl request. Contains the crawler job definition. 042 */ 043@SuppressWarnings({"serial"}) 044public class DoOneCrawlMessage extends HarvesterMessage implements Serializable { 045 046 /** the Job to crawl. */ 047 private Job submittedJob; 048 049 /** The original harvest info. */ 050 private final HarvestDefinitionInfo origHarvestInfo; 051 052 /** Extra metadata associated with the crawl-job. */ 053 private List<MetadataEntry> metadata; 054 055 /** 056 * A NetarkivetMessage that contains a Job for Heritrix. 057 * 058 * @param submittedJob the Job to crawl 059 * @param to the ChannelID for the Server 060 * @param metadata A list of job-metadata 061 * @throws ArgumentNotValid when submittedJob is null 062 */ 063 public DoOneCrawlMessage(Job submittedJob, ChannelID to, HarvestDefinitionInfo harvestInfo, 064 List<MetadataEntry> metadata) throws ArgumentNotValid { 065 super(to, Channels.getError()); 066 ArgumentNotValid.checkNotNull(submittedJob, "submittedJob"); 067 ArgumentNotValid.checkNotNull(metadata, "metadata"); 068 this.submittedJob = submittedJob; 069 this.origHarvestInfo = harvestInfo; 070 this.metadata = metadata; 071 } 072 073 /** 074 * @return the Job 075 */ 076 public Job getJob() { 077 return submittedJob; 078 } 079 080 /** 081 * @return the origHarvestInfo 082 */ 083 public HarvestDefinitionInfo getOrigHarvestInfo() { 084 return origHarvestInfo; 085 } 086 087 /** 088 * @return Returns the metadata. 089 */ 090 public List<MetadataEntry> getMetadata() { 091 return metadata; 092 } 093 094 /** 095 * Should be implemented as a part of the visitor pattern. fx.: public void accept(HarvesterMessageVisitor v) { 096 * v.visit(this); } 097 * 098 * @param v A message visitor 099 */ 100 public void accept(HarvesterMessageVisitor v) { 101 v.visit(this); 102 } 103 104 /** 105 * @return a String that represents the message - only for debugging ! 106 */ 107 public String toString() { 108 return super.toString() + " Job: " + submittedJob + ", metadata: " + metadata; 109 } 110 111 /** 112 * Method needed to de-serializable an object of this class. 113 * 114 * @param s an ObjectInputStream 115 * @throws ClassNotFoundException In case the object read is of unknown class. 116 * @throws IOException On I/O trouble reading the object. 117 */ 118 private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { 119 s.defaultReadObject(); 120 } 121 122 /** 123 * Method needed to serializable an object of this class. 124 * 125 * @param s an ObjectOutputStream 126 * @throws IOException On I/O trouble writing the object. 127 */ 128 private void writeObject(ObjectOutputStream s) throws IOException { 129 s.defaultWriteObject(); 130 } 131 132}