/* JUG Java Uuid Generator
 *
 * Copyright (c) 2002- Tatu Saloranta, tatu.saloranta@iki.fi
 *
 * Licensed under the License specified in the file LICENSE which is
 * included with the source code.
 * You may not use this file except in compliance with the License.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.wso2.carbon.uuid.generator;

import java.io.IOException;

/**
 * This is the API for utility classes optionally used by {@link UUIDTimer} to
 * ensure that timestamp values used for generating time/location-based UUIDs
 * are monotonically increasing, as well as that only one such generator
 * is ever used on a single system, even in presence of multiple JVMs.
 *<p>
 * The default implementation used by JUG is
 * {@link com.fasterxml.uuid.ext.FileBasedTimestampSynchronizer}.
 */
public abstract class TimestampSynchronizer
{
    protected TimestampSynchronizer() { }

    /**
     * Initialization method is will be called on an instance by
     * {@link UUIDTimer} right after it's been configured with one.
     * At this point the implementation instance should have been properly
     * configured, and should be able to determine the first legal timestamp
     * value (return value). Method should also initialize any locking that
     * it does (if any), such as locking files it needs.
     *<p>
     * Return value thus indicates the lowest initial time value that can
     * be used by the caller that can not have been used by previous
     * incarnations of the UUID generator (assuming instance was able to
     * find properly persisted data to figure that out).
     * However, caller also needs to make sure that it will
     * call {@link #update} when it actually needs the time stamp for the
     * first time,
     * since this method can not allocate timestamps beyond this initial
     * value at this point.
     *
     * @return First (and last) legal timestamp to use; <code>0L</code> if it
     *  can not
     *   determine it and caller can use whatever value (current timestamp)
     *   it has access to.
     */
    protected abstract long initialize()
        throws IOException;

    /**
     * Method {@link UUIDTimer} will call if this synchronizer object is
     * being replaced by another synchronizer (or removed, that is, no
     * more synchronization is to be done). It will not be called if JVM
     * terminates.
     */
    protected abstract void deactivate()
        throws IOException;

    /**
     * Method called by {@link UUIDTimer} to indicate that it has generated
     * a timestamp value that is beyond last legal timestamp value.
     * The method should only return once it has "locked" specified timestamp
     * value (and possible additional ones).
     *
     * @param now Timestamp value caller wants to use, and that the
     *   synchronizer is asked to protect.
     *
     * @return First timestamp value that can NOT be used by the caller;
     *    has to be higher than the input timestamp value
     */
    protected abstract long update(long now)
        throws IOException;
}

@@ -1,205 +1,187 @@
 /*
- JUG Java Uuid Generator%0A *%0A * Copyright (c) 2002- Tatu Saloranta, tatu.saloranta@iki.fi%0A *%0A * Licensed under the License specified in the file LICENSE which is%0A * included with the source code.%0A * Y
+%0A *  Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A *  WSO2 Inc. licenses this file to you under the Apache License,%0A *  Version 2.0 (the %22License%22); y
 ou m
@@ -207,16 +207,20 @@
 e except
+%0A * 
  in comp
@@ -244,16 +244,112 @@
 icense.%0A
+ *  You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A
  *%0A * Un
@@ -404,16 +404,19 @@
 writing,
+%0A *
  softwar
@@ -416,19 +416,16 @@
 software
-%0A *
  distrib
@@ -467,16 +467,19 @@
 ed on an
+%0A *
  %22AS IS%22
@@ -485,19 +485,16 @@
 %22 BASIS,
-%0A *
  WITHOUT
@@ -525,16 +525,19 @@
 S OF ANY
+%0A *
  KIND, e
@@ -561,19 +561,17 @@
 implied.
-%0A *
+ 
  See the
@@ -586,16 +586,19 @@
  for the
+%0A *
  specifi
@@ -633,19 +633,16 @@
 ions and
-%0A *
  limitat
@@ -645,16 +645,19 @@
 itations
+%0A *
  under t
@@ -672,17 +672,16 @@
 se.%0A */%0A
-%0A
 package 
@@ -1049,16 +1049,17 @@
 JVMs.%0A *
+ 
 %3Cp%3E%0A * T
@@ -1216,10 +1216,11 @@
 izer
+ %7B
 %0A
-%7B
 %0A   
@@ -1255,16 +1255,21 @@
 izer() %7B
+%0A%0A   
  %7D%0A%0A    
@@ -1696,16 +1696,17 @@
 .%0A     *
+ 
 %3Cp%3E%0A    
@@ -2319,17 +2319,16 @@
 t%0A     *
- 
  can not
@@ -2334,18 +2334,16 @@
 t%0A     *
-  
  determi
@@ -2408,18 +2408,16 @@
 )%0A     *
-  
  it has 
@@ -2476,32 +2476,36 @@
 alize()%0A        
+    
 throws IOExcepti
@@ -2802,32 +2802,36 @@
 ivate()%0A        
+    
 throws IOExcepti
@@ -3191,16 +3191,25 @@
 e%0A     *
+         
    synch
@@ -3237,23 +3237,16 @@
 rotect.%0A
-     *%0A
      * @
@@ -3316,19 +3316,16 @@
 ;%0A     *
-   
  has to 
@@ -3418,16 +3418,20 @@
 ng now)%0A
+    
         

Add license header