下面列出了io.grpc.ServiceDescriptor#getMethods ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Gets all method names from the given service descriptor.
*
* @param serviceDescriptor The service descriptor to get the names from.
* @return The newly created and sorted list of the method names.
*/
protected List<String> collectMethodNamesForService(final ServiceDescriptor serviceDescriptor) {
final List<String> methods = new ArrayList<>();
for (final MethodDescriptor<?, ?> grpcMethod : serviceDescriptor.getMethods()) {
methods.add(extractMethodName(grpcMethod));
}
methods.sort(String.CASE_INSENSITIVE_ORDER);
return methods;
}
/**
* Gets all method names from the given service descriptor.
*
* @param serviceDescriptor The service descriptor to get the names from.
* @return The newly created and sorted list of the method names.
*/
protected List<String> collectMethodNamesForService(final ServiceDescriptor serviceDescriptor) {
final List<String> methods = new ArrayList<>();
for (final MethodDescriptor<?, ?> grpcMethod : serviceDescriptor.getMethods()) {
methods.add(extractMethodName(grpcMethod));
}
methods.sort(String.CASE_INSENSITIVE_ORDER);
return methods;
}
/**
* Set the given access predicate for the all methods of the given service. This will replace previously set
* predicates.
*
* @param service The service to protect with a custom check.
* @param predicate The predicate used to check the {@link Authentication}.
* @return This instance for chaining.
* @see #setDefault(AccessPredicate)
*/
public ManualGrpcSecurityMetadataSource set(final ServiceDescriptor service, final AccessPredicate predicate) {
requireNonNull(service, "service");
final Collection<ConfigAttribute> wrappedPredicate = wrap(predicate);
for (final MethodDescriptor<?, ?> method : service.getMethods()) {
this.accessMap.put(method, wrappedPredicate);
}
return this;
}
/**
* Removes all access predicates for the all methods of the given service. After that, the default will be used for
* those methods.
*
* @param service The service to protect with only the default.
* @return This instance for chaining.
* @see #setDefault(AccessPredicate)
*/
public ManualGrpcSecurityMetadataSource remove(final ServiceDescriptor service) {
requireNonNull(service, "service");
for (final MethodDescriptor<?, ?> method : service.getMethods()) {
this.accessMap.remove(method);
}
return this;
}
/**
* Set the given access predicate for the all methods of the given service. This will replace previously set
* predicates.
*
* @param service The service to protect with a custom check.
* @param predicate The predicate used to check the {@link Authentication}.
* @return This instance for chaining.
* @see #setDefault(AccessPredicate)
*/
public ManualGrpcSecurityMetadataSource set(final ServiceDescriptor service, final AccessPredicate predicate) {
requireNonNull(service, "service");
final Collection<ConfigAttribute> wrappedPredicate = wrap(predicate);
for (final MethodDescriptor<?, ?> method : service.getMethods()) {
this.accessMap.put(method, wrappedPredicate);
}
return this;
}
/**
* Removes all access predicates for the all methods of the given service. After that, the default will be used for
* those methods.
*
* @param service The service to protect with only the default.
* @return This instance for chaining.
* @see #setDefault(AccessPredicate)
*/
public ManualGrpcSecurityMetadataSource remove(final ServiceDescriptor service) {
requireNonNull(service, "service");
for (final MethodDescriptor<?, ?> method : service.getMethods()) {
this.accessMap.remove(method);
}
return this;
}
/**
* Pre-registers the all methods provided by the given service. This will initialize all default counters and timers
* for those methods.
*
* @param service The service to initialize the meters for.
* @see #preregisterMethod(MethodDescriptor)
*/
public void preregisterService(final ServiceDescriptor service) {
for (final MethodDescriptor<?, ?> method : service.getMethods()) {
preregisterMethod(method);
}
}
/**
* Pre-registers the all methods provided by the given service. This will initialize all default counters and timers
* for those methods.
*
* @param service The service to initialize the meters for.
* @see #preregisterMethod(MethodDescriptor)
*/
public void preregisterService(final ServiceDescriptor service) {
for (final MethodDescriptor<?, ?> method : service.getMethods()) {
preregisterMethod(method);
}
}