001/* 002 * #%L 003 * Netarchivesuite - archive 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.archive.arcrepository.bitpreservation; 024 025import dk.netarkivet.archive.distribute.ArchiveMessage; 026import dk.netarkivet.archive.distribute.ArchiveMessageVisitor; 027import dk.netarkivet.common.distribute.Channels; 028import dk.netarkivet.common.distribute.arcrepository.ReplicaStoreState; 029 030/** 031 * Class encapsulating a request to update AdminData. The message has two different types: changestorestate-type, and 032 * changechecksum-type. There is a constructor for each type. 033 */ 034@SuppressWarnings({"serial"}) 035public class AdminDataMessage extends ArchiveMessage { 036 037 /** The filename to be updated in AdminData. */ 038 private String fileName; 039 /** The id of the replica, where the file resides. */ 040 private String replicaId; 041 /** 042 * the new storestate for the filename. Used only when changestorestate is true. 043 */ 044 private ReplicaStoreState newvalue; 045 /** 046 * the new checksum for the filename. Used only when changechecksum is true. 047 */ 048 private String checksum; 049 /** change storestate flag. default = false. */ 050 private boolean changestorestate = false; 051 /** change checksum flag. default = false. */ 052 private boolean changechecksum = false; 053 054 /** 055 * Constructor used when you change the BitarchiveStoreState. 056 * 057 * @param theFileName The filename you want to give a new BitarchiveStoreState. 058 * @param theReplicaId The ID for the bitarchive where the file resides 059 * @param newval The new BitarchiveStoreState 060 */ 061 public AdminDataMessage(String theFileName, String theReplicaId, ReplicaStoreState newval) { 062 super(Channels.getTheRepos(), Channels.getThisReposClient()); 063 this.fileName = theFileName; 064 this.replicaId = theReplicaId; 065 this.newvalue = newval; 066 this.changestorestate = true; 067 } 068 069 /** 070 * Constructor used when you want to change the checksum for the given filename. 071 * 072 * @param theFileName the given filename 073 * @param theChecksum the new checksum for the filename 074 */ 075 public AdminDataMessage(String theFileName, String theChecksum) { 076 super(Channels.getTheRepos(), Channels.getThisReposClient()); 077 fileName = theFileName; 078 checksum = theChecksum; 079 changechecksum = true; 080 } 081 082 /** 083 * Should be implemented as a part of the visitor pattern. fx.: public void accept(ArchiveMessageVisitor v) { 084 * v.visit(this); } 085 * 086 * @param v A message visitor 087 */ 088 public void accept(ArchiveMessageVisitor v) { 089 v.visit(this); 090 } 091 092 /** 093 * Method for retrieving the replica id from this message. 094 * 095 * @return Returns the replicaId. 096 */ 097 public String getReplicaId() { 098 return replicaId; 099 } 100 101 /** 102 * Method for retrieving the name of the file which are refered to in this message. 103 * 104 * @return Returns the fileName. 105 */ 106 public String getFileName() { 107 return fileName; 108 } 109 110 /** 111 * @return Returns the fileName. 112 */ 113 public String getChecksum() { 114 return checksum; 115 } 116 117 /** 118 * Return the state of the changestorestate - flag. 119 * 120 * @return true, if this message is a changestorestate message 121 */ 122 public boolean isChangeStoreState() { 123 return changestorestate; 124 } 125 126 /** 127 * Return the state of the changechecksum - flag. 128 * 129 * @return true, if this message is a changechecksum message 130 */ 131 public boolean isChangeChecksum() { 132 return changechecksum; 133 } 134 135 /** 136 * @return Returns the newvalue. 137 */ 138 public ReplicaStoreState getNewvalue() { 139 return newvalue; 140 } 141}