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.datamodel; 024 025import java.util.List; 026import java.util.Map; 027import java.util.Set; 028 029import dk.netarkivet.harvester.harvesting.frontier.FrontierReportFilter; 030import dk.netarkivet.harvester.harvesting.frontier.InMemoryFrontierReport; 031import dk.netarkivet.harvester.harvesting.monitor.StartedJobInfo; 032 033/** 034 * Abstract class for handling the persistence of running job infos. 035 * 036 * @see StartedJobInfo 037 */ 038public abstract class RunningJobsInfoDAO implements DAO { 039 040 /** The singleton instance of this class. */ 041 private static RunningJobsInfoDAO instance; 042 043 /** 044 * Constructor used when creating singleton. Do not call directly. 045 */ 046 protected RunningJobsInfoDAO() { 047 048 } 049 050 /** 051 * Gets the JobDAO singleton. 052 * 053 * @return the JobDAO singleton 054 */ 055 public static synchronized RunningJobsInfoDAO getInstance() { 056 if (instance == null) { 057 instance = new RunningJobsInfoDBDAO(); 058 } 059 return instance; 060 } 061 062 /** 063 * Stores a {@link StartedJobInfo} record to the persistent storage. The record is stored in the monitor table, and 064 * if the elapsed time since the last history sample is equal or superior to the history sample rate, also to the 065 * history table. 066 * 067 * @param startedJobInfo the record to store. 068 */ 069 public abstract void store(StartedJobInfo startedJobInfo); 070 071 /** 072 * Returns the most recent record for every job, partitioned by harvest definition name. 073 * 074 * @return the full listing of started job information, partitioned by harvest definition name. 075 */ 076 public abstract Map<String, List<StartedJobInfo>> getMostRecentByHarvestName(); 077 078 /** 079 * Returns an array of all progress records chronologically sorted for the given job ID. 080 * 081 * @param jobId the job id. 082 * @return an array of all progress records chronologically sorted for the given job ID. 083 */ 084 public abstract StartedJobInfo[] getFullJobHistory(long jobId); 085 086 /** 087 * Returns an array of progress records chronologically sorted for the given job ID, starting at a given crawl time, 088 * and limited to a given number of records. 089 * 090 * @param jobId the job id. 091 * @param startTime the crawl time (in seconds) to begin. 092 * @param limit the maximum number of records to fetch. 093 * @return an array of progress records chronologically sorted for the given job ID, starting at a given crawl time, 094 * and limited to a given number of record. 095 */ 096 public abstract StartedJobInfo[] getMostRecentByJobId(long jobId, long startTime, int limit); 097 098 /** 099 * Returns the most recent progress record for the given job ID. 100 * 101 * @param jobId the job id. 102 * @return the most recent progress record for the given job ID. 103 */ 104 public abstract StartedJobInfo getMostRecentByJobId(long jobId); 105 106 /** 107 * Removes all monitor and history records pertaining to the given job ID from the persistent storage. 108 * 109 * @param jobId the job id. 110 * @return the number of deleted records. 111 */ 112 public abstract int removeInfoForJob(long jobId); 113 114 /** 115 * Store frontier report data to the persistent storage. 116 * 117 * @param report the report to store 118 * @param filterId the id of the filter that produced the report 119 * @param jobId The ID of the harvestjob responsible for this report 120 * @return the update count 121 */ 122 public abstract int storeFrontierReport(String filterId, InMemoryFrontierReport report, Long jobId); 123 124 /** 125 * Returns the list of the available frontier report types. 126 * 127 * @return the list of the available frontier report types. 128 * @see FrontierReportFilter#getFilterId() 129 */ 130 public abstract String[] getFrontierReportFilterTypes(); 131 132 /** 133 * Retrieve a frontier report from a job id and a given filter class. 134 * 135 * @param jobId the job id 136 * @param filterId the id of the filter that produced the report 137 * @return a frontier report 138 */ 139 public abstract InMemoryFrontierReport getFrontierReport(long jobId, String filterId); 140 141 /** 142 * Deletes all frontier report data pertaining to the given job id from the persistent storage. 143 * 144 * @param jobId the job id 145 * @return the update count 146 */ 147 public abstract int deleteFrontierReports(long jobId); 148 149 /** 150 * Returns the ids of jobs for which history records exist, as an immutable set. 151 * 152 * @return the ids of jobs for which history records exist. 153 */ 154 public abstract Set<Long> getHistoryRecordIds(); 155 156}