com.google.common.eventbus.AllowConcurrentEvents Java Examples

The following examples show how to use com.google.common.eventbus.AllowConcurrentEvents. 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: UserRoleMappingAuditor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final UserRoleMappingEvent event) {
  if (isRecording()) {
    AuditData data = new AuditData();
    data.setDomain(DOMAIN);
    data.setType(type(event.getClass()));
    data.setContext(event.getUserId());

    Map<String, Object> attributes = data.getAttributes();
    attributes.put("id", event.getUserId());
    attributes.put("source", event.getUserSource());
    attributes.put("roles", string(event.getRoles()));

    record(data);
  }
}
 
Example #2
Source File: ComponentAuditor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final ComponentEvent event) {
  if (isRecording() && event.isLocal()) {
    Component component = event.getComponent();

    AuditData data = new AuditData();
    data.setDomain(DOMAIN);
    data.setType(type(event.getClass()));
    data.setContext(component.name());

    Map<String, Object> attributes = data.getAttributes();
    attributes.put("repository.name", event.getRepositoryName());
    attributes.put("format", component.format());
    attributes.put("name", component.name());
    attributes.put("group", component.group());
    attributes.put("version", component.version());

    record(data);
  }
}
 
Example #3
Source File: AllureStoryReporter.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void onSubStepsPublishingFinish(SubStepsPublishingFinishEvent event)
{
    modifyStepTitle(event.getSubStepTitle());
    Throwable throwable = event.getSubStepThrowable();
    if (throwable == null)
    {
        updateStepStatus(Status.PASSED);
        stopStep();
    }
    else
    {
        stopStep(StatusProvider.getStatus(throwable), getStatusDetailsFromThrowable(throwable));
    }
}
 
Example #4
Source File: ValidityConditionHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final ConditionEvent.Unsatisfied event) {
  if (event.getCondition() == nexusActiveCondition) {
    releaseValidity();
  }
  else if (event.getCondition() == validityCondition) {
    reference.disable();
    try {
      capabilityRegistry.remove(reference.context().id());
    }
    catch (Exception e) {
      log.error("Failed to remove capability with id '{}'", reference.context().id(), e);
    }
  }
}
 
Example #5
Source File: RepositoryAuditor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final RepositoryEvent event) {
  if (isRecording()) {
    Repository repository = event.getRepository();
    AuditData data = new AuditData();
    data.setDomain(DOMAIN);
    data.setType(type(event.getClass()));
    data.setContext(repository.getName());

    if (event instanceof RepositoryCreatedEvent || event instanceof RepositoryUpdatedEvent) {
      data.setAttributes(createFullAttributes(repository));
    }
    else {
      data.setAttributes(createSimple(repository));
    }

    record(data);
  }
}
 
Example #6
Source File: LoggingAuditor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final LoggerLevelChangedEvent event) {
  if (isRecording()) {
    String logger = event.getLogger();
    LoggerLevel level = event.getLevel();

    AuditData data = new AuditData();
    data.setDomain(DOMAIN);
    data.setType(CHANGED_TYPE);
    data.setContext(logger);

    Map<String, Object> attributes = data.getAttributes();
    attributes.put("logger", logger);
    attributes.put("level", string(level));
    record(data);
  }
}
 
Example #7
Source File: EmailAuditor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final EmailConfigurationChangedEvent event) {
  if (isRecording()) {
    EmailConfiguration configuration = event.getConfiguration();

    AuditData data = new AuditData();
    data.setDomain(DOMAIN);
    data.setType(CHANGED_TYPE);
    data.setContext(SYSTEM_CONTEXT);

    Map<String, Object> attributes = data.getAttributes();
    attributes.put("enabled", string(configuration.isEnabled()));
    attributes.put("host", configuration.getHost());
    attributes.put("port", string(configuration.getPort()));
    attributes.put("username", configuration.getUsername());
    attributes.put("fromAddress", configuration.getFromAddress());
    attributes.put("subjectPrefix", configuration.getSubjectPrefix());

    // TODO: various ssl/tls/trust-store shit

    record(data);
  }
}
 
