Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederikheremans/0a525a660636b92481d4 to your computer and use it in GitHub Desktop.
Save frederikheremans/0a525a660636b92481d4 to your computer and use it in GitHub Desktop.
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.web.scripts;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.extensions.surf.persister.PersisterService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.extensions.surf.ModuleDeploymentService;
import org.springframework.extensions.surf.persister.CachedPersister;
import org.springframework.extensions.surf.types.ModuleDeployment;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Joram Barrez
*/
public class ReloadModuleDeploymentsWebscript extends DeclarativeWebScript implements ApplicationContextAware
{
private ApplicationContext applicationContext;
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, CachedPersister> persisters = applicationContext.getBeansOfType(CachedPersister.class);
for (CachedPersister persister : persisters.values())
{
persister.invalidateCache();
}
ModuleDeploymentService moduleDeploymentService = applicationContext.getBean(ModuleDeploymentService.class);
// I'm not very proud on this. But it's really very temporary.
try
{
Class moduleDeploymentClass = moduleDeploymentService.getClass();
Field field = moduleDeploymentClass.getDeclaredField("configuredModules");
field.setAccessible(true);
field.set(moduleDeploymentService, null);
field = moduleDeploymentClass.getDeclaredField("deployedModules");
field.setAccessible(true);
field.set(moduleDeploymentService, null);
// Call the following method will also trigger a reload from the persisted extensions
List<ModuleDeployment> moduleDeployments = moduleDeploymentService.getDeployedModules();
System.out.println("Found " + moduleDeployments.size() + " module deployments");
PersisterService persister = applicationContext.getBean(PersisterService.class);
persister.init();
} catch (Exception e) {
e.printStackTrace();
}
return new HashMap<String, Object>();
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
this.applicationContext = applicationContext;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment