• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RequestContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.gerrit.server.util.RequestContext的典型用法代码示例。如果您正苦于以下问题:Java RequestContext类的具体用法?Java RequestContext怎么用?Java RequestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RequestContext类属于com.google.gerrit.server.util包,在下文中一共展示了RequestContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: run

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Override
public void run() {
  RequestContext old = requestContext.setContext(this);
  try {
    MergedSender cm = mergedSenderFactory.create(project, changeId);
    if (submitter != null) {
      cm.setFrom(submitter);
    }
    cm.setNotify(notifyHandling);
    cm.setAccountsToNotify(accountsToNotify);
    cm.send();
  } catch (Exception e) {
    log.error("Cannot email merged notification for " + changeId, e);
  } finally {
    requestContext.setContext(old);
    if (db != null) {
      db.close();
      db = null;
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:EmailMerge.java


示例2: AdministrateServerGroupsProvider

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Inject
public AdministrateServerGroupsProvider(
    GroupBackend groupBackend,
    @GerritServerConfig Config config,
    ThreadLocalRequestContext threadContext,
    ServerRequestContext serverCtx) {
  RequestContext ctx = threadContext.setContext(serverCtx);
  try {
    ImmutableSet.Builder<GroupReference> builder = ImmutableSet.builder();
    for (String value : config.getStringList("capability", null, "administrateServer")) {
      PermissionRule rule = PermissionRule.fromString(value, false);
      String name = rule.getGroup().getName();
      GroupReference g = GroupBackends.findBestSuggestion(groupBackend, name);
      if (g != null) {
        builder.add(g);
      } else {
        Logger log = LoggerFactory.getLogger(getClass());
        log.warn("Group \"{}\" not available, skipping.", name);
      }
    }
    groups = builder.build();
  } finally {
    threadContext.setContext(ctx);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:AdministrateServerGroupsProvider.java


示例3: GroupSetProvider

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
protected GroupSetProvider(
    GroupBackend groupBackend,
    ThreadLocalRequestContext threadContext,
    ServerRequestContext serverCtx,
    List<String> groupNames) {
  RequestContext ctx = threadContext.setContext(serverCtx);
  try {
    ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder();
    for (String n : groupNames) {
      GroupReference g = GroupBackends.findBestSuggestion(groupBackend, n);
      if (g != null) {
        builder.add(g.getUUID());
      } else {
        Logger log = LoggerFactory.getLogger(getClass());
        log.warn("Group \"{}\" not available, skipping.", n);
      }
    }
    groupIds = builder.build();
  } finally {
    threadContext.setContext(ctx);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:GroupSetProvider.java


示例4: run

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Override
public void run() {
  RequestContext old = requestContext.setContext(this);
  try {

    CommentSender cm = commentSenderFactory.create(notes.getProjectName(), notes.getChangeId());
    cm.setFrom(user.getAccountId());
    cm.setPatchSet(patchSet, patchSetInfoFactory.get(notes.getProjectName(), patchSet));
    cm.setChangeMessage(message.getMessage(), message.getWrittenOn());
    cm.setComments(comments);
    cm.setPatchSetComment(patchSetComment);
    cm.setLabels(labels);
    cm.setNotify(notify);
    cm.setAccountsToNotify(accountsToNotify);
    cm.send();
  } catch (Exception e) {
    log.error("Cannot email comments for " + patchSet.getId(), e);
  } finally {
    requestContext.setContext(old);
    if (db != null) {
      db.close();
      db = null;
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:EmailReviewComments.java


示例5: onStartPlugin

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
public void onStartPlugin(Plugin plugin) {
  RequestContext oldContext = enter(plugin);
  try {
    attachItem(sysItems, plugin.getSysInjector(), plugin);
    attachItem(sshItems, plugin.getSshInjector(), plugin);
    attachItem(httpItems, plugin.getHttpInjector(), plugin);

    attachSet(sysSets, plugin.getSysInjector(), plugin);
    attachSet(sshSets, plugin.getSshInjector(), plugin);
    attachSet(httpSets, plugin.getHttpInjector(), plugin);

    attachMap(sysMaps, plugin.getSysInjector(), plugin);
    attachMap(sshMaps, plugin.getSshInjector(), plugin);
    attachMap(httpMaps, plugin.getHttpInjector(), plugin);
  } finally {
    exit(oldContext);
  }

  for (StartPluginListener l : onStart) {
    l.onStartPlugin(plugin);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:PluginGuiceEnvironment.java


示例6: setUp

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  Injector injector = Guice.createInjector(new InMemoryModule());
  injector.injectMembers(this);
  lifecycle = new LifecycleManager();
  lifecycle.add(injector);
  lifecycle.start();

  db = schemaFactory.open();
  schemaCreator.create(db);
  // Need to create at least one user to be admin before creating a "normal"
  // registered user.
  // See AccountManager#create().
  accountManager.authenticate(AuthRequest.forUser("admin")).getAccountId();
  admins = groupCache.get(new AccountGroup.NameKey("Administrators")).orElse(null).getGroupUUID();
  setUpPermissions();

  Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
  user = userFactory.create(userId);

  Project.NameKey name = new Project.NameKey("project");
  InMemoryRepository inMemoryRepo = repoManager.createRepository(name);
  project = new ProjectConfig(name);
  project.load(inMemoryRepo);
  repo = new TestRepository<>(inMemoryRepo);

  requestContext.setContext(
      new RequestContext() {
        @Override
        public CurrentUser getUser() {
          return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
          return Providers.of(db);
        }
      });
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:40,代码来源:CommitsCollectionTest.java


示例7: doFilter

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  RequestContext old = local.setContext(requestContext.get());
  try {
    try {
      chain.doFilter(request, response);
    } finally {
      cleanup.get().run();
    }
  } finally {
    local.setContext(old);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:15,代码来源:RequestContextFilter.java


示例8: scope

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
public <T> Callable<T> scope(RequestContext requestContext, Callable<T> callable) {
  Context ctx = new Context();
  Callable<T> wrapped = context(requestContext, cleanup(callable));
  return () -> {
    Context old = current.get();
    current.set(ctx);
    try {
      return wrapped.call();
    } finally {
      current.set(old);
    }
  };
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:PerThreadRequestScope.java


示例9: impl

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Override
protected List<Change> impl(RequestContext ctx) throws OrmException {
  String ref = event.getRefName();
  Project.NameKey project = new Project.NameKey(event.getProjectName());
  if (ref.equals(RefNames.REFS_CONFIG)) {
    return asChanges(queryProvider.get().byProjectOpen(project));
  }
  return asChanges(queryProvider.get().byBranchNew(new Branch.NameKey(project, ref)));
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:10,代码来源:ReindexAfterRefUpdate.java


示例10: start

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Override
protected void start(PluginGuiceEnvironment env) throws Exception {
  RequestContext oldContext = env.enter(this);
  try {
    startPlugin(env);
  } finally {
    env.exit(oldContext);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:10,代码来源:ServerPlugin.java


示例11: stop

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Override
protected void stop(PluginGuiceEnvironment env) {
  if (serverManager != null) {
    RequestContext oldContext = env.enter(this);
    try {
      serverManager.stop();
    } finally {
      env.exit(oldContext);
    }
    serverManager = null;
    sysInjector = null;
    sshInjector = null;
    httpInjector = null;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:16,代码来源:ServerPlugin.java


示例12: onReloadPlugin

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
void onReloadPlugin(Plugin oldPlugin, Plugin newPlugin) {
  // Index all old registrations by the raw type. These may be replaced
  // during the reattach calls below. Any that are not replaced will be
  // removed when the old plugin does its stop routine.
  ListMultimap<TypeLiteral<?>, ReloadableRegistrationHandle<?>> old = LinkedListMultimap.create();
  for (ReloadableRegistrationHandle<?> h : oldPlugin.getReloadableHandles()) {
    old.put(h.getKey().getTypeLiteral(), h);
  }

  RequestContext oldContext = enter(newPlugin);
  try {
    reattachMap(old, sysMaps, newPlugin.getSysInjector(), newPlugin);
    reattachMap(old, sshMaps, newPlugin.getSshInjector(), newPlugin);
    reattachMap(old, httpMaps, newPlugin.getHttpInjector(), newPlugin);

    reattachSet(old, sysSets, newPlugin.getSysInjector(), newPlugin);
    reattachSet(old, sshSets, newPlugin.getSshInjector(), newPlugin);
    reattachSet(old, httpSets, newPlugin.getHttpInjector(), newPlugin);

    reattachItem(old, sysItems, newPlugin.getSysInjector(), newPlugin);
    reattachItem(old, sshItems, newPlugin.getSshInjector(), newPlugin);
    reattachItem(old, httpItems, newPlugin.getHttpInjector(), newPlugin);
  } finally {
    exit(oldContext);
  }

  for (ReloadPluginListener l : onReload) {
    l.onReloadPlugin(oldPlugin, newPlugin);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:31,代码来源:PluginGuiceEnvironment.java


示例13: setApiUser

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
public void setApiUser(Account.Id id) {
  IdentifiedUser user = userFactory.create(id);
  requestContext.setContext(
      new RequestContext() {
        @Override
        public CurrentUser getUser() {
          return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
          return Providers.of(db);
        }
      });
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:16,代码来源:SchemaUpgradeTestEnvironment.java


示例14: setUpInjector

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Before
public void setUpInjector() throws Exception {
  Injector injector = Guice.createInjector(new InMemoryModule());
  injector.injectMembers(this);
  lifecycle = new LifecycleManager();
  lifecycle.add(injector);
  lifecycle.start();

  db = schemaFactory.open();
  schemaCreator.create(db);
  userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
  user = userFactory.create(userId);

  requestContext.setContext(
      new RequestContext() {
        @Override
        public CurrentUser getUser() {
          return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
          return Providers.of(db);
        }
      });

  configureProject();
  setUpChange();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:30,代码来源:LabelNormalizerTest.java


示例15: newRequestContext

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
protected RequestContext newRequestContext(Account.Id requestUserId) {
  final CurrentUser requestUser = userFactory.create(requestUserId);
  return new RequestContext() {
    @Override
    public CurrentUser getUser() {
      return requestUser;
    }

    @Override
    public Provider<ReviewDb> getReviewDbProvider() {
      return Providers.of(db);
    }
  };
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:15,代码来源:AbstractQueryProjectsTest.java


示例16: setAnonymous

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
protected void setAnonymous() {
  requestContext.setContext(
      new RequestContext() {
        @Override
        public CurrentUser getUser() {
          return anonymousUser.get();
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
          return Providers.of(db);
        }
      });
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:15,代码来源:AbstractQueryProjectsTest.java


示例17: setUp

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  Injector injector = Guice.createInjector(new InMemoryModule());
  injector.injectMembers(this);
  lifecycle = new LifecycleManager();
  lifecycle.add(injector);
  lifecycle.start();

  try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
    schemaCreator.create(underlyingDb);
  }
  db = schemaFactory.open();
  Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
  user = userFactory.create(userId);

  project = new Project.NameKey("test");

  InMemoryRepository inMemoryRepo = repoManager.createRepository(project);
  repo = new TestRepository<>(inMemoryRepo);

  requestContext.setContext(
      new RequestContext() {
        @Override
        public CurrentUser getUser() {
          return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
          return Providers.of(db);
        }
      });
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:34,代码来源:BatchUpdateTest.java


示例18: createBatchUserIfNotExistsYet

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
private void createBatchUserIfNotExistsYet() {
	try (ReviewDb db = schema.open()) {
		List<Account> accounts = db.accounts().anyAccounts().toList();
		if (accounts.isEmpty()) {
			logger.info("Cannot create batch user account. No admin user yet. Log in as admin user to Gerrit.");
			executor.schedule(this::createBatchUserIfNotExistsYet, 2, TimeUnit.SECONDS);
			return;
		}

		RequestContext oldContext = null;

		try {
			oldContext = context.setContext(new RequestContext() {
				@Override
				public CurrentUser getUser() {
					return userFactory.create(accounts.iterator().next().getId());
				}

				@Override
				public Provider<ReviewDb> getReviewDbProvider() {
					return () -> db;
				}
			});

			AccountExternalId.Key accountKey = new AccountExternalId.Key(AccountExternalId.SCHEME_USERNAME, username);
			AccountExternalId accountExternalId = db.accountExternalIds().get(accountKey);

			if (accountExternalId == null) {
				accountExternalId = createBatchUser(db);
				logger.info("Batch user account created");
			}

			authorizedKeys.addKey(accountExternalId.getAccountId(), sshKey);
			sshKeyCache.evict(username);
		} finally {
			if (oldContext != null) {
				context.setContext(oldContext);
			}
		}
	} catch (OrmException | IOException | ConfigInvalidException | InvalidSshKeyException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:atteo,项目名称:jfactory,代码行数:44,代码来源:CreateBatchUser.java


示例19: Destination

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
protected Destination(
    Injector injector,
    DestinationConfiguration cfg,
    RemoteSiteUser.Factory replicationUserFactory,
    PluginUser pluginUser,
    GitRepositoryManager gitRepositoryManager,
    PermissionBackend permissionBackend,
    Provider<CurrentUser> userProvider,
    ProjectCache projectCache,
    GroupBackend groupBackend,
    ReplicationStateListener stateLog,
    GroupIncludeCache groupIncludeCache,
    DynamicItem<EventDispatcher> eventDispatcher) {
  config = cfg;
  this.eventDispatcher = eventDispatcher;
  gitManager = gitRepositoryManager;
  this.permissionBackend = permissionBackend;
  this.userProvider = userProvider;
  this.projectCache = projectCache;
  this.stateLog = stateLog;

  CurrentUser remoteUser;
  if (!cfg.getAuthGroupNames().isEmpty()) {
    ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder();
    for (String name : cfg.getAuthGroupNames()) {
      GroupReference g = GroupBackends.findExactSuggestion(groupBackend, name);
      if (g != null) {
        builder.add(g.getUUID());
        addRecursiveParents(g.getUUID(), builder, groupIncludeCache);
      } else {
        repLog.warn(String.format("Group \"%s\" not recognized, removing from authGroup", name));
      }
    }
    remoteUser = replicationUserFactory.create(new ListGroupMembership(builder.build()));
  } else {
    remoteUser = pluginUser;
  }

  Injector child =
      injector.createChildInjector(
          new FactoryModule() {
            @Override
            protected void configure() {
              bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST);
              bind(PerThreadRequestScope.Propagator.class);

              bind(Destination.class).toInstance(Destination.this);
              bind(RemoteConfig.class).toInstance(config.getRemoteConfig());
              install(new FactoryModuleBuilder().build(PushOne.Factory.class));
            }

            @Provides
            public PerThreadRequestScope.Scoper provideScoper(
                final PerThreadRequestScope.Propagator propagator,
                final Provider<RequestScopedReviewDbProvider> dbProvider) {
              final RequestContext requestContext =
                  new RequestContext() {
                    @Override
                    public CurrentUser getUser() {
                      return remoteUser;
                    }

                    @Override
                    public Provider<ReviewDb> getReviewDbProvider() {
                      return dbProvider.get();
                    }
                  };
              return new PerThreadRequestScope.Scoper() {
                @Override
                public <T> Callable<T> scope(Callable<T> callable) {
                  return propagator.scope(requestContext, callable);
                }
              };
            }
          });

  opFactory = child.getInstance(PushOne.Factory.class);
  threadScoper = child.getInstance(PerThreadRequestScope.Scoper.class);
}
 
开发者ID:GerritCodeReview,项目名称:plugins_replication,代码行数:80,代码来源:Destination.java


示例20: enter

import com.google.gerrit.server.util.RequestContext; //导入依赖的package包/类
public RequestContext enter(Plugin plugin) {
  return local.setContext(new PluginRequestContext(plugin.getPluginUser()));
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:4,代码来源:PluginGuiceEnvironment.java



注:本文中的com.google.gerrit.server.util.RequestContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PointFeature类代码示例发布时间:2022-05-22
下一篇:
Java DoPreUpgradeResponseProto类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap