org.sonatype.nexus.common.event.EventManager Java Examples

The following examples show how to use org.sonatype.nexus.common.event.EventManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchIndexServiceImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param client source for a {@link Client}
 * @param indexNamingPolicy the index naming policy
 * @param indexSettingsContributors the index settings contributors
 * @param eventManager the event manager
 * @param bulkCapacity how many bulk requests to batch before they're automatically flushed (default: 1000)
 * @param concurrentRequests how many bulk requests to execute concurrently (default: 1; 0 means execute synchronously)
 * @param flushInterval how long to wait in milliseconds between flushing bulk requests (default: 0, instantaneous)
 * @param calmTimeout timeout in ms to wait for a calm period
 * @param batchingThreads This is the number of threads 'n' batching up index updates into 'n' BulkProcessors.
 *                        That is, the number of independent batches to accumulate index updates in.
 */
@Inject
public SearchIndexServiceImpl(final Provider<Client> client, // NOSONAR
                              final IndexNamingPolicy indexNamingPolicy,
                              final List<IndexSettingsContributor> indexSettingsContributors,
                              final EventManager eventManager,
                              @Named("${nexus.elasticsearch.bulkCapacity:-1000}") final int bulkCapacity,
                              @Named("${nexus.elasticsearch.concurrentRequests:-1}") final int concurrentRequests,
                              @Named("${nexus.elasticsearch.flushInterval:-0}") final int flushInterval,
                              @Named("${nexus.elasticsearch.calmTimeout:-3000}") final int calmTimeout,
                              @Named("${nexus.elasticsearch.batching.threads.count:-1}") final int batchingThreads)
{
  checkState(batchingThreads > 0,
      "'nexus.elasticsearch.batching.threads.count' must be positive.");

  this.client = checkNotNull(client);
  this.indexNamingPolicy = checkNotNull(indexNamingPolicy);
  this.indexSettingsContributors = checkNotNull(indexSettingsContributors);
  this.eventManager = checkNotNull(eventManager);
  this.calmTimeout = calmTimeout;
  this.periodicFlush = flushInterval > 0;

  createBulkProcessorsAndExecutors(bulkCapacity, concurrentRequests, flushInterval, batchingThreads);
}
 
Example #2
Source File: HttpClientManagerImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public HttpClientManagerImpl(final EventManager eventManager,
    final HttpClientConfigurationStore store,
    @Named("initial") final Provider<HttpClientConfiguration> defaults,
    final SharedHttpClientConnectionManager sharedConnectionManager,
    final DefaultsCustomizer defaultsCustomizer)
{
  this.eventManager = checkNotNull(eventManager);

  this.store = checkNotNull(store);
  log.debug("Store: {}", store);

  this.defaults = checkNotNull(defaults);
  log.debug("Defaults: {}", defaults);

  this.sharedConnectionManager = checkNotNull(sharedConnectionManager);
  this.defaultsCustomizer = checkNotNull(defaultsCustomizer);
}
 
Example #3
Source File: MavenComponentMaintenanceFacetTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() throws Exception {

  underTest = Guice.createInjector(new TransactionModule(), new AbstractModule()
  {
    @Override
    protected void configure() {
      bind(EventManager.class).toInstance(eventManager);
    }
  }).getInstance(MavenComponentMaintenanceFacet.class);

  underTest.attach(repository);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);

  when(storageTx.findAsset(entityId)).thenReturn(asset);
  when(storageTx.findAsset(entityId, bucket)).thenReturn(asset);
  when(storageTx.findBucket(any())).thenReturn(bucket);
  when(storageTx.findComponent(any())).thenReturn(component);
  when(storageTx.findComponentInBucket(any(), eq(bucket))).thenReturn(component);
  when(storageTx.browseAssets(component)).thenReturn(new ArrayList<>());

  UnitOfWork.begin(() -> storageTx);
}
 
