Skip to content

Commit 76a631b

Browse files
committed
api: Remove unused ServiceProviders.load()
load() unused since c8a94d1 in 2020.
1 parent 9903488 commit 76a631b

File tree

3 files changed

+20
-40
lines changed

3 files changed

+20
-40
lines changed

api/src/main/java/io/grpc/InternalServiceProviders.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ public final class InternalServiceProviders {
2424
private InternalServiceProviders() {
2525
}
2626

27-
/**
28-
* Accessor for method.
29-
*/
30-
public static <T> T load(
31-
Class<T> klass,
32-
Iterable<Class<?>> hardcoded,
33-
ClassLoader classLoader,
34-
PriorityAccessor<T> priorityAccessor) {
35-
return ServiceProviders.load(klass, hardcoded, classLoader, priorityAccessor);
36-
}
37-
3827
/**
3928
* Accessor for method.
4029
*/

api/src/main/java/io/grpc/ServiceProviders.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ private ServiceProviders() {
2929
// do not instantiate
3030
}
3131

32-
/**
33-
* If this is not Android, returns the highest priority implementation of the class via
34-
* {@link ServiceLoader}.
35-
* If this is Android, returns an instance of the highest priority class in {@code hardcoded}.
36-
*/
37-
public static <T> T load(
38-
Class<T> klass,
39-
Iterable<Class<?>> hardcoded,
40-
ClassLoader cl,
41-
PriorityAccessor<T> priorityAccessor) {
42-
List<T> candidates = loadAll(klass, hardcoded, cl, priorityAccessor);
43-
if (candidates.isEmpty()) {
44-
return null;
45-
}
46-
return candidates.get(0);
47-
}
48-
4932
/**
5033
* If this is not Android, returns all available implementations discovered via
5134
* {@link ServiceLoader}.

api/src/test/java/io/grpc/ServiceProvidersTest.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public void contextClassLoaderProvider() {
6969
Thread.currentThread().setContextClassLoader(rcll);
7070
assertEquals(
7171
Available7Provider.class,
72-
ServiceProviders.load(
73-
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR).getClass());
72+
load(ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR).getClass());
7473
} finally {
7574
Thread.currentThread().setContextClassLoader(ccl);
7675
}
@@ -85,8 +84,7 @@ public void noProvider() {
8584
serviceFile,
8685
"io/grpc/ServiceProvidersTestAbstractProvider-doesNotExist.txt");
8786
Thread.currentThread().setContextClassLoader(cl);
88-
assertNull(ServiceProviders.load(
89-
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR));
87+
assertNull(load(ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR));
9088
} finally {
9189
Thread.currentThread().setContextClassLoader(ccl);
9290
}
@@ -98,8 +96,7 @@ public void multipleProvider() throws Exception {
9896
"io/grpc/ServiceProvidersTestAbstractProvider-multipleProvider.txt");
9997
assertSame(
10098
Available7Provider.class,
101-
ServiceProviders.load(
102-
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR).getClass());
99+
load(ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR).getClass());
103100

104101
List<ServiceProvidersTestAbstractProvider> providers = ServiceProviders.loadAll(
105102
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR);
@@ -116,16 +113,15 @@ public void unavailableProvider() {
116113
"io/grpc/ServiceProvidersTestAbstractProvider-unavailableProvider.txt");
117114
assertEquals(
118115
Available7Provider.class,
119-
ServiceProviders.load(
120-
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR).getClass());
116+
load(ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR).getClass());
121117
}
122118

123119
@Test
124120
public void unknownClassProvider() {
125121
ClassLoader cl = new ReplacingClassLoader(getClass().getClassLoader(), serviceFile,
126122
"io/grpc/ServiceProvidersTestAbstractProvider-unknownClassProvider.txt");
127123
try {
128-
ServiceProviders.load(
124+
ServiceProviders.loadAll(
129125
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR);
130126
fail("Exception expected");
131127
} catch (ServiceConfigurationError e) {
@@ -140,7 +136,7 @@ public void exceptionSurfacedToCaller_failAtInit() {
140136
try {
141137
// Even though there is a working provider, if any providers fail then we should fail
142138
// completely to avoid returning something unexpected.
143-
ServiceProviders.load(
139+
ServiceProviders.loadAll(
144140
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR);
145141
fail("Expected exception");
146142
} catch (ServiceConfigurationError expected) {
@@ -154,7 +150,7 @@ public void exceptionSurfacedToCaller_failAtPriority() {
154150
"io/grpc/ServiceProvidersTestAbstractProvider-failAtPriorityProvider.txt");
155151
try {
156152
// The exception should be surfaced to the caller
157-
ServiceProviders.load(
153+
ServiceProviders.loadAll(
158154
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR);
159155
fail("Expected exception");
160156
} catch (FailAtPriorityProvider.PriorityException expected) {
@@ -168,7 +164,7 @@ public void exceptionSurfacedToCaller_failAtAvailable() {
168164
"io/grpc/ServiceProvidersTestAbstractProvider-failAtAvailableProvider.txt");
169165
try {
170166
// The exception should be surfaced to the caller
171-
ServiceProviders.load(
167+
ServiceProviders.loadAll(
172168
ServiceProvidersTestAbstractProvider.class, NO_HARDCODED, cl, ACCESSOR);
173169
fail("Expected exception");
174170
} catch (FailAtAvailableProvider.AvailableException expected) {
@@ -244,6 +240,18 @@ class RandomClass {}
244240
assertFalse(candidates.iterator().hasNext());
245241
}
246242

243+
private static <T> T load(
244+
Class<T> klass,
245+
Iterable<Class<?>> hardcoded,
246+
ClassLoader cl,
247+
PriorityAccessor<T> priorityAccessor) {
248+
List<T> candidates = ServiceProviders.loadAll(klass, hardcoded, cl, priorityAccessor);
249+
if (candidates.isEmpty()) {
250+
return null;
251+
}
252+
return candidates.get(0);
253+
}
254+
247255
private static class BaseProvider extends ServiceProvidersTestAbstractProvider {
248256
private final boolean isAvailable;
249257
private final int priority;

0 commit comments

Comments
 (0)