if (!isHotDeployEnabled(init))
{
return;
}
ReentrantLock lock = new ReentrantLock();
if (lock.tryLock(500, TimeUnit.MILLISECONDS))
{
try
{
hotDeploymentStrategy = createHotDeployment(Thread.currentThread().getContextClassLoader(), isHotDeployEnabled(init));
boolean changed = new TimestampCheckForwardingDeploymentStrategy()
{
@Override
protected DeploymentStrategy delegate()
{
return hotDeploymentStrategy;
}
}.changedSince(init.getTimestamp());
if (hotDeploymentStrategy.available() && changed)
{
ServletLifecycle.beginReinitialization(request);
Contexts.getEventContext().set(HotDeploymentStrategy.NAME, hotDeploymentStrategy);
hotDeploymentStrategy.scan();
if (hotDeploymentStrategy.getTimestamp() > init.getTimestamp())
{
log.info("redeploying components");
Seam.clearComponentNameCache();
for ( String name: init.getHotDeployableComponents() )
{
Component component = Component.forName(name);
if (component!=null)
{
ScopeType scope = component.getScope();
if ( scope!=ScopeType.STATELESS && scope.isContextActive() )
{
scope.getContext().remove(name);
}
init.removeObserverMethods(component);
}
Contexts.getApplicationContext().remove(name + COMPONENT_SUFFIX);
}
init.getHotDeployableComponents().clear();
installHotDeployableComponents();
installComponents(init);
log.info("done redeploying components");
}
// update the timestamp outside of the second timestamp check to be sure we don't cause an unnecessary scan
// the second scan checks annotations (the slow part) which might happen to exclude the most recent file
init.setTimestamp(System.currentTimeMillis());
ServletLifecycle.endReinitialization();
}
final WarRootDeploymentStrategy warRootDeploymentStrategy = new WarRootDeploymentStrategy(Thread.currentThread().getContextClassLoader(), warRoot, new File[] { warClassesDirectory, warLibDirectory, hotDeployDirectory });
changed = new TimestampCheckForwardingDeploymentStrategy()
{
@Override
protected DeploymentStrategy delegate()
{
return warRootDeploymentStrategy;
}
}.changedSince(init.getWarTimestamp());
if (changed)
{
warRootDeploymentStrategy.scan();
if (warRootDeploymentStrategy.getTimestamp() > init.getWarTimestamp())
{
log.info("redeploying page descriptors...");
Pages pages = (Pages) ServletLifecycle.getServletContext().getAttribute(Seam.getComponentName(Pages.class));
if (pages != null) {
// application context is needed for creating expressions
Lifecycle.setupApplication();
pages.initialize(warRootDeploymentStrategy.getDotPageDotXmlFileNames());
Lifecycle.cleanupApplication();
}
ServletLifecycle.getServletContext().removeAttribute(Seam.getComponentName(Exceptions.class));
init.setWarTimestamp(warRootDeploymentStrategy.getTimestamp());
log.info("done redeploying page descriptors");
}
}
}
finally
{
lock.unlock();
}
}
}