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