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 2009 Sun Microsystems, Inc. 025 * Portions Copyright 2010-2013 ForgeRock AS. 026 */ 027package org.opends.server.replication.server.changelog.je; 028 029import java.io.UnsupportedEncodingException; 030 031import com.sleepycat.je.DatabaseEntry; 032 033import static org.opends.server.util.StaticUtils.*; 034 035/** 036 * Useful to create ReplicationServer keys from sequence numbers. 037 */ 038public class ReplicationDraftCNKey extends DatabaseEntry 039{ 040 private static final long serialVersionUID = 1L; 041 042 /** 043 * Creates a ReplicationDraftCNKey that can start anywhere in the DB. 044 */ 045 public ReplicationDraftCNKey() 046 { 047 super(); 048 } 049 050 /** 051 * Creates a new ReplicationKey from the given change number. 052 * 053 * @param changeNumber 054 * The change number to use. 055 */ 056 public ReplicationDraftCNKey(long changeNumber) 057 { 058 try 059 { 060 // Should it use StaticUtils.getBytes() to increase performances? 061 setData(String.format("%016d", changeNumber).getBytes("UTF-8")); 062 } 063 catch (UnsupportedEncodingException e) 064 { 065 // Should never happens, UTF-8 is always supported 066 // TODO : add better logging 067 } 068 } 069 070 /** 071 * Getter for the change number associated with this key. 072 * 073 * @return the change number associated with this key. 074 */ 075 public long getChangeNumber() 076 { 077 return Long.valueOf(decodeUTF8(getData())); 078 } 079}