HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-procedure / src / main / java / org / apache / hadoop / hbase / procedure2 / ProcedureScheduler.java
blob72b2b284ca19c40eba02be79910562ed781dc830
1 /**
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;
25 /**
26 * Keep track of the runnable procedures
28 @InterfaceAudience.Private
29 public interface ProcedureScheduler {
30 /**
31 * Start the scheduler
33 void start();
35 /**
36 * Stop the scheduler
38 void stop();
40 /**
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.
44 void signalAll();
46 /**
47 * Inserts the specified element at the front of this queue.
48 * @param proc the Procedure to add
50 void addFront(Procedure proc);
52 /**
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);
59 /**
60 * Inserts all elements in the iterator at the front of this queue.
62 void addFront(Iterator<Procedure> procedureIterator);
64 /**
65 * Inserts the specified element at the end of this queue.
66 * @param proc the Procedure to add
68 void addBack(Procedure proc);
70 /**
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);
77 /**
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);
84 /**
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);
91 /**
92 * @return true if there are procedures available to process, otherwise false.
94 boolean hasRunnables();
96 /**
97 * Fetch one Procedure from the queue
98 * @return the Procedure to execute, or null if nothing present.
100 Procedure poll();
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);
111 * List lock queues.
112 * @return the locks
114 List<LockedResource> getLocks();
117 * @return {@link LockedResource} for resource of specified type & name. null if resource is not
118 * locked.
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.
126 int size();
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.
133 void clear();