Example #8
Source File: RepositoryConditionSupport.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final CapabilityEvent.AfterUpdate event) {
  if (event.getReference().context().id().equals(capabilityIdentity)) {
    if (!sameRepositoryAs(repositoryBeforeLastUpdate)) {
      try {
        bindLock.writeLock().lock();
        for (final Repository repository : repositoryManager.browse()) {
          handle(new RepositoryCreatedEvent(repository));
        }
      }
      finally {
        bindLock.writeLock().unlock();
      }
    }
  }
}
 
Example #9
Source File: TaskAuditor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final TaskEvent event) {
  if (isRecording()) {
    TaskInfo task = event.getTaskInfo();
    TaskConfiguration configuration = task.getConfiguration();

    AuditData data = new AuditData();
    data.setDomain(DOMAIN);
    data.setType(type(event.getClass()));
    data.setContext(configuration.getTypeName());

    Map<String, Object> attributes = data.getAttributes();
    // TaskInfo.{id/name/message} are all delegates to configuration
    attributes.put("schedule", string(task.getSchedule()));
    attributes.put("currentState", string(task.getCurrentState()));
    attributes.put("lastRunState", string(task.getLastRunState()));

    // TODO: may want to use TaskDescriptor to provider better comprehension of the configuration
    // TODO: ... for now though, just include everything its simpler
    attributes.putAll(configuration.asMap());

    record(data);
  }
}
 
Example #10
Source File: RealmAuditor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final RealmConfigurationChangedEvent event) {
  if (isRecording()) {
    RealmConfiguration configuration = event.getConfiguration();

    AuditData data = new AuditData();
    data.setDomain(DOMAIN);
    data.setType(CHANGED_TYPE);
    data.setContext(SYSTEM_CONTEXT);

    Map<String, Object> attributes = data.getAttributes();
    attributes.put("realms", string(configuration.getRealmNames()));

    record(data);
  }
}
 
Example #11
Source File: CapabilityOfTypeActiveCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final CapabilityEvent.AfterActivated event) {
  if (!isSatisfied() && type.equals(event.getReference().context().type())) {
    checkAllCapabilities();
  }
}
 
Example #12
Source File: NpmSearchIndexSubscriber.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * On package root {@link Asset} change event (any change, CREATE, UPDATE or DELETE), the owning repository's cached
 * index document should be invalidated.
 */
@Subscribe
@AllowConcurrentEvents
public void on(final EntityBatchEvent batchEvent) {
  // skip when replicating, origin node will delete any search indexes
  if (!EventHelper.isReplicating()) {
    for (final EntityEvent event : batchEvent.getEvents()) {
      final Repository npmAssetRepository = filterNpmAssetRepository(event);
      if (npmAssetRepository != null) {
        invalidateCachedSearchIndex(npmAssetRepository);
      }
    }
  }
}
 
Example #13
Source File: PassivateCapabilityDuringUpdateCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final CapabilityEvent.AfterUpdate event) {
  if (event.getReference().context().id().equals(id)) {
    setSatisfied(true);
  }
}
 
Example #14
Source File: CompositeConditionSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final ConditionEvent.Satisfied event) {
  if (shouldReevaluateFor(event.getCondition())) {
    setSatisfied(reevaluate(conditions));
  }
}
 
Example #15
Source File: MavenHostedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final EntityBatchEvent batchEvent) {
  // are we affected by this event?
  boolean deleteCatalog = false;
  for (final EntityEvent event : batchEvent.getEvents()) {
    if (event instanceof ComponentEvent) {
      final ComponentEvent componentEvent = (ComponentEvent) event;
      if (getRepository().getName().equals(componentEvent.getRepositoryName()) &&
          MAVEN_ARCHETYPE_PACKAGING.equals(
              componentEvent.getComponent().formatAttributes().get(Attributes.P_PACKAGING, String.class))) {
        deleteCatalog = true;
        break;
      }
    }
  }

  if (deleteCatalog) {
    UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
    try {
      TransactionalDeleteBlob.operation.throwing(IOException.class).call(() ->
          MavenFacetUtils.deleteWithHashes(mavenFacet, archetypeCatalogMavenPath)
      );
    }
    catch (IOException e) {
      log.warn("Could not delete {}", archetypeCatalogMavenPath, e);
    }
    finally {
      UnitOfWork.end();
    }
  }
}
 
