001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2013-2014 ForgeRock AS.
016 */
017package org.opends.server.replication.protocol;
018
019import java.util.zip.DataFormatException;
020
021/**
022 * This message is sent at regular intervals by the replication server
023 * when it is sending no other messages.  It allows the directory server to
024 * detect a problem sooner when a synchronization server has crashed or has
025 * been isolated from the network.
026 */
027public class HeartbeatMsg extends ReplicationMsg
028{
029  /**
030   * Create a new HeartbeatMsg.
031   *
032   */
033  public HeartbeatMsg()
034  {
035  }
036
037  /**
038   * Creates a new heartbeat message from its encoded form.
039   *
040   * @param in The byte array containing the encoded form of the message.
041   * @throws java.util.zip.DataFormatException If the byte array does not
042   * contain a valid encoded form of the message.
043   */
044  HeartbeatMsg(byte[] in) throws DataFormatException
045  {
046    /* The heartbeat message is encoded in the form :
047     * <msg-type>
048     */
049    if (in.length != 1 || in[0] != MSG_TYPE_HEARTBEAT)
050    {
051      throw new DataFormatException("Input is not a valid Heartbeat Message.");
052    }
053  }
054
055  /** {@inheritDoc} */
056  @Override
057  public byte[] getBytes(short protocolVersion)
058  {
059    /*
060     * The heartbeat message contains:
061     * <msg-type>
062     */
063    return new byte[] { MSG_TYPE_HEARTBEAT };
064  }
065
066  /** {@inheritDoc} */
067  @Override
068  public String toString()
069  {
070    return getClass().getSimpleName();
071  }
072}