Set<Exception> exceptions = new LinkedHashSet<>();
// Before Passivation Events
if( fireEvents )
{
ActivationEvent event = new ActivationEvent( target, PASSIVATING );
for( ActivationEventListener listener : listeners )
{
try
{
listener.onEvent( event );
}
catch( Exception ex )
{
if( ex instanceof PassivationException )
{
exceptions.addAll( ( (PassivationException) ex ).causes() );
}
else
{
exceptions.add( ex );
}
}
}
}
// Before Passivation for Activators
if( targetActivators != null )
{
try
{
targetActivators.beforePassivation( target );
}
catch( PassivationException ex )
{
exceptions.addAll( ex.causes() );
}
catch( Exception ex )
{
exceptions.add( ex );
}
}
// Passivation
while( !activeChildren.isEmpty() )
{
passivateOneChild( exceptions );
}
// Internal Passivation Callback
if( callback != null )
{
try
{
callback.run();
}
catch( Exception ex )
{
if( ex instanceof PassivationException )
{
exceptions.addAll( ( (PassivationException) ex ).causes() );
}
else
{
exceptions.add( ex );
}
}
}
// After Passivation for Activators
if( targetActivators != null )
{
try
{
targetActivators.afterPassivation( target instanceof ServiceReference
? new PassiveServiceReference( (ServiceReference) target )
: target );
}
catch( PassivationException ex )
{
exceptions.addAll( ex.causes() );
}
catch( Exception ex )
{
exceptions.add( ex );
}
}
targetActivators = null;
// After Passivation Events
if( fireEvents )
{
ActivationEvent event = new ActivationEvent( target, PASSIVATED );
for( ActivationEventListener listener : listeners )
{
try
{
listener.onEvent( event );