001/* 002 * #%L 003 * Netarchivesuite - archive 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.archive.webinterface; 024 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028import dk.netarkivet.archive.arcrepository.bitpreservation.ActiveBitPreservation; 029import dk.netarkivet.archive.arcrepository.bitpreservation.ActiveBitPreservationFactory; 030import dk.netarkivet.common.distribute.arcrepository.Replica; 031import dk.netarkivet.common.exceptions.ArgumentNotValid; 032import dk.netarkivet.common.exceptions.UnknownID; 033 034/** 035 * Class for threading a bitpreservation update into a thread. 036 */ 037public class BitpreservationUpdateThread extends Thread { 038 039 /** The log. */ 040 //private Log log = LogFactory.getLog(BitpreservationUpdateThread.class.getName()); 041 protected static final Logger log = LoggerFactory.getLogger(BitpreservationUpdateThread.class); 042 043 /** The ActiveBitPreservation class. */ 044 private final ActiveBitPreservation preserve; 045 046 /** The type of update requested. */ 047 private final BitpreservationUpdateType type; 048 049 /** The replica to work on. */ 050 private final Replica theReplica; 051 052 /** 053 * Constructor for the BitpreservationUpdateThread. 054 * 055 * @param replica The given replica to work on. 056 * @param updateType The type of update requested. 057 * @throws ArgumentNotValid If either the Replica or the BitpreservationUpdateType is null. 058 */ 059 public BitpreservationUpdateThread(Replica replica, BitpreservationUpdateType updateType) throws ArgumentNotValid { 060 ArgumentNotValid.checkNotNull(replica, "Replica replica"); 061 ArgumentNotValid.checkNotNull(updateType, "BitpreservationUpdateType " + "updateType"); 062 preserve = ActiveBitPreservationFactory.getInstance(); 063 type = updateType; 064 theReplica = replica; 065 } 066 067 /** Starts the updatethread thread. */ 068 public void run() { 069 try { 070 if (type.equals(BitpreservationUpdateType.CHECKSUM)) { 071 preserve.findChangedFiles(theReplica); 072 } else if (type.equals(BitpreservationUpdateType.FINDMISSING)) { 073 preserve.findMissingFiles(theReplica); 074 } else { 075 throw new UnknownID("Can't handle type '" + type + "' yet"); 076 } 077 } catch (Exception ex) { 078 log.warn("Update of Activebitpreservation information failed", ex); 079 } 080 } 081}