View Javadoc

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
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
17   */
18  package org.apache.hadoop.hbase.ipc;
19  
20  import org.apache.hadoop.classification.InterfaceAudience;
21  import org.apache.hadoop.classification.InterfaceStability;
22  
23  import java.io.IOException;
24  import java.net.InetSocketAddress;
25  
26  /**
27   * An interface for RPC request scheduling algorithm.
28   */
29  @InterfaceAudience.Private
30  @InterfaceStability.Evolving
31  public interface RpcScheduler {
32  
33    /** Exposes runtime information of a {@code RpcServer} that a {@code RpcScheduler} may need. */
34    interface Context {
35      InetSocketAddress getListenerAddress();
36    }
37  
38    /**
39     * Does some quick initialization. Heavy tasks (e.g. starting threads) should be
40     * done in {@link #start()}. This method is called before {@code start}.
41     *
42     * @param context provides methods to retrieve runtime information from
43     */
44    void init(Context context);
45  
46    /**
47     * Prepares for request serving. An implementation may start some handler threads here.
48     */
49    void start();
50  
51    /** Stops serving new requests. */
52    void stop();
53  
54    /**
55     * Dispatches an RPC request asynchronously. An implementation is free to choose to process the
56     * request immediately or delay it for later processing.
57     *
58     * @param task the request to be dispatched
59     */
60    void dispatch(CallRunner task) throws IOException, InterruptedException;
61  
62    /** Retrieves length of the general queue for metrics. */
63    int getGeneralQueueLength();
64  
65    /** Retrieves length of the priority queue for metrics. */
66    int getPriorityQueueLength();
67  
68    /** Retrieves length of the replication queue for metrics. */
69    int getReplicationQueueLength();
70  }