mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-8832 Fix Event Outbox shutdown (#2959)
* ACS-8832 Add destroy method in EventSender * ACS-8832 Rename * ACS-8832 Reformat
This commit is contained in:
@@ -38,6 +38,12 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.domain.node.TransactionEntity;
|
||||
import org.alfresco.repo.event.v1.model.DataAttributes;
|
||||
@@ -81,11 +87,6 @@ import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.alfresco.util.TriPredicate;
|
||||
import org.alfresco.util.transaction.TransactionListenerAdapter;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||
|
||||
/**
|
||||
* Generates events and sends them to an event topic.
|
||||
@@ -417,8 +418,7 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link NodeEventConsolidator} for the supplied {@code nodeRef} from
|
||||
* the current transaction context.
|
||||
* @return the {@link NodeEventConsolidator} for the supplied {@code nodeRef} from the current transaction context.
|
||||
*/
|
||||
protected NodeEventConsolidator getEventConsolidator(NodeRef nodeRef)
|
||||
{
|
||||
@@ -438,7 +438,6 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
return eventConsolidator;
|
||||
}
|
||||
|
||||
|
||||
protected Consolidators getTxnConsolidators(Object resourceKey)
|
||||
{
|
||||
Consolidators consolidators = AlfrescoTransactionSupport.getResource(resourceKey);
|
||||
@@ -451,8 +450,7 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link ChildAssociationEventConsolidator} for the supplied {@code childAssociationRef} from
|
||||
* the current transaction context.
|
||||
* @return the {@link ChildAssociationEventConsolidator} for the supplied {@code childAssociationRef} from the current transaction context.
|
||||
*/
|
||||
private ChildAssociationEventConsolidator getEventConsolidator(ChildAssociationRef childAssociationRef)
|
||||
{
|
||||
@@ -473,8 +471,7 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link PeerAssociationEventConsolidator} for the supplied {@code peerAssociationRef} from
|
||||
* the current transaction context.
|
||||
* @return the {@link PeerAssociationEventConsolidator} for the supplied {@code peerAssociationRef} from the current transaction context.
|
||||
*/
|
||||
private PeerAssociationEventConsolidator getEventConsolidator(AssociationRef peerAssociationRef)
|
||||
{
|
||||
@@ -528,8 +525,7 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
childAssociationRef.getQName(),
|
||||
childAssociationRef.getChildRef(),
|
||||
childAssociationRef.isPrimary(),
|
||||
childAssociationRef.getNthSibling()
|
||||
);
|
||||
childAssociationRef.getNthSibling());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -546,7 +542,10 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
@Override
|
||||
protected void onShutdown(ApplicationEvent applicationEvent)
|
||||
{
|
||||
//NOOP
|
||||
if (eventSender != null)
|
||||
{
|
||||
eventSender.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
protected class EventTransactionListener extends TransactionListenerAdapter
|
||||
@@ -586,8 +585,7 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a node transaction is not only active, but also committed with modifications.
|
||||
* This means that a {@link TransactionEntity} object was created.
|
||||
* @return true if a node transaction is not only active, but also committed with modifications. This means that a {@link TransactionEntity} object was created.
|
||||
*/
|
||||
protected boolean isTransactionCommitted()
|
||||
{
|
||||
@@ -601,7 +599,8 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
try
|
||||
{
|
||||
sendEvents();
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Must consume the exception to protect other TransactionListeners
|
||||
LOGGER.error("Unexpected error while sending repository events", e);
|
||||
@@ -650,11 +649,16 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
/**
|
||||
* Handles all kinds of events and sends them within dedicated transaction.
|
||||
*
|
||||
* @param entityReference - reference to an entity (e.g. node, child association, peer association)
|
||||
* @param eventConsolidator - object encapsulating events occurred in a transaction
|
||||
* @param entityToEventEligibilityVerifier - allows to verify if entity is eligible to generate an even. If null no verification is necessary
|
||||
* @param <REF> - entity reference type (e.g. {@link NodeRef}, {@link AssociationRef}, {@link ChildAssociationRef})
|
||||
* @param <CON> - event consolidator type - extension of {@link EventConsolidator}
|
||||
* @param entityReference
|
||||
* - reference to an entity (e.g. node, child association, peer association)
|
||||
* @param eventConsolidator
|
||||
* - object encapsulating events occurred in a transaction
|
||||
* @param entityToEventEligibilityVerifier
|
||||
* - allows to verify if entity is eligible to generate an even. If null no verification is necessary
|
||||
* @param <REF>
|
||||
* - entity reference type (e.g. {@link NodeRef}, {@link AssociationRef}, {@link ChildAssociationRef})
|
||||
* @param <CON>
|
||||
* - event consolidator type - extension of {@link EventConsolidator}
|
||||
*/
|
||||
private <REF extends EntityRef, CON extends EventConsolidator<REF, ? extends Resource>> void sendEvent(
|
||||
final REF entityReference, final CON eventConsolidator, final TriPredicate<REF, CON, EventInfo> entityToEventEligibilityVerifier)
|
||||
@@ -676,12 +680,18 @@ public class EventGenerator extends AbstractLifecycleBean implements Initializin
|
||||
/**
|
||||
* Creates events from various kinds of entities.
|
||||
*
|
||||
* @param entityReference - reference to an entity (e.g. node, child association, peer association)
|
||||
* @param eventConsolidator - object encapsulating events occurred in a transaction
|
||||
* @param eventInfo - object holding the event information
|
||||
* @param entityToEventEligibilityVerifier - allows to verify if entity is eligible to generate an even. If null no verification is necessary
|
||||
* @param <REF> - entity reference type (e.g. {@link NodeRef}, {@link AssociationRef}, {@link ChildAssociationRef})
|
||||
* @param <CON> - event consolidator type - extension of {@link EventConsolidator}
|
||||
* @param entityReference
|
||||
* - reference to an entity (e.g. node, child association, peer association)
|
||||
* @param eventConsolidator
|
||||
* - object encapsulating events occurred in a transaction
|
||||
* @param eventInfo
|
||||
* - object holding the event information
|
||||
* @param entityToEventEligibilityVerifier
|
||||
* - allows to verify if entity is eligible to generate an even. If null no verification is necessary
|
||||
* @param <REF>
|
||||
* - entity reference type (e.g. {@link NodeRef}, {@link AssociationRef}, {@link ChildAssociationRef})
|
||||
* @param <CON>
|
||||
* - event consolidator type - extension of {@link EventConsolidator}
|
||||
*/
|
||||
private <REF extends EntityRef, CON extends EventConsolidator<REF, ? extends Resource>> Optional<RepoEvent<?>> createEvent(
|
||||
final REF entityReference, final CON eventConsolidator, final EventInfo eventInfo,
|
||||
|
@@ -37,19 +37,28 @@ public interface EventSender
|
||||
{
|
||||
/**
|
||||
* Accepts a callback function creating an event and sends this event to specified destination.
|
||||
* @param eventProducer - callback function that creates an event
|
||||
*
|
||||
* @param eventProducer
|
||||
* - callback function that creates an event
|
||||
*/
|
||||
void accept(Callable<Optional<RepoEvent<?>>> eventProducer);
|
||||
|
||||
/**
|
||||
* It's called right after event sender instantiation (see {@link org.alfresco.repo.event2.EventSenderFactoryBean}).
|
||||
* It might be used to initialize the sender implementation.
|
||||
* It's called right after event sender instantiation (see {@link org.alfresco.repo.event2.EventSenderFactoryBean}). It might be used to initialize the sender implementation.
|
||||
*/
|
||||
default void initialize()
|
||||
{
|
||||
// no initialization by default
|
||||
}
|
||||
|
||||
/**
|
||||
* It's called when the application context is closing, allowing {@link org.alfresco.repo.event2.EventGenerator} to perform cleanup operations.
|
||||
*/
|
||||
default void destroy()
|
||||
{
|
||||
// no destruction by default
|
||||
}
|
||||
|
||||
default boolean shouldParticipateInTransaction()
|
||||
{
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user