2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.procedure2
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
22 import java
.util
.concurrent
.TimeUnit
;
23 import org
.apache
.yetus
.audience
.InterfaceAudience
;
26 * Keep track of the runnable procedures
28 @InterfaceAudience.Private
29 public interface ProcedureScheduler
{
41 * In case the class is blocking on poll() waiting for items to be added,
42 * this method should awake poll() and poll() should return.
47 * Inserts the specified element at the front of this queue.
48 * @param proc the Procedure to add
50 void addFront(Procedure proc
);
53 * Inserts the specified element at the front of this queue.
54 * @param proc the Procedure to add
55 * @param notify whether need to notify worker
57 void addFront(Procedure proc
, boolean notify
);
60 * Inserts all elements in the iterator at the front of this queue.
62 void addFront(Iterator
<Procedure
> procedureIterator
);
65 * Inserts the specified element at the end of this queue.
66 * @param proc the Procedure to add
68 void addBack(Procedure proc
);
71 * Inserts the specified element at the end of this queue.
72 * @param proc the Procedure to add
73 * @param notify whether need to notify worker
75 void addBack(Procedure proc
, boolean notify
);
78 * The procedure can't run at the moment.
79 * add it back to the queue, giving priority to someone else.
80 * @param proc the Procedure to add back to the list
82 void yield(Procedure proc
);
85 * The procedure in execution completed.
86 * This can be implemented to perform cleanups.
87 * @param proc the Procedure that completed the execution.
89 void completionCleanup(Procedure proc
);
92 * @return true if there are procedures available to process, otherwise false.
94 boolean hasRunnables();
97 * Fetch one Procedure from the queue
98 * @return the Procedure to execute, or null if nothing present.
103 * Fetch one Procedure from the queue
104 * @param timeout how long to wait before giving up, in units of unit
105 * @param unit a TimeUnit determining how to interpret the timeout parameter
106 * @return the Procedure to execute, or null if nothing present.
108 Procedure
poll(long timeout
, TimeUnit unit
);
114 List
<LockedResource
> getLocks();
117 * @return {@link LockedResource} for resource of specified type & name. null if resource is not
120 LockedResource
getLockResource(LockedResourceType resourceType
, String resourceName
);
123 * Returns the number of elements in this queue.
124 * @return the number of elements in this queue.
129 * Clear current state of scheduler such that it is equivalent to newly created scheduler.
130 * Used for testing failure and recovery. To emulate server crash/restart,
131 * {@link ProcedureExecutor} resets its own state and calls clear() on scheduler.