001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Dragos Mihalache
016 */
017package org.nuxeo.ecm.core.uidgen;
018
019/**
020 * UID Sequencer interface defines a method to retrieve next ids based on a given key.
021 */
022public interface UIDSequencer {
023
024    /**
025     * Gets the sequencer name.
026     *
027     * @since 7.4
028     */
029    String getName();
030
031    /**
032     * Sets the sequencer name.
033     *
034     * @since 7.4
035     */
036    void setName(String name);
037
038    /**
039     * Init Sequencer
040     *
041     * @since 7.3
042     */
043    void init();
044
045    /**
046     * Initializes the sequencer with the given key to at least the given id.
047     * <p>
048     * A sequence can only be incremented, so if its current id is greater than the given id the sequence won't be
049     * decremented to reach the given id.
050     *
051     * @since 7.4
052     */
053    void initSequence(String key, int id);
054
055    /**
056     * For the given key returns the incremented UID which is also stored in the same sequence entry. This is a
057     * "one time use" function for a document.
058     *
059     * @param key
060     * @return
061     */
062    int getNext(String key);
063
064    /**
065     * Cleanup callback
066     *
067     * @since 7.3
068     */
069    void dispose();
070
071}