Example #16
Source File: NexusAuthenticationEventAuditor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final NexusAuthenticationEvent event) {
  Set<AuthenticationFailureReason> failureReasonsToLog = getFailureReasonsToLog(event);

  if (isRecording() && !failureReasonsToLog.isEmpty()) {
    AuditData auditData = new AuditData();

    auditData.setType("authentication");
    auditData.setDomain(DOMAIN);
    auditData.setTimestamp(event.getEventDate());

    Map<String, Object> attributes = auditData.getAttributes();
    attributes.put("failureReasons", failureReasonsToLog);
    attributes.put("wasSuccessful", event.isSuccessful());

    if (event.getClientInfo() != null) {
      ClientInfo clientInfo = event.getClientInfo();
      attributes.put("userId", clientInfo.getUserid());
      attributes.put("remoteIp", clientInfo.getRemoteIP());
      attributes.put("userAgent", clientInfo.getUserAgent());
      attributes.put("path", clientInfo.getPath());
    }

    record(auditData);
  }
}
 
Example #17
Source File: OrientNpmGroupFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Subscribe
@Guarded(by = STARTED)
@AllowConcurrentEvents
public void on(final AssetUpdatedEvent updated) {
  if (matchingEvent(updated) && hasBlobBeenUpdated(updated)) {
    invalidatePackageRoot(updated);
  }
}
 
Example #18
Source File: CapabilityOfTypeExistsCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final CapabilityEvent.Created event) {
  if (!isSatisfied() && type.equals(event.getReference().context().type())) {
    checkAllCapabilities();
  }
}
 
Example #19
Source File: RepositoryExistsCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final RepositoryDeletedEvent event) {
  if (sameRepositoryAs(event.getRepository().getName())) {
    setSatisfied(false);
  }
}
 
Example #20
Source File: NpmProxyCacheInvalidatorFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
protected void on(final RepositoryUpdatedEvent event) {
  final Repository repository = event.getRepository();

  repository.optionalFacet(NpmProxyFacet.class).ifPresent(npm -> {
    if (!Objects.equals(getRemoteUrl(repository.getConfiguration()), getRemoteUrl(event.getOldConfiguration()))) {
      npm.invalidateProxyCaches();
    }
  });
}
 
Example #21
Source File: RepositoryExistsCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@AllowConcurrentEvents
@Subscribe
public void handle(final RepositoryCreatedEvent event) {
  if (sameRepositoryAs(event.getRepository().getName())) {
    setSatisfied(true);
  }
}
 
Example #22
Source File: RepositoryConditionSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final CapabilityEvent.BeforeUpdate event) {
  if (event.getReference().context().id().equals(capabilityIdentity)) {
    repositoryBeforeLastUpdate = getRepositoryName();
  }
}
 
Example #23
Source File: LegacyHttpBridgeService.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final CapabilityEvent event) {
  if (event.getReference().context().descriptor().type().equals(LegacyUrlCapabilityDescriptor.TYPE)) {
    toggleLegacyHttpBridgeModule();
  }
}
 
Example #24
Source File: CapabilityAuditor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final CapabilityEvent event) {
  if (isRecording()) {
    CapabilityReference reference = event.getReference();
    CapabilityContext context = reference.context();
    CapabilityDescriptor descriptor = context.descriptor();

    AuditData data = new AuditData();
    data.setDomain(DOMAIN);
    data.setType(type(event.getClass()));
    data.setContext(context.type().toString());

    Map<String, Object> attributes = data.getAttributes();
    attributes.put("id", context.id().toString());
    attributes.put("type", context.type().toString());
    attributes.put("enabled", string(context.isEnabled()));
    attributes.put("active", string(context.isActive()));
    attributes.put("failed", string(context.hasFailure()));

    // include all non-secure properties
    Map<String,FormField> fields = fields(descriptor);
    for (Entry<String,String> entry : context.properties().entrySet()) {
      FormField field = fields.get(entry.getKey());
      // skip secure fields
      if (field instanceof Encrypted) {
        continue;
      }
      attributes.put("property." + entry.getKey(), entry.getValue());
    }

    record(data);
  }
}
 
