Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.je;
  
 import java.util.UUID;
 
Defines an opaque token that can be used to identify a specific transaction commit in a replicated environment. It's unique relative to its environment.

Since CommitTokens identify a point in the serialized transaction schedule created on the master, it's meaningful to compare commit tokens, as described in the compareTo(com.sleepycat.je.CommitToken) method below. CommitTokens are obtained from Transaction.getCommitToken()

 
 public class CommitToken implements SerializableComparable<CommitToken> {
 
     private static final long serialVersionUID = 1L;
     private final UUID repenvUUID;
     private final long vlsn;

    

Parameters:
repenvUUID identifies the replicated environment associated with the vlsn
vlsn the vlsn representing the state of the database.
Hidden:
For internal use only. Creates a CommitToken suitable for use in a consistency policy.
 
     public CommitToken(UUID repenvUUIDlong vlsn) {
         if (repenvUUID == null) {
             throw EnvironmentFailureException.unexpectedState
                 ("The UUID must not be null");
         }
 
         if (vlsn == ..getSequence()) {
             throw EnvironmentFailureException.unexpectedState
                 ("The vlsn must not be null");
         }
 
         this. = repenvUUID;
         this. = vlsn;
     }
 
     public UUID getRepenvUUID() {
         return ;
     }
 
     public long getVLSN() {
         return ;
     }
 
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
         result = prime * result
                 + (( == null) ? 0 : .hashCode());
         result = prime * result + (int) ( ^ ( >>> 32));
         return result;
     }
 
     @Override
     public boolean equals(Object obj) {
         if (this == obj) {
             return true;
         }
         if (obj == null) {
             return false;
         }
         if (!(obj instanceof CommitToken)) {
             return false;
         }
         CommitToken other = (CommitTokenobj;
         if ( == null) {
             if (other.repenvUUID != null) {
                 return false;
             }
         } else if (!.equals(other.repenvUUID)) {
             return false;
         }
         if ( != other.vlsn) {
             return false;
         }
         return true;
     }

    
Implements the Comparable interface. Note that it's not meaningful to compare commit tokens across environments, since they represent states in unrelated serialized transaction streams.

CommitToken(1) < CommitToken(2) implies that CommitToken(1) represents a state of the database that preceded the state defined by CommitToken(2).

Throws:
java.lang.IllegalArgumentException if two tokens from different environments are compared.
    public int compareTo(CommitToken other) {
        if (! .equals(other.repenvUUID)) {
            throw new IllegalArgumentException
            ("Comparisons across environments are not meaningful. " +
             "This environment: " +  +
             " other environment: " + other.getRepenvUUID());
        }
        final long compare =  - other.vlsn;
        return (compare < 0) ? -1 : ((compare == 0) ? 0 : 1);
    }
    @Override
    public String toString() {
        return "UUID: " +  + " VLSN: " + ;
    }
New to GrepCode? Check out our FAQ X