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 2006-2010 Sun Microsystems, Inc.
015 * Portions Copyright 2011-2015 ForgeRock AS.
016 */
017package org.opends.server.replication.protocol;
018
019/**
020 * The version utility class for the replication protocol.
021 */
022public class ProtocolVersion
023{
024  /**
025   * The constant for the first historical version of the replication protocol.
026   */
027  public static final short REPLICATION_PROTOCOL_V1 = 1;
028  /**
029   * The constant for the real value of the first historical version of the
030   * replication protocol (was used in start messages only).
031   */
032  public static final short REPLICATION_PROTOCOL_V1_REAL = 49;
033  /**
034   * The constant for the second version of the replication protocol.
035   * <ul>
036   * <li>Add fields in the header for assured replication.</li>
037   * </ul>
038   */
039  public static final short REPLICATION_PROTOCOL_V2 = 2;
040
041  /**
042   * The constant for the 3rd version of the replication protocol.
043   * <ul>
044   * <li>Add messages for remote ECL : not used as of today.</li>
045   * </ul>
046   */
047  public static final short REPLICATION_PROTOCOL_V3 = 3;
048
049  /**
050   * The constant for the 4th version of the replication protocol.
051   * <ul>
052   * <li>Add to the body of the ADD/MOD/MODDN/DEL msgs, a list of attribute for
053   * ECL entry attributes.</li>
054   * <li>Modified algorithm for choosing a RS to connect to: introduction of a
055   * ReplicationServerDSMsg message.</li>
056   * <li>also added of the server URL in RSInfo of TopologyMsg</li>
057   * <li>Introduction of a StopMsg for proper connections ending.</li>
058   * <li>Initialization failover/flow control</li>
059   * </ul>
060   */
061  public static final short REPLICATION_PROTOCOL_V4 = 4;
062
063  /**
064   * The constant for the 5th version of the replication protocol.
065   * <ul>
066   * <li>Add support for wild-cards in change log included attributes</li>
067   * <li>Add support for specifying additional included attributes for deletes</li>
068   * <li>See OPENDJ-194.</li>
069   * </ul>
070   */
071  public static final short REPLICATION_PROTOCOL_V5 = 5;
072
073  /**
074   * The constant for the 6th version of the replication protocol.
075   * <ul>
076   * <li>include DS local URL in the DSInfo of TopologyMsg.</li>
077   * </ul>
078   */
079  public static final short REPLICATION_PROTOCOL_V6 = 6;
080
081  /**
082   * The constant for the 7th version of the replication protocol.
083   * <ul>
084   * <li>compact encoding for length, CSNs, and server IDs.</li>
085   * </ul>
086   */
087  public static final short REPLICATION_PROTOCOL_V7 = 7;
088
089  /**
090   * The constant for the 8th version of the replication protocol.
091   * <ul>
092   * <li>New ReplicaOfflineMsg.</li>
093   * </ul>
094   */
095  public static final short REPLICATION_PROTOCOL_V8 = 8;
096
097  /**
098   * The replication protocol version used by the instance of RS/DS in this VM.
099   */
100  private static final short CURRENT_VERSION = REPLICATION_PROTOCOL_V8;
101
102  /**
103   * Gets the current version of the replication protocol.
104   *
105   * @return The current version of the protocol.
106   */
107  public static short getCurrentVersion()
108  {
109    return CURRENT_VERSION;
110  }
111
112  /**
113   * Specifies the oldest version of the protocol from the provided one
114   * and the current one.
115   *
116   * @param version The version to be compared to the current one.
117   * @return The minimal protocol version.
118   */
119  public static short getCompatibleVersion(short version)
120  {
121    return version < CURRENT_VERSION ? version : CURRENT_VERSION;
122  }
123}