001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.procedure2; 019 020import org.apache.yetus.audience.InterfaceAudience; 021 022/** 023 * Interface to get status of a Lock without getting access to acquire/release lock. Currently used 024 * in MasterProcedureScheduler where we want to give Queues access to lock's status for scheduling 025 * purposes, but not the ability to acquire/release it. 026 */ 027@InterfaceAudience.Private 028public interface LockStatus { 029 030 /** 031 * Return whether this lock has already been held, 032 * <p/> 033 * Notice that, holding the exclusive lock or shared lock are both considered as locked, i.e, this 034 * method usually equals to {@code hasExclusiveLock() || getSharedLockCount() > 0}. 035 */ 036 default boolean isLocked() { 037 return hasExclusiveLock() || getSharedLockCount() > 0; 038 } 039 040 /** 041 * Whether the exclusive lock has been held. 042 */ 043 boolean hasExclusiveLock(); 044 045 /** 046 * Return true if the procedure itself holds the exclusive lock, or any ancestors of the give 047 * procedure hold the exclusive lock. 048 */ 049 boolean hasLockAccess(Procedure<?> proc); 050 051 /** 052 * Get the procedure which holds the exclusive lock. 053 */ 054 Procedure<?> getExclusiveLockOwnerProcedure(); 055 056 /** 057 * Return the id of the procedure which holds the exclusive lock, if exists. Or a negative value 058 * which means no one holds the exclusive lock. 059 * <p/> 060 * Notice that, in HBase, we assume that the procedure id is positive, or at least non-negative. 061 */ 062 default long getExclusiveLockProcIdOwner() { 063 Procedure<?> proc = getExclusiveLockOwnerProcedure(); 064 return proc != null ? proc.getProcId() : -1L; 065 } 066 067 /** 068 * Get the number of procedures which hold the shared lock. 069 */ 070 int getSharedLockCount(); 071}