| Method from org.jboss.system.server.profileservice.ProfileServiceBootstrap Detail: |
protected T getBean(KernelController controller,
Object name,
Class expectedType) {
ControllerContext context = controller.getInstalledContext(name);
if (context == null)
throw new IllegalStateException("Context not installed: " + name);
Object result = context.getTarget();
if (result == null)
throw new IllegalStateException("No target for " + name);
if (expectedType.isInstance(result) == false)
throw new IllegalStateException(name + " expected " + expectedType.getName() + " was " + result.getClass().getName());
return expectedType.cast(result);
}
|
public Kernel getKernel() {
return kernel;
}
|
public MainDeployer getMainDeployer() {
return mainDeployer;
}
Return the MainDeployer bean. |
public ProfileService getProfileService() {
return profileService;
}
Return the ProfileService bean. |
protected void loadProfile(String name) throws Exception {
MainDeployer deployer = getMainDeployer();
if (deployer == null)
throw new NullPointerException("MainDeployer has not been set");
ProfileService ps = getProfileService();
if (ps == null)
throw new NullPointerException("ProfileService has not been set");
// Load the named profile
ProfileKey key = new ProfileKey(name);
Profile profile = ps.getProfile(key);
// HACK
VFSDeployment first = null;
// Deploy the bootstrap
Collection< VFSDeployment > boostraps = profile.getDeployments(DeploymentPhase.BOOTSTRAP);
for (VFSDeployment d : boostraps)
{
deployer.addDeployment(d);
if (first == null)
first = d;
}
deployer.process();
deployer.checkComplete();
Thread thread = Thread.currentThread();
ClassLoader old = thread.getContextClassLoader();
// FIXME remove this hack
MainDeployerImpl hack = (MainDeployerImpl) deployer;
ClassLoader cl = null;
if (first != null)
{
DeploymentContext ctx = hack.getDeploymentContext(first.getName());
if (ctx != null)
cl = ctx.getClassLoader();
}
//if (cl != null)
// thread.setContextClassLoader(cl);
try
{
// Deploy the profile deployers
Collection< VFSDeployment > profileDeployers = profile.getDeployments(DeploymentPhase.DEPLOYER);
for (VFSDeployment d : profileDeployers)
deployer.addDeployment(d);
deployer.process();
deployer.checkComplete();
// Deploy the profile applications
Collection< VFSDeployment > profileDeployments = profile.getDeployments(DeploymentPhase.APPLICATION);
for (VFSDeployment d : profileDeployments)
deployer.addDeployment(d);
deployer.process();
deployer.checkComplete();
}
finally
{
thread.setContextClassLoader(old);
}
}
Load the deployments associated with the named profile and deploy them
using the MainDeployer. |
public void prepareShutdown(Server server) {
shutdown.set(true);
if (mainDeployer != null)
mainDeployer.prepareShutdown();
}
|
public void setKernel(Kernel kernel) {
this.kernel = kernel;
}
|
public void shutdown(Server server) {
unloadProfile(profileName);
try
{
mainDeployer.shutdown();
}
catch (Throwable t)
{
log.warn("Error shutting down the main deployer", t);
}
}
|
public void start(Server server) throws Exception {
shutdown.set(false);
KernelController controller = kernel.getController();
// Get the beans TODO injection!
profileService = getBean(controller, "ProfileService", ProfileService.class);
log.debug("Using ProfileService: " + profileService);
mainDeployer = getBean(controller, "MainDeployer", MainDeployer.class);
log.debug("Using MainDeployer: " + mainDeployer);
// Validate that everything is ok
mainDeployer.checkComplete();
// Load the profile beans
try
{
loadProfile(profileName);
}
catch (IncompleteDeploymentException e)
{
log.error("Failed to load profile: " + e.getMessage());
}
catch (Exception e)
{
log.error("Failed to load profile: ", e);
}
// Mark the profile as ready for hotdeployment if supported
Profile profile = profileService.getActiveProfile();
if( profile != null )
profile.enableModifiedDeploymentChecks(true);
}
|
protected void unload(MainDeployer deployer,
Collection deployments) {
if (deployments == null || deployments.isEmpty())
return;
for (VFSDeployment d : deployments)
{
try
{
deployer.removeDeployment(d);
}
catch (Exception e)
{
log.warn("Unable to remove deployment: " + d);
}
}
deployer.process();
}
Unload a set of deployments |
protected void unloadProfile(String name) {
MainDeployer deployer = getMainDeployer();
if (deployer == null)
{
log.warn("MainDeployer has not been set");
return;
}
ProfileService ps = getProfileService();
if (ps == null)
{
log.warn("ProfileService has not been set");
return;
}
try
{
// Load the named profile
ProfileKey key = new ProfileKey(name);
Profile profile = ps.getProfile(key);
// HACK
VFSDeployment first = null;
// Deploy the bootstrap
Collection< VFSDeployment > boostraps = profile.getDeployments(DeploymentPhase.BOOTSTRAP);
for (VFSDeployment d : boostraps)
{
if (first == null)
{
first = d;
break;
}
}
Thread thread = Thread.currentThread();
ClassLoader old = thread.getContextClassLoader();
// FIXME remove this hack
MainDeployerImpl hack = (MainDeployerImpl) deployer;
ClassLoader cl = null;
if (first != null)
{
try
{
DeploymentContext ctx = hack.getDeploymentContext(first.getName());
if (ctx != null)
cl = ctx.getClassLoader();
}
catch (Exception e)
{
log.debug("Unable to get first deployment", e);
}
}
//if (cl != null)
// thread.setContextClassLoader(cl);
try
{
// Undeploy the applications
unload(deployer, profile.getDeployments(DeploymentPhase.APPLICATION));
// Undeploy the deployers
unload(deployer, profile.getDeployments(DeploymentPhase.DEPLOYER));
// Undeploy the bootstrap
unload(deployer, profile.getDeployments(DeploymentPhase.BOOTSTRAP));
}
finally
{
thread.setContextClassLoader(old);
}
}
catch (Throwable t)
{
log.warn("Error unloading profile", t);
}
}
Unload the deployments associated with the named profile and undeploy them
using the MainDeployer in reverse phase order. |