Example #4
Source File: AptApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private static Repository createRepository(
    final Type type,
    final String distribution,
    final String keypair,
    final String passphrase,
    final Boolean flat) throws Exception
{
  Repository repository = new RepositoryImpl(mock(EventManager.class), type, new AptFormat());

  Configuration configuration = config("my-repo");
  Map<String, Object> apt = newHashMap();
  apt.put("distribution", distribution);
  apt.put("keypair", keypair);
  apt.put("passphrase", passphrase);
  apt.put("flat", flat);
  Map<String, Object> attributes = newHashMap();
  attributes.put("apt", apt);
  NestedAttributesMap aptNested = new NestedAttributesMap("apt", apt);
  when(configuration.attributes("apt")).thenReturn(aptNested);
  repository.init(configuration);
  return repository;
}
 
Example #5
Source File: AbstractSecurityTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
protected void customizeModules(List<Module> modules) {
  modules.add(new AbstractModule()
  {
    @Override
    protected void configure() {
      install(new WebSecurityModule(mock(ServletContext.class)));

      bind(SecurityConfigurationSource.class).annotatedWith(Names.named("default")).toInstance(
          new PreconfiguredSecurityConfigurationSource(initialSecurityConfiguration()));

      RealmConfiguration realmConfiguration = new TestRealmConfiguration();
      realmConfiguration.setRealmNames(Arrays.asList("MockRealmA", "MockRealmB"));
      bind(RealmConfiguration.class).annotatedWith(Names.named("initial")).toInstance(realmConfiguration);

      bind(ApplicationDirectories.class).toInstance(mock(ApplicationDirectories.class));
      bind(NodeAccess.class).toInstance(mock(NodeAccess.class));
      bind(AnonymousManager.class).toInstance(mock(AnonymousManager.class));
      bind(EventManager.class).toInstance(getEventManager());

      requestInjection(AbstractSecurityTest.this);
    }
  });
}
 
Example #6
Source File: BlobStoreManagerImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public BlobStoreManagerImpl(final EventManager eventManager, //NOSONAR
                            final BlobStoreConfigurationStore store,
                            final Map<String, BlobStoreDescriptor> blobStoreDescriptors,
                            final Map<String, Provider<BlobStore>> blobStorePrototypes,
                            final FreezeService freezeService,
                            final Provider<RepositoryManager> repositoryManagerProvider,
                            final NodeAccess nodeAccess,
                            @Nullable @Named("${nexus.blobstore.provisionDefaults}") final Boolean provisionDefaults)
{
  this.eventManager = checkNotNull(eventManager);
  this.store = checkNotNull(store);
  this.blobStoreDescriptors = checkNotNull(blobStoreDescriptors);
  this.blobStorePrototypes = checkNotNull(blobStorePrototypes);
  this.freezeService = checkNotNull(freezeService);
  this.repositoryManagerProvider = checkNotNull(repositoryManagerProvider);

  if (provisionDefaults != null) {
    // explicit true/false setting, so honour that
    this.provisionDefaults = provisionDefaults::booleanValue;
  }
  else {
    // otherwise only create in non-clustered mode
    this.provisionDefaults = () -> !nodeAccess.isClustered();
  }
}
 
Example #7
Source File: QuartzSchedulerSPI.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("squid:S00107") //suppress constructor parameter count
@Inject
public QuartzSchedulerSPI(final EventManager eventManager,
                          final NodeAccess nodeAccess,
                          final Provider<JobStore> jobStoreProvider,
                          final Provider<Scheduler> schedulerProvider,
                          final LastShutdownTimeService lastShutdownTimeService,
                          final DatabaseStatusDelayedExecutor delayedExecutor,
                          @Named("${nexus.quartz.recoverInterruptedJobs:-true}") final boolean recoverInterruptedJobs)
{
  this.eventManager = checkNotNull(eventManager);
  this.nodeAccess = checkNotNull(nodeAccess);
  this.jobStoreProvider = checkNotNull(jobStoreProvider);
  this.schedulerProvider = checkNotNull(schedulerProvider);
  this.lastShutdownTimeService = checkNotNull(lastShutdownTimeService);
  this.recoverInterruptedJobs = recoverInterruptedJobs;
  this.delayedExecutor = checkNotNull(delayedExecutor);

  this.scheduleFactory = new QuartzScheduleFactory();
  this.triggerConverter = new QuartzTriggerConverter(this.scheduleFactory);

  // FIXME: sort out with refinement to lifecycle below
  this.active = true;
}
 
