001/*
002 * #%L
003 * Netarchivesuite - monitor
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.monitor.registry.distribute;
024
025import dk.netarkivet.common.distribute.Channels;
026import dk.netarkivet.common.distribute.monitorregistry.HostEntry;
027import dk.netarkivet.common.exceptions.ArgumentNotValid;
028import dk.netarkivet.monitor.distribute.MonitorMessage;
029import dk.netarkivet.monitor.distribute.MonitorMessageVisitor;
030
031/**
032 * This type of message is sent to the monitor registry server to register the host for remote JMX monitoring.
033 */
034@SuppressWarnings({"serial"})
035public class RegisterHostMessage extends MonitorMessage {
036    /** The HostEntry to register. */
037    HostEntry hostEntry;
038
039    /**
040     * Creates a message with the JMX host entry for a host registered to the monitor server.
041     *
042     * @param name The name of the remote host.
043     * @param jmxPort The JMX port allocated on the remote host.
044     * @param rmiPort The RMI port allocated on the remote host.
045     * @throws ArgumentNotValid on null or empty hostname, or negative ports.
046     */
047    public RegisterHostMessage(String name, int jmxPort, int rmiPort) {
048        super(Channels.getTheMonitorServer(), Channels.getError());
049        ArgumentNotValid.checkNotNullOrEmpty(name, "String name");
050        ArgumentNotValid.checkNotNegative(jmxPort, "int jmxPort");
051        ArgumentNotValid.checkNotNegative(rmiPort, "int rmiPort");
052        this.hostEntry = new HostEntry(name, jmxPort, rmiPort);
053    }
054
055    /**
056     * Should be implemented as a part of the visitor pattern. e.g.: <code>
057     * public void accept(MonitorMessageVisitor v) {
058     * v.visit(this);
059     * }
060     * </code>
061     *
062     * @param v A message visitor.
063     * @see MonitorMessageVisitor
064     */
065    public void accept(MonitorMessageVisitor v) {
066        v.visit(this);
067    }
068
069    /**
070     * Get the host entry for the host registering.
071     *
072     * @return The host entry.
073     */
074    public HostEntry getHostEntry() {
075        return hostEntry;
076    }
077}