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