Restore gerrit-provided DynamicItem when plugin unloads

Change-Id: I21db4f146916dd129e306fdc3416b9acae2e453b
This commit is contained in:
Jonathan Nieder
2014-03-25 10:34:17 -07:00
parent 0ea26c900a
commit 72e69e6f40

View File

@@ -149,8 +149,9 @@ public class DynamicItem<T> {
*/
public RegistrationHandle set(Provider<T> impl, String pluginName) {
final NamedProvider<T> item = new NamedProvider<T>(impl, pluginName);
NamedProvider<T> old = null;
while (!ref.compareAndSet(null, item)) {
NamedProvider<T> old = ref.get();
old = ref.get();
if (old != null) {
if ("gerrit".equals(old.pluginName)) {
if (ref.compareAndSet(old, item)) {
@@ -163,10 +164,12 @@ public class DynamicItem<T> {
key.getTypeLiteral(), old.pluginName, pluginName));
}
}
final NamedProvider<T> defaultItem = old;
return new RegistrationHandle() {
@Override
public void remove() {
ref.compareAndSet(item, null);
ref.compareAndSet(item, defaultItem);
}
};
}