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