Skip to content

Instantly share code, notes, and snippets.

@blangel
Created March 2, 2012 19:25
Show Gist options
  • Save blangel/1960632 to your computer and use it in GitHub Desktop.
Save blangel/1960632 to your computer and use it in GitHub Desktop.
import static net.ocheyedan.clapi.ClApi;
// class structure removed for brevity
void usageExample {
using(ThriftVersion.2);
callCodeDependingUponThriftVersion2();
using(ThriftVersion.3);
callCodeDependingUponThriftVersion3();
}
public final class ClApi extends URLClassLoader {
private static final ClApi instance = new ClApi(); // or injected
public static void using(Version version) {
instance.using.set(version);
}
// created in init from some yaml file or something which links (auto-generated?) Version (i.e., ThriftVersion.2)
// to the appropriate ClassLoader
private final ImmutableMap<Version, ClassLoader> config;
// this class would become the system-classloader and it would contain all non-multi-versioned jars but then
// delegate to those ClassLoader's in {@link #config} depending upon what's set in the ThreadLocal {@link #using} variable.
private final ThreadLocal<Version> using;
private ClApi() { }
}
public interface Version { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment