Feature event publishing (#884)
* refactored code to use EventPublisherHolder for publishing application events where possible Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * fixed comment Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
2b5b8b4a63
commit
c68c5a6f5b
@@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupsValidation;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.integration.support.locks.LockRegistry;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.AsyncResult;
|
||||
@@ -45,8 +44,6 @@ public abstract class AbstractRolloutManagement implements RolloutManagement {
|
||||
|
||||
protected final ApplicationContext context;
|
||||
|
||||
protected final ApplicationEventPublisher eventPublisher;
|
||||
|
||||
protected final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
|
||||
protected final PlatformTransactionManager txManager;
|
||||
@@ -60,15 +57,14 @@ public abstract class AbstractRolloutManagement implements RolloutManagement {
|
||||
protected AbstractRolloutManagement(final TargetManagement targetManagement,
|
||||
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
|
||||
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
||||
final ApplicationEventPublisher eventPublisher, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final PlatformTransactionManager txManager, final TenantAware tenantAware, final LockRegistry lockRegistry,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
||||
final TenantAware tenantAware, final LockRegistry lockRegistry,
|
||||
final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
||||
this.targetManagement = targetManagement;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
this.rolloutGroupManagement = rolloutGroupManagement;
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.context = context;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
this.txManager = txManager;
|
||||
this.tenantAware = tenantAware;
|
||||
|
||||
@@ -10,26 +10,28 @@ package org.eclipse.hawkbit.repository.model.helper;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.cloud.bus.ServiceMatcher;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
/**
|
||||
* A singleton bean which holds the event publisher to have to the cache manager
|
||||
* in beans not instantiated by spring e.g. JPA entities or
|
||||
* CacheFieldEntityListener which cannot be autowired.
|
||||
* A singleton bean which holds the event publisher and service origin Id in
|
||||
* order to publish remote application events. It can be used in beans not
|
||||
* instantiated by spring e.g. JPA entities which cannot be auto-wired.
|
||||
*/
|
||||
public final class EventPublisherHolder implements ApplicationContextAware {
|
||||
public final class EventPublisherHolder {
|
||||
|
||||
private static final EventPublisherHolder SINGLETON = new EventPublisherHolder();
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
private String applicationId;
|
||||
@Autowired(required = false)
|
||||
private ServiceMatcher serviceMatcher;
|
||||
|
||||
@Autowired
|
||||
private BusProperties bus;
|
||||
|
||||
private EventPublisherHolder() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,12 +48,11 @@ public final class EventPublisherHolder implements ApplicationContextAware {
|
||||
return eventPublisher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the service origin Id coming either from {@link ServiceMatcher}
|
||||
* when available or {@link BusProperties} otherwise.
|
||||
*/
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(final ApplicationContext applicationContext) {
|
||||
applicationId = applicationContext.getBean(BusProperties.class).getId();
|
||||
return serviceMatcher != null ? serviceMatcher.getServiceId() : bus.getId();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user