• 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.netty;
18 
19 import io.grpc.Internal;
20 import io.grpc.ServerCredentials;
21 import io.grpc.ServerProvider;
22 import java.net.InetSocketAddress;
23 
24 /** Provider for {@link NettyServerBuilder} instances. */
25 @Internal
26 public final class NettyServerProvider extends ServerProvider {
27 
28   @Override
isAvailable()29   protected boolean isAvailable() {
30     return true;
31   }
32 
33   @Override
priority()34   protected int priority() {
35     return 5;
36   }
37 
38   @Override
builderForPort(int port)39   protected NettyServerBuilder builderForPort(int port) {
40     return NettyServerBuilder.forPort(port);
41   }
42 
43   @Override
newServerBuilderForPort(int port, ServerCredentials creds)44   protected NewServerBuilderResult newServerBuilderForPort(int port, ServerCredentials creds) {
45     ProtocolNegotiators.FromServerCredentialsResult result = ProtocolNegotiators.from(creds);
46     if (result.error != null) {
47       return NewServerBuilderResult.error(result.error);
48     }
49     return NewServerBuilderResult.serverBuilder(
50         new NettyServerBuilder(new InetSocketAddress(port), result.negotiator));
51   }
52 }
53 
54