001/* 002 * #%L 003 * Netarchivesuite - harvester 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 */ 023 024package dk.netarkivet.harvester.distribute; 025 026import dk.netarkivet.common.distribute.ChannelID; 027import dk.netarkivet.harvester.datamodel.HarvestChannel; 028 029/** 030 * This singleton class is in charge of giving out the correct channels. 031 */ 032 033public class HarvesterChannels { 034 035 private static final String THESCHED_CHANNEL_PREFIX = "THE_SCHED"; 036 /** 037 * Prefix for the channel used to send CrawlProgressMessages. 038 */ 039 private static final String HARVEST_MONITOR_CHANNEL_PREFIX = "HARVESTMON"; 040 041 /** 042 * Prefix for the channel used to sending HarvesterReadyMessages. 043 */ 044 private static final String HARVESTER_STATUS_CHANNEL_PREFIX = "HARVESTER_STATUS"; 045 /** 046 * The one existing instance of the Channels object. Not accessible from the outside at all. 047 */ 048 private static HarvesterChannels instance; 049 050 /** 051 * Accessor for singleton internally. 052 * 053 * @return the <code>Channels</code> object for this singleton. 054 */ 055 private static HarvesterChannels getInstance() { 056 if (instance == null) { 057 instance = new HarvesterChannels(); 058 } 059 return instance; 060 } 061 062 /** 063 * @return the <code>ChannelID</code> for the queue on which HarvestControllers send harvest status messages 064 */ 065 public static ChannelID getTheSched() { 066 return getInstance().THE_SCHED; 067 } 068 069 public final ChannelID THE_SCHED = new ChannelID(THESCHED_CHANNEL_PREFIX, ChannelID.COMMON, ChannelID.NO_IP, 070 ChannelID.NO_APPLINST_ID, ChannelID.QUEUE); 071 072 /** 073 * Return the queue for the harvest monitor registry. 074 * 075 * @return the <code>ChannelID</code> object for the queue. 076 */ 077 public static ChannelID getHarvestMonitorChannel() { 078 return getInstance().HARVEST_MONITOR; 079 } 080 081 private final ChannelID HARVEST_MONITOR = new ChannelID(HARVEST_MONITOR_CHANNEL_PREFIX, ChannelID.COMMON, 082 ChannelID.NO_IP, ChannelID.NO_APPLINST_ID, ChannelID.QUEUE); 083 084 /** 085 * @return the <code>ChannelID</code> object for the topic used by the harvesters to call in ready for new jobs. 086 */ 087 public static ChannelID getHarvesterStatusChannel() { 088 return getInstance().HARVESTER_STATUS; 089 } 090 091 private final ChannelID HARVESTER_STATUS = new ChannelID(HARVESTER_STATUS_CHANNEL_PREFIX, ChannelID.COMMON, 092 ChannelID.NO_IP, ChannelID.NO_APPLINST_ID, ChannelID.TOPIC); 093 094 /** 095 * Prefix for the channels used to send 096 * {@link dk.netarkivet.harvester.harvesting.distribute.HarvesterRegistrationRequest}s and 097 * {@link dk.netarkivet.harvester.harvesting.distribute.HarvesterRegistrationResponse}s 098 */ 099 private static final String HARVEST_CHANNEL_VALIDITY_PREFIX = "HCHAN_VAL_"; 100 101 private final ChannelID HARVEST_CHANNEL_VALIDITY_REQUEST = new ChannelID(HARVEST_CHANNEL_VALIDITY_PREFIX + "REQ", 102 ChannelID.COMMON, ChannelID.NO_IP, ChannelID.NO_APPLINST_ID, ChannelID.QUEUE); 103 104 /** 105 * Return the queue for sending {@link dk.netarkivet.harvester.harvesting.distribute.HarvesterRegistrationRequest}s. 106 * 107 * @return the <code>ChannelID</code> object for the queue. 108 */ 109 public static ChannelID getHarvesterRegistrationRequestChannel() { 110 return getInstance().HARVEST_CHANNEL_VALIDITY_REQUEST; 111 } 112 113 /** 114 * Prefix for channels related to harvest channel validity messages. 115 */ 116 private final ChannelID HARVEST_CHANNEL_VALIDITY_RESPONSE = new ChannelID(HARVEST_CHANNEL_VALIDITY_PREFIX + "RESP", 117 ChannelID.COMMON, ChannelID.NO_IP, ChannelID.NO_APPLINST_ID, ChannelID.QUEUE); 118 119 /** 120 * Return the queue for sending {@link dk.netarkivet.harvester.harvesting.distribute.HarvesterRegistrationResponse} 121 * s. 122 * 123 * @return the <code>ChannelID</code> object for the queue. 124 */ 125 public static ChannelID getHarvesterRegistrationResponseChannel() { 126 return getInstance().HARVEST_CHANNEL_VALIDITY_RESPONSE; 127 } 128 129 /** 130 * The prefix for channels handling snapshot harvest jobs. 131 */ 132 private static final String JOB_SNAPSHOT_CHANNEL_PREFIX = "JOB_SNAPSHOT"; 133 134 /** 135 * The prefix for channels handling focused harvest jobs. 136 */ 137 private static final String JOB_PARTIAL_CHANNEL_PREFIX = "JOB_PARTIAL"; 138 139 /** 140 * Returns the queue which is used by the scheduler to send doOneCrawl to Harvest Controllers listening on the given 141 * harvest channel. 142 * 143 * @return That channel (queue) 144 */ 145 public static ChannelID getHarvestJobChannelId(HarvestChannel harvestChannel) { 146 String prefix = (harvestChannel.isSnapshot() ? JOB_SNAPSHOT_CHANNEL_PREFIX : JOB_PARTIAL_CHANNEL_PREFIX) + "_" 147 + harvestChannel.getName().toUpperCase(); 148 return new ChannelID(prefix, ChannelID.COMMON, ChannelID.NO_IP, ChannelID.NO_APPLINST_ID, ChannelID.QUEUE); 149 } 150 151 /** 152 * Returns the queue which is used by the scheduler to send doOneCrawl to Harvest Controllers listening on the given 153 * harvest channel. 154 * 155 * @return That channel (queue) 156 */ 157 public static ChannelID getHarvestJobChannelId(String harvestChannelName, boolean isSnapshot) { 158 String prefix = (isSnapshot ? JOB_SNAPSHOT_CHANNEL_PREFIX : JOB_PARTIAL_CHANNEL_PREFIX) + "_" 159 + harvestChannelName.toUpperCase(); 160 return new ChannelID(prefix, ChannelID.COMMON, ChannelID.NO_IP, ChannelID.NO_APPLINST_ID, ChannelID.QUEUE); 161 } 162 163}