Skip to content

Commit 4e6e3c7

Browse files
committed
LocationService: do not cache resolvers by scheme
We want the ability for multiple resolvers to handle the same scheme in different scenarios. So we don't want to cache which resolver was used based only on scheme. Therefore, the getResolver method becomes the same as getHandler, doing the lookup every time. So we deprecate it.
1 parent 8846410 commit 4e6e3c7

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

src/main/java/org/scijava/io/location/DefaultLocationService.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
package org.scijava.io.location;
3434

3535
import java.net.URI;
36-
import java.util.HashMap;
37-
import java.util.Map;
3836

3937
import org.scijava.plugin.AbstractHandlerService;
4038
import org.scijava.plugin.Plugin;
@@ -50,11 +48,5 @@ public class DefaultLocationService extends
5048
AbstractHandlerService<URI, LocationResolver> implements
5149
LocationService
5250
{
53-
54-
private final Map<String, LocationResolver> resolvers = new HashMap<>();
55-
56-
@Override
57-
public LocationResolver getResolver(final URI uri) {
58-
return resolvers.computeIfAbsent(uri.getScheme(), u -> getHandler(uri));
59-
}
51+
// NB: No implementation needed.
6052
}

src/main/java/org/scijava/io/location/LocationService.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,11 @@ default Location resolve(URI uri) throws URISyntaxException {
8686
return resolver != null ? resolver.resolve(uri) : null;
8787
}
8888

89-
/**
90-
* Returns a {@link LocationResolver} capable of resolving URL like the one
91-
* provided to this method. Allows faster repeated resolving of similar URIs
92-
* without going through this service.
93-
*
94-
* @param uri the uri
95-
* @return the {@link LocationResolver} for this uri type, or
96-
* <code>null</code> if no resolver could be found.
97-
*/
98-
LocationResolver getResolver(URI uri);
89+
/** @deprecated Use {@link #getHandler(URI)} instead. */
90+
@Deprecated
91+
default LocationResolver getResolver(URI uri) {
92+
return getHandler(uri);
93+
}
9994

10095
// -- PTService methods --
10196

src/test/java/org/scijava/io/location/LocationServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void testResolve() throws URISyntaxException {
5555
final LocationService loc = ctx.getService(LocationService.class);
5656

5757
final URI uri = new File(new File(".").getAbsolutePath()).toURI();
58-
final LocationResolver res = loc.getResolver(uri);
58+
final LocationResolver res = loc.getHandler(uri);
5959

6060
assertTrue(res instanceof FileLocationResolver);
6161
assertEquals(uri, res.resolve(uri).getURI());

0 commit comments

Comments
 (0)