Example #8
Source File: DatabaseFreezeServiceImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public DatabaseFreezeServiceImpl(final Set<Provider<DatabaseInstance>> providers,
                                 final EventManager eventManager,
                                 final DatabaseFrozenStateManager databaseFrozenStateManager,
                                 final Provider<OServer> server,
                                 final NodeAccess nodeAccess,
                                 final SecurityHelper securityHelper,
                                 final List<Freezable> freezables)
{
  this.providers = checkNotNull(providers);
  this.eventManager = checkNotNull(eventManager);
  this.databaseFrozenStateManager = checkNotNull(databaseFrozenStateManager);
  checkNotNull(server);
  distributedServerManagerProvider = () -> server.get().getDistributedManager();
  this.nodeAccess = checkNotNull(nodeAccess);
  this.securityHelper = securityHelper;
  this.freezables = checkNotNull(freezables);
}
 
Example #9
Source File: NpmSearchIndexFacetGroupTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  underTest = Guice.createInjector(new TransactionModule(), new AbstractModule()
  {
    @Override
    protected void configure() {
      bind(EventManager.class).toInstance(eventManager);
    }
  }).getInstance(NpmSearchIndexFacetGroup.class);

  underTest.attach(groupRepository);

  when(groupRepository.facet(GroupFacet.class)).thenReturn(groupFacet);
  when(groupRepository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(storageFacet.txSupplier()).thenReturn(supplierStorageTx);
  when(storageTx.findAssetWithProperty(P_NAME, REPOSITORY_ROOT_ASSET, groupBucket)).thenReturn(asset);
  when(storageTx.findBucket(groupRepository)).thenReturn(groupBucket);
}
 
Example #10
Source File: RealmManagerImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public RealmManagerImpl(
    final BeanLocator beanLocator,
    final EventManager eventManager,
    final RealmConfigurationStore store,
    @Named("initial") final Provider<RealmConfiguration> defaults,
    final RealmSecurityManager realmSecurityManager,
    final Map<String, Realm> availableRealms)
{
  this.beanLocator = checkNotNull(beanLocator);
  this.eventManager = checkNotNull(eventManager);
  this.store = checkNotNull(store);
  log.debug("Store: {}", store);
  this.defaults = checkNotNull(defaults);
  log.debug("Defaults: {}", defaults);
  this.realmSecurityManager = checkNotNull(realmSecurityManager);
  this.availableRealms = checkNotNull(availableRealms);
}
 
Example #11
Source File: DefaultSecuritySystem.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public DefaultSecuritySystem(final EventManager eventManager,
                             final RealmSecurityManager realmSecurityManager,
                             final RealmManager realmManager,
                             final AnonymousManager anonymousManager,
                             final Map<String, AuthorizationManager> authorizationManagers,
                             final Map<String, UserManager> userManagers,
                             final SecurityHelper securityHelper)
{
  this.eventManager = checkNotNull(eventManager);
  this.realmSecurityManager = checkNotNull(realmSecurityManager);
  this.realmManager = checkNotNull(realmManager);
  this.anonymousManager = checkNotNull(anonymousManager);
  this.authorizationManagers = checkNotNull(authorizationManagers);
  this.userManagers = checkNotNull(userManagers);
  this.securityHelper = checkNotNull(securityHelper);
}
 
Example #12
Source File: HttpClientManagerImplIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void before() {
  underTest = new HttpClientManagerImpl(mock(EventManager.class), mock(HttpClientConfigurationStore.class),
      () -> mock(HttpClientConfiguration.class), mock(SharedHttpClientConnectionManager.class),
      mock(DefaultsCustomizer.class));

  resetCounts();
}
 
