Repurpose IndexingObjectStore ?
Tom Zeller
tzeller at dragonacea.biz
Tue Sep 22 11:03:03 EDT 2015
> On Sep 21, 2015, at 6:30 PM, Cantor, Scott <cantor.2 at osu.edu> wrote:
>
> On 9/21/15, 5:39 PM, "dev on behalf of Tom Zeller" <dev-bounces at shibboleth.net on behalf of tzeller at dragonacea.biz> wrote:
>
>
>
>> Does it sound reasonable to repurpose IndexingObjectStore<T> to use an index other than a String ?
>
> I don't pretend to understand that class or why it's used, but it looks to me like the indexing is an internal function, not an exposed thing. They're just supposed to be opaque strings returned by put() and then used with get(), but they're manufactured internally.
Here’s what I’ve implemented, and what I thought IndexingObjectStore might fit :
public class ServerBuilderExample {
private Map<JettyConfig, Pair<ServerProcess, Integer>> map;
public ServerBuilderExample() {
map = new LinkedHashMap<>();
}
public synchronized ServerProcess start(@Nonnull final BaseConfig config)
throws ComponentInitializationException {
if (map.containsKey(config)) {
map.get(config).setSecond(Integer.valueOf(map.get(config).getSecond() + 1));
return map.get(config).getFirst();
}
final ServerProcess process = buildServerProcess(config);
process.start();
map.put(config, new Pair(process, Integer.valueOf(0)));
return process;
}
public void stop() {
synchronized (this) {
for (final Pair<ServerProcess, Integer> pair : map.values()) {
final ServerProcess process = pair.getFirst();
final Integer count = pair.getSecond();
if (count > 0) {
pair.setSecond(Integer.valueOf(count - 1));
} else if (count == 0) {
process.stop();
}
}
}
}
}
Basically, a “CountingCachingMap” ? Dunno. For a given Object K, return T, counting the number of times T has been returned, starting T when necessary and stopping when unused. Rod sent me an example using static classes, if he sees this maybe he’ll understand what I’m trying to do.
More information about the dev
mailing list