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