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.txn;

LockType is a type safe enumeration of all lock types. Methods on LockType objects can be used to determine whether a type conflicts with another type or can be upgraded to another type.
 
 public class LockType {

    
Lock types. Indexes must be kept manually synchronized in the matrixes below.
 
     public static final LockType READ =
         new LockType(0, false"READ");
     public static final LockType WRITE =
         new LockType(1, true"WRITE");
     public static final LockType RANGE_READ =
         new LockType(2, false"RANGE_READ");
     public static final LockType RANGE_WRITE =
         new LockType(3, true"RANGE_WRITE");
     public static final LockType RANGE_INSERT =
         new LockType(4, false"RANGE_INSERT");

    
NONE is used for requesting a dirty read and does not appear in the conflict or upgrade matrices.
 
     public static final LockType NONE =
         new LockType(5, false"NONE");

    
RESTART is used for waiting for a restart and does not appear in the conflict or upgrade matrices.
 
     public static final LockType RESTART =
         new LockType(6, false"RESTART");

    
Whenever the conflict matrix is changed be sure to update this. For every type that can cause a RESTART result call setCausesRestart. This could have been determined programmatically but I chose to maintain it manually to avoid extra code size.
 
     static {
         .setCausesRestart();
         .setCausesRestart();
     }

    
Lock conflict matrix.

 
     private static LockConflict[][] conflictMatrix = {
         { // READ is held and there is a request for:
             .,   // READ
             .,   // WRITE
             .,   // RANGE_READ
             .,   // RANGE_WRITE
             .,   // RANGE_INSERT
         },
         { // WRITE is held and there is a request for:
             .,   // READ
             .,   // WRITE
             .,   // RANGE_READ
             .,   // RANGE_WRITE
             .,   // RANGE_INSERT
         },
         { // RANGE_READ is held and there is a request for:
             .,   // READ
             .,   // WRITE
             .,   // RANGE_READ
             .,   // RANGE_WRITE
             .,   // RANGE_INSERT
         },
         { // RANGE_WRITE is held and there is a request for:
             .,   // READ
             .,   // WRITE
             .,   // RANGE_READ
             .,   // RANGE_WRITE
             .,   // RANGE_INSERT
         },
         { // RANGE_INSERT is held and there is a request for:
             .,   // READ
             .,   // WRITE
             .// RANGE_READ
             .// RANGE_WRITE
             .,   // RANGE_INSERT
         },
     };

    
Lock upgrade matrix.

    private static LockUpgrade[][] upgradeMatrix = {
        { // READ is held and there is a request for:
            .,                  // READ
            .,             // WRITE
            .,          // RANGE_READ
            .,       // RANGE_WRITE
            .,                   // RANGE_INSERT
        },
        { // WRITE is held and there is a request for:
            .,                  // READ
            .,                  // WRITE
            .,         // RANGE_READ
            .,         // RANGE_WRITE
            .,                   // RANGE_INSERT
        },
        { // RANGE_READ is held and there is a request for:
            .,                  // READ
            .,       // WRITE
            .,                  // RANGE_READ
            .,       // RANGE_WRITE
            .,                   // RANGE_INSERT
        },
        { // RANGE_WRITE is held and there is a request for:
            .,                  // READ
            .,                  // WRITE
            .,                  // RANGE_READ
            .,                  // RANGE_WRITE
            .,                   // RANGE_INSERT
        },
        { // RANGE_INSERT is held and there is a request for:
            .,                   // READ
            .,                   // WRITE
            .,                   // RANGE_READ
            .,                   // RANGE_WRITE
            .,                  // RANGE_INSERT
        },
    };
    private int index;
    private boolean write;
    private String name;
    private boolean causesRestart;

    
No lock types can be defined outside this class.
    private LockType(int indexboolean writeString name) {
        this. = index;
        this. = write;
        this. = name;
    }

    
Returns true if this is a WRITE or RANGE_WRITE lock. For RANGE_INSERT, false is returned because RANGE_INSERT is used to lock the key following the insertion key, not the insertion key itself.
    public final boolean isWriteLock() {
        return ;
    }

    
Specifies that when this type is requested it can result in LockGrantType.RESTART.
    private void setCausesRestart() {
         = true;
    }

    
Returns whether when this type is requested it can result in LockGrantType.RESTART.
    final boolean getCausesRestart() {
        return ;
    }

    
Returns the LockConfict that results when this lock type is held and the given lock type is requested by another locker.
    LockConflict getConflict(LockType requestedType) {
        return [][requestedType.index];
    }

    
Returns the LockUpgrade that results when this lock type is held and the given lock type is requested by the same locker.

For the returned LockUpgrade object, getIllegal will never return true because this method fires an assertion if getIllegal returns true.

    LockUpgrade getUpgrade(LockType requestedType) {
        LockUpgrade upgrade = [][requestedType.index];
        assert !upgrade.getIllegal() : toString() + " to " + requestedType;
        return upgrade;
    }
    @Override
    public String toString() {
        return ;
    }
New to GrepCode? Check out our FAQ X