Example #25
Source File: RouterChangeListener.java    From mpush with Apache License 2.0 5 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
void on(RouterChangeEvent event) {
    String userId = event.userId;
    Router<?> r = event.router;
    if (r.getRouteType().equals(Router.RouterType.LOCAL)) {
        sendKickUserMessage2Client(userId, (LocalRouter) r);
    } else {
        sendKickUserMessage2MQ(userId, (RemoteRouter) r);
    }
}
 
Example #26
Source File: NexusTaskNotificationEmailSender.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sends alert emails if necessary on failure.
 */
@Subscribe
@AllowConcurrentEvents
public void on(final TaskEventStoppedFailed event) {
  final TaskInfo taskInfo = event.getTaskInfo();
  if (!haveAlertEmail(taskInfo)) {
    return;
  }
  String body = taskNotificationMessageGenerator(taskInfo.getTypeId()).failed(taskInfo, event.getFailureCause());
  log.trace("sending message {}", body);
  sendEmail("Task execution failure", taskInfo.getConfiguration().getAlertEmail(), body);
}
 
Example #27
Source File: CapabilityHasNoFailuresCondition.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@AllowConcurrentEvents
@Subscribe
public void handle(final CallbackFailureCleared event) {
  if (event.getReference().context().id().equals(context.id())) {
    failingAction = null;
    failure = null;
    setSatisfied(true);
  }
}
 
Example #28
Source File: ClientDefaultInitializer.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void onRequestOut(InvocationFinishEvent finishEvent) {
  if (InvocationType.CONSUMER.equals(finishEvent.getInvocation().getInvocationType())) {
      LOGGER.info(accessLogGenerator.generateClientLog(finishEvent));
  }
}
 
Example #29
Source File: AssetBlobCleanupTaskManager.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Subscribe
@AllowConcurrentEvents
public void on(final TaskDeletedEvent event) {
  TaskInfo taskInfo = event.getTaskInfo();
  if (TYPE_ID.equals(taskInfo.getTypeId())) {
    TaskConfiguration taskConfiguration = taskInfo.getConfiguration();
    String format = taskConfiguration.getString(FORMAT_FIELD_ID);
    String contentStore = taskConfiguration.getString(CONTENT_STORE_FIELD_ID);
    activeFormatStores.remove(format, contentStore);
  }
}
 
Example #30
Source File: SimpleSubscriber.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public SimpleSubscriber(Object instance, Method method) {
  this.instance = instance;
  this.method = method;

  enableExceptionPropagation = method.getAnnotation(EnableExceptionPropagation.class) != null;
  SubscriberOrder subscriberOrder = method.getAnnotation(SubscriberOrder.class);
  if (subscriberOrder != null) {
    order = subscriberOrder.value();
  }

  try {
    lambda = LambdaMetafactoryUtils.createLambda(instance, method, Consumer.class);
  } catch (Throwable throwable) {
    // because enhance LambdaMetafactoryUtils to support ALL_MODES by reflect
    // never run into this branch.
    // otherwise create a listener instance of anonymous class will run into this branch
    LOGGER.warn("Failed to create lambda for method: {}, fallback to reflect.", method, throwable);

    checkAccess(method);
    lambda = event -> {
      try {
        method.invoke(instance, event);
      } catch (Throwable e) {
        LOGGER.warn("Failed to call event listener {}.", method.getName());
        throw new IllegalStateException(e);
      }
    };
  }

  dispatcher = this::syncDispatch;
  if (method.getAnnotation(AllowConcurrentEvents.class) != null) {
    dispatcher = this::concurrentDispatch;
  }
}