// if we are stopping a destination with an Application or Session scoped assembler, we may
// have to remove the assembler from the ServletContext or Session
if (factoryInstance != null)
{
MessageBroker mb = FlexContext.getMessageBroker();
String attributeId = factoryInstance.getAttributeId();
if (FlexFactory.SCOPE_APPLICATION.equals(factoryInstance.getScope()))
{
ServletContext ctx = FlexContext.getServletConfig().getServletContext();
// this should never be the case, but just in case
if (ctx == null)
return;
synchronized (ctx)
{
// remove from ServletContext if reference count is zero
int refCount = (mb != null) ? mb.decrementAttributeIdRefCount(attributeId) : 0;
if (refCount <= 0)
{
// remove assembler from servlet context
ctx.removeAttribute(attributeId);
}
}
}
else if (FlexFactory.SCOPE_SESSION.equals(factoryInstance.getScope()))
{
FlexSession session = FlexContext.getFlexSession();
// if this is being stopped during runtime config, we should have a session available to us
// However, if this is being stopped on MessageBroker shutdown, we will not have a session
// but do not need to worry about clean up in that case as the entire session will be cleaned up
if (session == null)
return;
// remove from Session if reference count is zero
int refCount = (mb != null) ? mb.decrementAttributeIdRefCount(attributeId) : 0;
if (refCount <= 0)
{
// remove assembler from servlet context
session.removeAttribute(attributeId);
}