001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Dragos Mihalache
018 */
019package org.nuxeo.ecm.core.uidgen;
020
021/**
022 * UID Sequencer interface defines a method to retrieve next ids based on a given key.
023 */
024public interface UIDSequencer {
025
026    /**
027     * Gets the sequencer name.
028     *
029     * @since 7.4
030     */
031    String getName();
032
033    /**
034     * Sets the sequencer name.
035     *
036     * @since 7.4
037     */
038    void setName(String name);
039
040    /**
041     * Init Sequencer
042     *
043     * @since 7.3
044     */
045    void init();
046
047    /**
048     * Initializes the sequencer with the given key to at least the given id.
049     * <p>
050     * A sequence can only be incremented, so if its current id is greater than the given id the sequence won't be
051     * decremented to reach the given id.
052     *
053     * @since 7.4
054     */
055    void initSequence(String key, int id);
056
057    /**
058     * For the given key returns the incremented UID which is also stored in the same sequence entry. This is a
059     * "one time use" function for a document.
060     *
061     * @param key
062     * @return
063     */
064    int getNext(String key);
065
066    /**
067     * Extends {@link UIDSequencer#getNext(java.lang.String)} to return a long value. This method is compatible
068     * with getNext in the integer range.
069     *
070     * @since 8.3
071     */
072    long getNextLong(String key);
073
074    /**
075     * Cleanup callback
076     *
077     * @since 7.3
078     */
079    void dispose();
080
081}