Example #13
Source File: CipherRequiredCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public CipherRequiredCondition(final EventManager eventManager,
                               final CryptoHelper crypto,
                               final String transformation)
{
  super(eventManager, false);
  this.crypto = checkNotNull(crypto);
  this.transformation = checkNotNull(transformation);
}
 
Example #14
Source File: ValidityConditionHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
ValidityConditionHandler(final EventManager eventManager,
                         final CapabilityRegistry capabilityRegistry,
                         final Conditions conditions,
                         @Assisted final DefaultCapabilityReference reference)
{
  this.eventManager = checkNotNull(eventManager);
  this.capabilityRegistry = checkNotNull(capabilityRegistry);
  this.conditions = checkNotNull(conditions);
  this.reference = checkNotNull(reference);
}
 
Example #15
Source File: RolePermissionResolverImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  securityConfigurationManager = mock(SecurityConfigurationManager.class);
  when(securityConfigurationManager.readRole(any())).thenThrow(new NoSuchRoleException("Role not found"));
  underTest = new RolePermissionResolverImpl(securityConfigurationManager, Collections.emptyList(),
      mock(EventManager.class), 10);
}
 
Example #16
Source File: CapabilityRegistryBooter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public CapabilityRegistryBooter(final EventManager eventManager,
                                final Provider<DefaultCapabilityRegistry> capabilityRegistryProvider)
{
  this.eventManager = checkNotNull(eventManager);
  this.capabilityRegistryProvider = checkNotNull(capabilityRegistryProvider);
}
 
Example #17
Source File: UserManagerImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public UserManagerImpl(final EventManager eventManager,
                       final SecurityConfigurationManager configuration,
                       final SecuritySystem securitySystem,
                       final PasswordService passwordService,
                       final PasswordValidator passwordValidator)
{
  this.eventManager = checkNotNull(eventManager);
  this.configuration = configuration;
  this.securitySystem = securitySystem;
  this.passwordService = passwordService;
  this.passwordValidator = passwordValidator;
}
 
Example #18
Source File: CryptoConditionsImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public CryptoConditionsImpl(final EventManager eventManager,
                        final CryptoHelper crypto)
{
  this.eventManager = checkNotNull(eventManager);
  this.crypto = checkNotNull(crypto);
}
 
Example #19
Source File: IndexRequestProcessor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public IndexRequestProcessor(final RepositoryManager repositoryManager,
                             final EventManager eventManager,
                             final SearchIndexService searchIndexService,
                             @Named("${nexus.elasticsearch.bulkProcessing:-true}") final boolean bulkProcessing)
{
  this.repositoryManager = checkNotNull(repositoryManager);
  this.eventManager = checkNotNull(eventManager);
  this.searchIndexService = checkNotNull(searchIndexService);
  this.bulkProcessing = bulkProcessing;
}
 
Example #20
Source File: CapabilityConditionsImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public final void setUpCapabilityConditions() {
  final EventManager eventManager = mock(EventManager.class);
  final CapabilityDescriptorRegistry descriptorRegistry = mock(CapabilityDescriptorRegistry.class);
  final CapabilityRegistry capabilityRegistry = mock(CapabilityRegistry.class);
  underTest = new CapabilityConditionsImpl(eventManager, descriptorRegistry, capabilityRegistry);
}
 
Example #21
Source File: MutableSecurityContributor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
protected void initialize(final EventManager eventManager, final SecurityConfigurationManager configurationManager) {
  checkState(!initialized, "already initialized");
  this.eventManager = Preconditions.checkNotNull(eventManager);
  this.configurationManager = Preconditions.checkNotNull(configurationManager);
  initial(model);
  initialized = true;
}
 
Example #22
Source File: NexusWebSecurityManager.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public NexusWebSecurityManager(final Provider<EventManager> eventManager,
                               final Provider<CacheHelper> cacheHelper,
                               @Named("${nexus.shiro.cache.defaultTimeToLive:-2m}") final Provider<Time> defaultTimeToLive)
{
  this.eventManager = checkNotNull(eventManager);
  setCacheManager(new ShiroJCacheManagerAdapter(cacheHelper, defaultTimeToLive));
  //explicitly disable rememberMe
  this.setRememberMeManager(null); 
}
 
