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 java.util.Collections; 021import java.util.List; 022import org.apache.yetus.audience.InterfaceAudience; 023import org.apache.yetus.audience.InterfaceStability; 024 025/** 026 * Simple scheduler for procedures 027 */ 028@InterfaceAudience.Private 029@InterfaceStability.Evolving 030public class SimpleProcedureScheduler extends AbstractProcedureScheduler { 031 private final ProcedureDeque runnables = new ProcedureDeque(); 032 033 @Override 034 protected void enqueue(final Procedure procedure, final boolean addFront) { 035 if (addFront) { 036 runnables.addFirst(procedure); 037 } else { 038 runnables.addLast(procedure); 039 } 040 } 041 042 @Override 043 protected Procedure dequeue() { 044 return runnables.poll(); 045 } 046 047 @Override 048 public void clear() { 049 schedLock(); 050 try { 051 runnables.clear(); 052 } finally { 053 schedUnlock(); 054 } 055 } 056 057 @Override 058 public void yield(final Procedure proc) { 059 addBack(proc); 060 } 061 062 @Override 063 public boolean queueHasRunnables() { 064 return runnables.size() > 0; 065 } 066 067 @Override 068 public int queueSize() { 069 return runnables.size(); 070 } 071 072 @Override 073 public void completionCleanup(Procedure proc) { 074 } 075 076 @Override 077 public List<LockedResource> getLocks() { 078 return Collections.emptyList(); 079 } 080 081 @Override 082 public LockedResource getLockResource(LockedResourceType resourceType, String resourceName) { 083 return null; 084 } 085}