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 */ 023 024package dk.netarkivet.archive.bitarchive.distribute; 025 026import dk.netarkivet.archive.distribute.ArchiveMessage; 027import dk.netarkivet.archive.distribute.ArchiveMessageVisitor; 028import dk.netarkivet.common.distribute.ChannelID; 029import dk.netarkivet.common.distribute.arcrepository.BitarchiveRecord; 030 031/** 032 * Container for get requests. 033 */ 034@SuppressWarnings({"serial"}) 035public class GetMessage extends ArchiveMessage { 036 /** the arcfile to retrieve an record from. */ 037 private String arcfile; 038 /** offset of the record to retrieve. */ 039 private long index; 040 /** the retrieved record. */ 041 private BitarchiveRecord record; 042 043 /** 044 * Constructor. 045 * 046 * @param to Where the message should be sent. 047 * @param replyTo where the reply of this message should be sent. 048 * @param arcfile The name of the file to retrieve a arc-record from. 049 * @param index The offset of the arc-file. 050 */ 051 public GetMessage(ChannelID to, ChannelID replyTo, String arcfile, long index) { 052 super(to, replyTo); 053 this.arcfile = arcfile; 054 this.index = index; 055 } 056 057 /** 058 * Get name of the arc file. 059 * 060 * @return file name 061 */ 062 public String getArcFile() { 063 return arcfile; 064 } 065 066 /** 067 * Index of the record to retrieve. 068 * 069 * @return offset 070 */ 071 public long getIndex() { 072 return index; 073 } 074 075 /** 076 * Register retrieved record. 077 * 078 * @param rec Record retrieved from arcfile at offset index 079 */ 080 public void setRecord(BitarchiveRecord rec) { 081 record = rec; 082 } 083 084 /** 085 * Get the data retrieved from the arcfile. 086 * 087 * @return Record from arcfile 088 */ 089 public BitarchiveRecord getRecord() { 090 return record; 091 } 092 093 /** 094 * Should be implemented as a part of the visitor pattern. fx.: public void accept(ArchiveMessageVisitor v) { 095 * v.visit(this); } 096 * 097 * @param v A message visitor 098 */ 099 public void accept(ArchiveMessageVisitor v) { 100 v.visit(this); 101 } 102 103 /** 104 * Retrieval of a string representation of this instance. 105 * 106 * @return The string representation of this instance. 107 */ 108 public String toString() { 109 return super.toString() + " Arcfile: " + arcfile + " Offset: " + index; 110 } 111 112}