• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc.internal;
18 
19 import io.grpc.InternalChannelz.SocketStats;
20 import io.grpc.InternalInstrumented;
21 import java.io.IOException;
22 import java.util.List;
23 import javax.annotation.concurrent.ThreadSafe;
24 
25 /**
26  * An object that accepts new incoming connections. This would commonly encapsulate a bound socket
27  * that {@code accept()}s new connections.
28  */
29 @ThreadSafe
30 public interface InternalServer {
31   /**
32    * Starts transport. Implementations must not call {@code listener} until after {@code start()}
33    * returns. The method only returns after it has done the equivalent of bind()ing, so it will be
34    * able to service any connections created after returning.
35    *
36    * @param listener non-{@code null} listener of server events
37    * @throws IOException if unable to bind
38    */
start(ServerListener listener)39   void start(ServerListener listener) throws IOException;
40 
41   /**
42    * Initiates an orderly shutdown of the server. Existing transports continue, but new transports
43    * will not be created (once {@link ServerListener#serverShutdown()} callback is called). This
44    * method may only be called once.
45    */
shutdown()46   void shutdown();
47 
48   /**
49    * Returns what underlying port the server is listening on, or -1 if the port number is not
50    * available or does not make sense.
51    */
getPort()52   int getPort();
53 
54   /**
55    * Returns the listen sockets of this server. May return an empty list but never returns null.
56    */
getListenSockets()57   List<InternalInstrumented<SocketStats>> getListenSockets();
58 }
59