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.distribute; 024 025import java.util.ArrayList; 026import java.util.List; 027 028import dk.netarkivet.archive.bitarchive.distribute.BitarchiveClient; 029import dk.netarkivet.archive.checksum.distribute.ChecksumClient; 030import dk.netarkivet.common.distribute.ChannelID; 031import dk.netarkivet.common.distribute.Channels; 032 033/** 034 * This contains a method for retrieving all the replica clients at once. 035 */ 036public final class ReplicaClientFactory { 037 /** 038 * Private constructor. Prevents instantiation of this class. 039 */ 040 private ReplicaClientFactory() { 041 } 042 043 /** 044 * Method for retrieving the clients for the correct replicas. 045 * 046 * @return The clients to the different replicas as a list. 047 */ 048 public static List<ReplicaClient> getReplicaClients() { 049 // get the channels 050 ChannelID[] allBas = Channels.getAllArchives_ALL_BAs(); 051 ChannelID[] anyBas = Channels.getAllArchives_ANY_BAs(); 052 ChannelID[] theBamons = Channels.getAllArchives_BAMONs(); 053 ChannelID[] theCRs = Channels.getAllArchives_CRs(); 054 055 // initialise the resulting list according to the number of channels. 056 List<ReplicaClient> res = new ArrayList<ReplicaClient>(allBas.length); 057 058 // extract the replica types and 059 for (int i = 0; i < allBas.length; i++) { 060 // the theCR for a bitarchive is 'null', and the bitarchive channels 061 // are 'null' for the checksumarchive. 062 if (theCRs[i] == null) { 063 // add a bitarchive client. 064 res.add(BitarchiveClient.getInstance(allBas[i], anyBas[i], theBamons[i])); 065 } else { 066 // add a checksum client. 067 res.add(ChecksumClient.getInstance(theCRs[i])); 068 } 069 } 070 071 return res; 072 } 073}