}
register = false;
}
// try to get the PA from database by context name
MutablePortletApplication pa = registry.getPortletApplication(contextName);
if (pa != null)
{
if (log.isDebugEnabled())
{
log.debug("Portlet Application " + contextName + " found in registry.");
}
if ( pa.getApplicationType() != paType )
{
throw new RegistryException("Cannot start portlet application "+contextName+": as Application Types don't match: " + pa.getApplicationType() + " != " + paType);
}
if (!monitored && changeMonitor != null)
{
changeMonitor.remove(contextName);
}
if (log.isDebugEnabled())
{
log.debug("unregistering portlet application " + contextName + "...");
}
portletFactory.unregisterPortletApplication(pa);
}
// if (register && (pa == null || checksum != pa.getChecksum()))
if (register)
{
if (pa == null)
{
// new
try
{
if (log.isDebugEnabled())
{
log.debug("Register new portlet application " + contextName + ".");
}
pa = registerPortletApplication(paWar, pa, paType, paClassLoader, silent);
}
catch (Exception e)
{
String msg = "Error register new portlet application " + contextName + ".";
if (log.isDebugEnabled())
{
log.debug(msg);
}
throw new RegistryException(msg);
}
}
else
{
if (log.isDebugEnabled())
{
log.debug("Re-register existing portlet application " + contextName + ".");
}
int status = nodeManager.checkNode(new Long(pa.getId().toString()), pa.getName());
boolean reregister = false;
boolean deploy = false;
switch (status)
{
case NodeManager.NODE_NEW:
{
if (log.isDebugEnabled())
{
log.debug("Node for Portlet application " + contextName + " is NEW.");
}
//only reason is that the file got somehow corrupted
// so we really do not know what is going on here...
// the best chance at this point is to reregister (which might be the absolute wrong choice)
log.warn("The portlet application " + pa.getName() + " is registered in the database but not locally .... we will reregister");
reregister = true;
if (checksum != pa.getChecksum())
{
log.warn("The provided portlet application " + pa.getName() + " is a different version than in the database (db-checksum=" + pa.getChecksum() + ", local-checksum=: " + checksum + ") .... we will redeploy (also to the database)");
deploy = true;
}
break;
}
case NodeManager.NODE_SAVED:
{
if (log.isDebugEnabled())
{
log.debug("Node for Portlet application " + contextName + " is SAVED.");
}
if (checksum != pa.getChecksum())
{
log.warn("The provided portlet application " + pa.getName() + " is a different version than in the local node info and the database (db-checksum=" + pa.getChecksum() + ", local-checksum=: " + checksum + ") .... we will reregister AND redeploy (also to the database)");
//database and local node info are in synch, so we assume that this is a brand new
// war .... let's deploy
reregister = true;
deploy = true;
}
break;
}
case NodeManager.NODE_OUTDATED:
{
// new version in database, maybe changed by a different cluster node
if (log.isDebugEnabled())
{
log.debug("Node for Portlet application " + contextName + " is OUTDATED (local PA.id < DB PA.id).");
}
//database version is older (determined by id) than the database
//let's deploy and reregister
if (checksum != pa.getChecksum())
{
log.error("The portlet application " + pa.getName() + " provided for the upgrade IS WRONG. The database checksum= " + pa.getChecksum() + ", but the local=" + checksum + "....THIS NEEDS TO BE CORRECTED");
// if the checksums do not match make sure the database is updated with the new PA from file system
// I've observed "unavailable PA" in clustered env for the cluster node that reported OUTDATED state
deploy = true;
}
reregister = true;
break;
}
}
if (deploy)
{
if (log.isDebugEnabled())
{
log.debug("Register (deploy=true) Portlet application " + contextName + " in database.");
}
pa = registerPortletApplication(paWar, pa, paType, paClassLoader, silent);
}
else
if (reregister)
{
if (log.isDebugEnabled())
{
log.debug("Re-Register (reregister=true) Portlet application " + contextName + ".");
}
// add to search engine result
this.updateSearchEngine(true, pa);
this.updateSearchEngine(false, pa);
// and add to the current node info
try
{
nodeManager.addNode(new Long(pa.getId().toString()), pa.getName());
} catch (Exception e)
{
log.error("Adding node for portlet application " + pa.getName() + " caused exception" , e);
}
}
}