Example #23
Source File: AuthenticationEventSubscriber.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public AuthenticationEventSubscriber(
    final Provider<EventManager> eventManager,
    final Provider<ClientInfoProvider> clientInfoProvider)
{
  this.eventManager = checkNotNull(eventManager);
  this.clientInfoProvider = checkNotNull(clientInfoProvider);
}
 
Example #24
Source File: EventManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void asyncInheritsIsReplicating() throws Exception {
  EventExecutor executor = newEventExecutor();
  EventManager underTest = new EventManagerImpl(new DefaultBeanLocator(), executor);
  AsyncReentrantHandler handler = new AsyncReentrantHandler(underTest);
  underTest.register(handler);

  executor.start(); // enable multi-threaded mode

  // non-replicating case
  FakeAlmightySubject.forUserId("testUser").execute(
      () -> underTest.post("a string"));

  await().atMost(5, TimeUnit.SECONDS).until(underTest::isCalmPeriod);

  // handled two events, neither were replicating
  assertThat(handler.handledCount.get(), is(2));
  assertThat(handler.replicatingCount.get(), is(0));

  // replicating case
  FakeAlmightySubject.forUserId("testUser").execute(
      () -> EventHelper.asReplicating(
          () -> underTest.post("a string")));

  await().atMost(5, TimeUnit.SECONDS).until(underTest::isCalmPeriod);

  // handled two more events, both were replicating
  assertThat(handler.handledCount.get(), is(4));
  assertThat(handler.replicatingCount.get(), is(2));

  executor.stop(); // go back to single-threaded mode
}
 
Example #25
Source File: RepositoryConditionSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public RepositoryConditionSupport(final EventManager eventManager,
                                  final RepositoryManager repositoryManager,
                                  final Supplier<String> repositoryName)
{
  super(eventManager, false);
  this.repositoryManager = checkNotNull(repositoryManager);
  this.repositoryName = checkNotNull(repositoryName);
  bindLock = new ReentrantReadWriteLock();
}
 
Example #26
Source File: QuartzTaskInfo.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public QuartzTaskInfo(final EventManager eventManager,
                      final QuartzSchedulerSPI scheduler,
                      final JobKey jobKey,
                      final QuartzTaskState taskState,
                      @Nullable final QuartzTaskFuture taskFuture)
{
  this.eventManager = checkNotNull(eventManager);
  this.scheduler = checkNotNull(scheduler);
  this.jobKey = checkNotNull(jobKey);
  this.removed = false;
  setNexusTaskState(taskFuture != null ? RUNNING : WAITING, taskState, taskFuture);
}
 
Example #27
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static Repository createRepository(final Type type) throws Exception {
  Repository repository = new RepositoryImpl(mock(EventManager.class), type, new Format("test-format")
  {
  });
  repository.init(config("my-repo"));
  return repository;
}
 
Example #28
Source File: CipherKeyHighStrengthCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public CipherKeyHighStrengthCondition(final EventManager eventManager,
                                      final CryptoHelper crypto,
                                      final String transformation)
{
  super(eventManager, false);
  this.crypto = checkNotNull(crypto);
  this.transformation = checkNotNull(transformation);
}
 
Example #29
Source File: CapabilityConditionsImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public CapabilityConditionsImpl(final EventManager eventManager,
                                final CapabilityDescriptorRegistry descriptorRegistry,
                                final CapabilityRegistry capabilityRegistry)
{
  this.descriptorRegistry = checkNotNull(descriptorRegistry);
  this.capabilityRegistry = checkNotNull(capabilityRegistry);
  this.eventManager = checkNotNull(eventManager);
}
 
Example #30
Source File: CapabilityOfTypeActiveCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public CapabilityOfTypeActiveCondition(final EventManager eventManager,
                                       final CapabilityDescriptorRegistry descriptorRegistry,
                                       final CapabilityRegistry capabilityRegistry,
                                       final CapabilityType type)
{
  super(eventManager, descriptorRegistry, capabilityRegistry, type);
}