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 */
023package dk.netarkivet.harvester.harvesting.distribute;
024
025import dk.netarkivet.common.distribute.Channels;
026import dk.netarkivet.common.utils.SystemUtils;
027import dk.netarkivet.harvester.distribute.HarvesterChannels;
028import dk.netarkivet.harvester.distribute.HarvesterMessage;
029import dk.netarkivet.harvester.distribute.HarvesterMessageVisitor;
030import dk.netarkivet.harvester.harvesting.monitor.HarvestMonitor;
031
032/**
033 * Message sent by a HarvestController at startup, to check if the channel name it has been assigned is valid
034 * (e.g. registered in the harvest database).
035 * <p>
036 * The message is sent on a dedicated queue, and processed by the {@link HarvestMonitor}, which checks if the channel
037 * name matches a channel defined in the harvest database.
038 * <p>
039 * In reply a {@link HarvesterRegistrationResponse} is sent back.
040 *
041 * @author ngiraud
042 */
043@SuppressWarnings({"serial"})
044public class HarvesterRegistrationRequest extends HarvesterMessage {
045
046    /** The harvest channel name to check. */
047    private final String harvestChannelName;
048
049    private final String instanceId;
050    
051    private final String hostname;
052
053    public HarvesterRegistrationRequest(final String harvestChannelName, final String instanceId) {
054        super(HarvesterChannels.getHarvesterRegistrationRequestChannel(), Channels.getError());
055        this.harvestChannelName = harvestChannelName;
056        this.instanceId = instanceId;
057        this.hostname = SystemUtils.getLocalHostName();
058    }
059
060    @Override
061    public void accept(HarvesterMessageVisitor v) {
062        v.visit(this);
063    }
064
065    /**
066     * @return the harvestChannelName
067     */
068    public final String getHarvestChannelName() {
069        return harvestChannelName;
070    }
071
072    /**
073     * @return the instanceId
074     */
075    public final String getInstanceId() {
076        return instanceId;
077    }
078
079    /**
080     * @return the hostname of the sender
081     */
082    public final String getHostname() {
083        return hostname;
084    }
085    
086}