Admin Interface provides a class of services for exposing the overall state of gRPC activity in a given binary. It aims to be a convenient API that provides available admin services.
| 35 | * services. |
| 36 | */ |
| 37 | @ExperimentalApi("https://github.com/grpc/grpc-java/issues/7929") |
| 38 | @ThreadSafe |
| 39 | public final class AdminInterface { |
| 40 | private static final int DEFAULT_CHANNELZ_MAX_PAGE_SIZE = 100; |
| 41 | private static final Logger logger = Logger.getLogger(AdminInterface.class.getName()); |
| 42 | |
| 43 | // Do not instantiate. |
| 44 | private AdminInterface() {} |
| 45 | |
| 46 | /** |
| 47 | * Returns a list of gRPC's built-in admin services. |
| 48 | * |
| 49 | * @return list of standard admin services |
| 50 | */ |
| 51 | public static List<ServerServiceDefinition> getStandardServices() { |
| 52 | List<ServerServiceDefinition> services = new ArrayList<>(); |
| 53 | services.add(ChannelzService.newInstance(DEFAULT_CHANNELZ_MAX_PAGE_SIZE).bindService()); |
| 54 | BindableService csds = null; |
| 55 | try { |
| 56 | Class<?> clazz = Class.forName("io.grpc.xds.CsdsService"); |
| 57 | Method m = clazz.getMethod("newInstance"); |
| 58 | csds = (BindableService) m.invoke(null); |
| 59 | } catch (ClassNotFoundException e) { |
| 60 | logger.log(Level.FINE, "Unable to find CSDS service", e); |
| 61 | } catch (NoSuchMethodException e) { |
| 62 | logger.log(Level.FINE, "Unable to load CSDS service", e); |
| 63 | } catch (IllegalAccessException e) { |
| 64 | logger.log(Level.FINE, "Unable to load CSDS service", e); |
| 65 | } catch (InvocationTargetException e) { |
| 66 | logger.log(Level.FINE, "Unable to load CSDS service", e); |
| 67 | } |
| 68 | if (csds != null) { |
| 69 | services.add(csds.bindService()); |
| 70 | } |
| 71 | return Collections.unmodifiableList(services); |
| 72 | } |
| 73 | } |