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 */ 023package dk.netarkivet.harvester.harvesting.distribute; 024 025import java.io.Serializable; 026 027import dk.netarkivet.common.distribute.Channels; 028import dk.netarkivet.common.exceptions.ArgumentNotValid; 029import dk.netarkivet.harvester.datamodel.JobStatus; 030import dk.netarkivet.harvester.distribute.HarvesterMessage; 031import dk.netarkivet.harvester.distribute.HarvesterMessageVisitor; 032import dk.netarkivet.harvester.harvesting.monitor.HarvestMonitor; 033 034/** 035 * This message is sent by the HarvestSchedulerMonitorServer to the {@link HarvestMonitor} to notify it that a 036 * job ended and should not be monitored anymore, and that any resource used to monitor this job should be freed. 037 */ 038@SuppressWarnings({"serial"}) 039public class JobEndedMessage extends HarvesterMessage implements Serializable { 040 041 /** The associated job's ID. */ 042 private final long jobId; 043 044 /** The associated job's current status. */ 045 private final JobStatus jobStatus; 046 047 /** 048 * Constructs a new message. 049 * 050 * @param jobId the job ID. 051 * @param jobStatus the job's current status. 052 */ 053 public JobEndedMessage(long jobId, JobStatus jobStatus) { 054 super(HarvestMonitor.HARVEST_MONITOR_CHANNEL_ID, Channels.getError()); 055 ArgumentNotValid.checkNotNull(jobStatus, "jobStatus"); 056 this.jobId = jobId; 057 if (!(JobStatus.DONE.equals(jobStatus) || JobStatus.FAILED.equals(jobStatus))) { 058 throw new ArgumentNotValid("Got status '" + jobStatus.name() + "', expected either '" 059 + JobStatus.DONE.name() + "' or '" + JobStatus.FAILED.name() + "'"); 060 } 061 this.jobStatus = jobStatus; 062 } 063 064 /** 065 * @return the job id 066 */ 067 public long getJobId() { 068 return jobId; 069 } 070 071 /** 072 * @return the job status 073 */ 074 public JobStatus getJobStatus() { 075 return jobStatus; 076 } 077 078 @Override 079 public void accept(HarvesterMessageVisitor v) { 080 v.visit(this); 081 } 082 083}