use of com.google.gerrit.extensions.registration.DynamicSet in project gerrit by GerritCodeReview.
the class PluginGuiceEnvironment method reattachSet.
private void reattachSet(ListMultimap<TypeLiteral<?>, ReloadableRegistrationHandle<?>> oldHandles, Map<TypeLiteral<?>, DynamicSet<?>> sets, @Nullable Injector src, Plugin newPlugin) {
if (src == null || sets == null || sets.isEmpty()) {
return;
}
for (Map.Entry<TypeLiteral<?>, DynamicSet<?>> e : sets.entrySet()) {
@SuppressWarnings("unchecked") TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();
@SuppressWarnings("unchecked") DynamicSet<Object> set = (DynamicSet<Object>) e.getValue();
// Index all old handles that match this DynamicSet<T> keyed by
// annotations. Ignore the unique annotations, thereby favoring
// the @Named annotations or some other non-unique naming.
Map<Annotation, ReloadableRegistrationHandle<?>> am = new HashMap<>();
List<ReloadableRegistrationHandle<?>> old = oldHandles.get(type);
Iterator<ReloadableRegistrationHandle<?>> oi = old.iterator();
while (oi.hasNext()) {
ReloadableRegistrationHandle<?> h = oi.next();
Annotation a = h.getKey().getAnnotation();
if (a != null && !UNIQUE_ANNOTATION.isInstance(a)) {
am.put(a, h);
oi.remove();
}
}
// Replace old handles with new bindings, favoring cases where there
// is an exact match on an @Named annotation. If there is no match
// pick any handle and replace it. We generally expect only one
// handle of each DynamicSet type when using unique annotations, but
// possibly multiple ones if @Named was used. Plugin authors that want
// atomic replacement across reloads should use @Named annotations with
// stable names that do not change across plugin versions to ensure the
// handles are swapped correctly.
oi = old.iterator();
for (Binding<?> binding : bindings(src, type)) {
@SuppressWarnings("unchecked") Binding<Object> b = (Binding<Object>) binding;
Key<Object> key = b.getKey();
if (key.getAnnotation() == null) {
continue;
}
@SuppressWarnings("unchecked") ReloadableRegistrationHandle<Object> h1 = (ReloadableRegistrationHandle<Object>) am.remove(key.getAnnotation());
if (h1 != null) {
replace(newPlugin, h1, b);
} else if (oi.hasNext()) {
@SuppressWarnings("unchecked") ReloadableRegistrationHandle<Object> h2 = (ReloadableRegistrationHandle<Object>) oi.next();
oi.remove();
replace(newPlugin, h2, b);
} else {
newPlugin.add(set.add(b.getKey(), b.getProvider()));
}
}
}
}
use of com.google.gerrit.extensions.registration.DynamicSet in project gerrit by GerritCodeReview.
the class BatchProgramModule method configure.
@SuppressWarnings("rawtypes")
@Override
protected void configure() {
install(reviewDbModule);
install(new DiffExecutorModule());
install(new ReceiveCommitsExecutorModule());
install(BatchUpdate.module());
install(PatchListCacheImpl.module());
// Plugins are not loaded and we're just running through each change
// once, so don't worry about cache removal.
bind(new TypeLiteral<DynamicSet<CacheRemovalListener>>() {
}).toInstance(DynamicSet.<CacheRemovalListener>emptySet());
bind(new TypeLiteral<DynamicMap<Cache<?, ?>>>() {
}).toInstance(DynamicMap.<Cache<?, ?>>emptyMap());
bind(new TypeLiteral<List<CommentLinkInfo>>() {
}).toProvider(CommentLinkProvider.class).in(SINGLETON);
bind(new TypeLiteral<DynamicMap<ChangeQueryProcessor.ChangeAttributeFactory>>() {
}).toInstance(DynamicMap.<ChangeQueryProcessor.ChangeAttributeFactory>emptyMap());
bind(String.class).annotatedWith(CanonicalWebUrl.class).toProvider(CanonicalWebUrlProvider.class);
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toProvider(DisableReverseDnsLookupProvider.class).in(SINGLETON);
bind(Realm.class).to(FakeRealm.class);
bind(IdentifiedUser.class).toProvider(Providers.<IdentifiedUser>of(null));
bind(ReplacePatchSetSender.Factory.class).toProvider(Providers.<ReplacePatchSetSender.Factory>of(null));
bind(CurrentUser.class).to(IdentifiedUser.class);
factory(MergeUtil.Factory.class);
factory(PatchSetInserter.Factory.class);
factory(RebaseChangeOp.Factory.class);
// As Reindex is a batch program, don't assume the index is available for
// the change cache.
bind(SearchingChangeCacheImpl.class).toProvider(Providers.<SearchingChangeCacheImpl>of(null));
bind(new TypeLiteral<ImmutableSet<GroupReference>>() {
}).annotatedWith(AdministrateServerGroups.class).toInstance(ImmutableSet.<GroupReference>of());
bind(new TypeLiteral<Set<AccountGroup.UUID>>() {
}).annotatedWith(GitUploadPackGroups.class).toInstance(Collections.<AccountGroup.UUID>emptySet());
bind(new TypeLiteral<Set<AccountGroup.UUID>>() {
}).annotatedWith(GitReceivePackGroups.class).toInstance(Collections.<AccountGroup.UUID>emptySet());
install(new BatchGitModule());
install(new DefaultPermissionBackendModule());
install(new DefaultCacheFactory.Module());
install(new ExternalIdModule());
install(new GroupModule());
install(new NoteDbModule(cfg));
install(new PrologModule());
install(AccountByEmailCacheImpl.module());
install(AccountCacheImpl.module());
install(GroupCacheImpl.module());
install(GroupIncludeCacheImpl.module());
install(ProjectCacheImpl.module());
install(SectionSortCache.module());
install(ChangeKindCacheImpl.module());
install(MergeabilityCacheImpl.module());
install(TagCache.module());
factory(CapabilityCollection.Factory.class);
factory(CapabilityControl.Factory.class);
factory(ChangeData.Factory.class);
factory(ProjectState.Factory.class);
bind(ChangeJson.Factory.class).toProvider(Providers.<ChangeJson.Factory>of(null));
bind(AccountVisibility.class).toProvider(AccountVisibilityProvider.class).in(SINGLETON);
}
Aggregations