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.ChannelCredentials; 20 import io.grpc.Internal; 21 import io.grpc.ManagedChannelProvider; 22 import io.grpc.internal.SharedResourcePool; 23 import io.netty.channel.unix.DomainSocketAddress; 24 import java.net.SocketAddress; 25 import java.util.Collection; 26 import java.util.Collections; 27 28 /** Provider for {@link NettyChannelBuilder} instances for UDS channels. */ 29 @Internal 30 public final class UdsNettyChannelProvider extends ManagedChannelProvider { 31 32 @Override isAvailable()33 public boolean isAvailable() { 34 return (Utils.EPOLL_DOMAIN_CLIENT_CHANNEL_TYPE != null); 35 } 36 37 @Override priority()38 public int priority() { 39 return 3; 40 } 41 42 @Override builderForAddress(String name, int port)43 public NettyChannelBuilder builderForAddress(String name, int port) { 44 throw new AssertionError("NettyChannelProvider shadows this implementation"); 45 } 46 47 @Override builderForTarget(String target)48 public NettyChannelBuilder builderForTarget(String target) { 49 throw new AssertionError("NettyChannelProvider shadows this implementation"); 50 } 51 52 @Override newChannelBuilder(String target, ChannelCredentials creds)53 public NewChannelBuilderResult newChannelBuilder(String target, ChannelCredentials creds) { 54 NewChannelBuilderResult result = new NettyChannelProvider().newChannelBuilder(target, creds); 55 if (result.getChannelBuilder() != null) { 56 ((NettyChannelBuilder) result.getChannelBuilder()) 57 .eventLoopGroupPool(SharedResourcePool.forResource(Utils.DEFAULT_WORKER_EVENT_LOOP_GROUP)) 58 .channelType(Utils.EPOLL_DOMAIN_CLIENT_CHANNEL_TYPE); 59 } 60 return result; 61 } 62 63 @Override getSupportedSocketAddressTypes()64 protected Collection<Class<? extends SocketAddress>> getSupportedSocketAddressTypes() { 65 return Collections.singleton(DomainSocketAddress.class); 66 } 67 } 68