Search in sources :

Example 1 with DynamicSet

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()));
            }
        }
    }
}
Also used : Binding(com.google.inject.Binding) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) Annotation(java.lang.annotation.Annotation) TypeLiteral(com.google.inject.TypeLiteral) ReloadableRegistrationHandle(com.google.gerrit.extensions.registration.ReloadableRegistrationHandle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap)

Example 2 with DynamicSet

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);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) CurrentUser(com.google.gerrit.server.CurrentUser) CapabilityControl(com.google.gerrit.server.account.CapabilityControl) NoteDbModule(com.google.gerrit.server.notedb.NoteDbModule) DefaultCacheFactory(com.google.gerrit.server.cache.h2.DefaultCacheFactory) AdministrateServerGroups(com.google.gerrit.server.config.AdministrateServerGroups) GroupModule(com.google.gerrit.server.group.GroupModule) CacheRemovalListener(com.google.gerrit.server.cache.CacheRemovalListener) TypeLiteral(com.google.inject.TypeLiteral) ImmutableSet(com.google.common.collect.ImmutableSet) GitUploadPackGroups(com.google.gerrit.server.config.GitUploadPackGroups) MergeUtil(com.google.gerrit.server.git.MergeUtil) List(java.util.List) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) FakeRealm(com.google.gerrit.server.account.FakeRealm) Realm(com.google.gerrit.server.account.Realm) CommentLinkProvider(com.google.gerrit.server.project.CommentLinkProvider) SearchingChangeCacheImpl(com.google.gerrit.server.git.SearchingChangeCacheImpl) ChangeJson(com.google.gerrit.server.change.ChangeJson) GitReceivePackGroups(com.google.gerrit.server.config.GitReceivePackGroups) DisableReverseDnsLookupProvider(com.google.gerrit.server.config.DisableReverseDnsLookupProvider) PrologModule(com.google.gerrit.rules.PrologModule) CanonicalWebUrl(com.google.gerrit.server.config.CanonicalWebUrl) ChangeQueryProcessor(com.google.gerrit.server.query.change.ChangeQueryProcessor) DefaultCacheFactory(com.google.gerrit.server.cache.h2.DefaultCacheFactory) RebaseChangeOp(com.google.gerrit.server.change.RebaseChangeOp) CapabilityCollection(com.google.gerrit.server.account.CapabilityCollection) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ChangeData(com.google.gerrit.server.query.change.ChangeData) AccountVisibilityProvider(com.google.gerrit.server.account.AccountVisibilityProvider) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PatchSetInserter(com.google.gerrit.server.change.PatchSetInserter) ExternalIdModule(com.google.gerrit.server.account.externalids.ExternalIdModule) DiffExecutorModule(com.google.gerrit.server.patch.DiffExecutorModule) ProjectState(com.google.gerrit.server.project.ProjectState) ReceiveCommitsExecutorModule(com.google.gerrit.server.git.ReceiveCommitsExecutorModule) ReplacePatchSetSender(com.google.gerrit.server.mail.send.ReplacePatchSetSender) TagCache(com.google.gerrit.server.git.TagCache) SectionSortCache(com.google.gerrit.server.project.SectionSortCache) Cache(com.google.common.cache.Cache)

Aggregations

DynamicSet (com.google.gerrit.extensions.registration.DynamicSet)2 TypeLiteral (com.google.inject.TypeLiteral)2 Cache (com.google.common.cache.Cache)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)1 ReloadableRegistrationHandle (com.google.gerrit.extensions.registration.ReloadableRegistrationHandle)1 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)1 PrologModule (com.google.gerrit.rules.PrologModule)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 AccountVisibilityProvider (com.google.gerrit.server.account.AccountVisibilityProvider)1 CapabilityCollection (com.google.gerrit.server.account.CapabilityCollection)1 CapabilityControl (com.google.gerrit.server.account.CapabilityControl)1 FakeRealm (com.google.gerrit.server.account.FakeRealm)1 Realm (com.google.gerrit.server.account.Realm)1 ExternalIdModule (com.google.gerrit.server.account.externalids.ExternalIdModule)1 CacheRemovalListener (com.google.gerrit.server.cache.CacheRemovalListener)1 DefaultCacheFactory (com.google.gerrit.server.cache.h2.DefaultCacheFactory)1 ChangeJson (com.google.gerrit.server.change.ChangeJson)1 PatchSetInserter (com.google.gerrit.server.change.PatchSetInserter)1