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