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.bitarchive.distribute; 024 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028import dk.netarkivet.common.exceptions.ArgumentNotValid; 029import dk.netarkivet.common.exceptions.PermissionDenied; 030import dk.netarkivet.common.exceptions.UnknownID; 031 032/** 033 * Bitarchive container responsible for processing the different classes of message which can be received by a 034 * bitarchive and returning appropriate data. 035 */ 036public class AccessBitarchiveServer extends BitarchiveServer { 037 /** The logger used by this class. */ 038 private static final Logger log = LoggerFactory.getLogger(AccessBitarchiveServer.class); 039 040 041 /** The unique instance of this class. */ 042 private static AccessBitarchiveServer instance; 043 044 /** 045 * Returns the unique instance of this class The server creates an instance of the bitarchive it provides access to 046 * and starts to listen to JMS messages on the incomming jms queue 047 * <p> 048 * Also, heartbeats are sent out at regular intervals to the Bitarchive Monitor, to tell that this bitarchive is 049 * alive. 050 * 051 * @return the instance 052 * @throws UnknownID - if there was no heartbeat frequency defined in settings 053 * @throws ArgumentNotValid - if the heartbeat frequency in settings is invalid or either argument is null 054 */ 055 public static synchronized AccessBitarchiveServer getInstance() throws ArgumentNotValid, UnknownID { 056 if (instance == null) { 057 instance = new AccessBitarchiveServer(); 058 } 059 return instance; 060 } 061 062 /** 063 * The server creates an instance of the bitarchive it provides access to and starts to listen to JMS messages on 064 * the incomming jms queue 065 * <p> 066 * Also, heartbeats are sent out at regular intervals to the Bitarchive Monitor, to tell that this bitarchive is 067 * alive. 068 * 069 * @throws UnknownID - if there was no heartbeat frequency or temp dir defined in settings or if the bitarchiveid 070 * cannot be created. 071 * @throws PermissionDenied - if the temporary directory or the file directory cannot be written 072 */ 073 private AccessBitarchiveServer() throws UnknownID, PermissionDenied { 074 super(); 075 } 076 077 @Override 078 public void visit(UploadMessage msg) throws ArgumentNotValid { 079 msg.setNotOk(new ArgumentNotValid("Not valid to modify anything to an AccessBitarchive.")); 080 log.warn("Will not deal with UploadMessage #{}", msg); 081 con.reply(msg); 082 } 083 084 @Override 085 public void visit(RemoveAndGetFileMessage msg) throws ArgumentNotValid { 086 msg.setNotOk(new ArgumentNotValid("Not valid to modify anything to an AccessBitarchive.")); 087 log.warn("Will not deal with RemoveAndGetFileMessage #{}", msg); 088 con.reply(msg); 089 } 090}