|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.j2ee.deployment.impl; import org.openide.filesystems.FileUtil; import javax.enterprise.deploy.shared.ModuleType; import javax.enterprise.deploy.shared.StateType; import javax.enterprise.deploy.spi.*; import javax.enterprise.deploy.spi.status.*; import javax.enterprise.deploy.spi.exceptions.*; import org.netbeans.modules.j2ee.deployment.plugins.api.*; import org.netbeans.modules.j2ee.deployment.devmodules.api.*; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.deployment.impl.ui.DeployProgressUI; import org.openide.ErrorManager; import org.netbeans.modules.j2ee.deployment.execution.DeploymentTarget; import org.netbeans.modules.j2ee.deployment.execution.DeploymentConfigurationProvider; import org.openide.util.NbBundle; import org.openide.filesystems.FileObject; import java.util.Timer; import java.util.TimerTask; import java.util.*; import java.io.*; import javax.enterprise.deploy.model.DeployableObject; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; /** * Encapsulates a set of ServerTarget(s), provides a wrapper for deployment * help. This is a throw away object, that get created and used within * scope of one deployment execution. * * Typical user are ServerExecutor and Debugger code, with the following general sequence: * * TargetServer ts = new TargetServer(deploymentTarget); * ts.startTargets(deployProgressUI); * TargetModule[] tms = ts.deploy(deployProgressUI); * deploymentTarget.setTargetModules(tms); */ public class TargetServer { private static final long DISTRIBUTE_TIMEOUT = 120000; private static final long INCREMENTAL_TIMEOUT = 60000; private static final long TIMEOUT = 60000; private static final TargetModule[] EMPTY_TARGETMODULE_ARRAY = new TargetModule[0]; private Target[] targets; private final ServerInstance instance; private final DeploymentTarget dtarget; private IncrementalDeployment incremental; //null value signifies don't do incremental private boolean debugMode = false; private Map availablesMap = null; private Set deployedRootTMIDs = new HashSet(); // type TargetModule private Set undeployTMIDs = new HashSet(); // TMID private Set distributeTargets = new HashSet(); //Target private TargetModule[] redeployTargetModules = null; private File application = null; private File currentContentDir = null; private String contextRoot = null; private ProgressHandler startEventHandler = null; public TargetServer(DeploymentTarget target) { this.dtarget = target; this.instance = dtarget.getServer().getServerInstance(); } private void init(DeployProgressUI ui) { if (targets == null) { instance.start(ui); targets = dtarget.getServer().toTargets(); } incremental = instance.getIncrementalDeployment(); if (incremental != null && ! checkServiceImplementations()) incremental = null; try { FileObject contentFO = dtarget.getModule().getContentDirectory(); if (contentFO != null) { currentContentDir = FileUtil.toFile(contentFO); } // Note: configuration is not DO so will not be saved automatically on execute DeploymentConfigurationProvider dcp = dtarget.getDeploymentConfigurationProvider(); if (dcp != null) dcp.saveOnDemand(); } catch (IOException ioe) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); } J2eeModuleProvider.ConfigSupport configSupport = dtarget.getConfigSupport(); if (J2eeModule.WAR.equals(dtarget.getModule().getModuleType())) { contextRoot = configSupport.getWebContextRoot(); } processLastTargetModules(); } private boolean canFileDeploy(Target[] targetz, DeployableObject deployable) { if (targetz == null || targetz.length != 1) { ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, NbBundle.getMessage( TargetServer.class, "MSG_MoreThanOneIncrementalTargets")); return false; } if (!instance.getIncrementalDeployment().canFileDeploy(targetz[0], deployable)) return false; return true; } private boolean canFileDeploy(TargetModule[] targetModules, DeployableObject deployable) { if (targetModules == null || targetModules.length != 1) { ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, NbBundle.getMessage( TargetServer.class, "MSG_MoreThanOneIncrementalTargets")); return false; } if (!instance.getIncrementalDeployment().canFileDeploy(targetModules[0].getTarget(), deployable)) return false; return true; } private AppChangeDescriptor distributeChanges(TargetModule targetModule, DeployProgressUI ui) throws IOException { ServerFileDistributor sfd = new ServerFileDistributor(instance, dtarget); ui.setProgressObject(sfd); ModuleChangeReporter mcr = dtarget.getModuleChangeReporter(); AppChangeDescriptor acd = sfd.distribute(targetModule, mcr); return acd; } private File initialDistribute(Target target, DeployProgressUI ui) { InitialServerFileDistributor sfd = new InitialServerFileDistributor(dtarget, target); ui.setProgressObject(sfd); return sfd.distribute(); } private boolean checkServiceImplementations() { String missing = null; if (instance.getServer().getDeploymentPlanSplitter() == null) missing = DeploymentPlanSplitter.class.getName(); if (missing != null) { String msg = NbBundle.getMessage(ServerFileDistributor.class, "MSG_MissingServiceImplementations", missing); ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, msg); return false; } return true; } // return list of TargetModule to redeploy private TargetModule[] checkUndeployForChangedReferences(Set toRedeploy) { // PENDING: what are changed references for ejbmod, j2eeapp??? if (dtarget.getModule().getModuleType() == J2eeModule.WAR) { for (Iterator j=toRedeploy.iterator(); j.hasNext();) { TargetModule deployed = (TargetModule) j.next(); File lastContentDir = (deployed.getContentDirectory() == null) ? null : new File(deployed.getContentDirectory()); // content dir or context root changes since last deploy if ((currentContentDir != null && ! currentContentDir.equals(lastContentDir)) || (contextRoot != null && ! contextRoot.equals(deployed.getContextRoot()))) { distributeTargets.add(deployed.findTarget()); undeployTMIDs.add(deployed.delegate()); deployed.remove(); j.remove(); } } } return (TargetModule[]) toRedeploy.toArray(new TargetModule[toRedeploy.size()]); } // return list of target modules to redeploy private TargetModule[] checkUndeployForSameReferences(Target[] targs) { return checkUndeployForSharedReferences(Collections.EMPTY_SET, targs, null); } private TargetModule[] checkUndeployForSharedReferences(Set toRedeploy, Target[] targs) { return checkUndeployForSharedReferences(toRedeploy, targs, null); } private TargetModule[] checkUndeployForSharedReferences(Set toRedeploy, Target[] targs, Map queryInfo) { // PENDING: what are changed references for ejbmod, j2eeapp??? if (contextRoot == null) { return (TargetModule[]) toRedeploy.toArray(new TargetModule[toRedeploy.size()]); } boolean shared = false; TargetModuleIDResolver tmidResolver = instance.getTargetModuleIDResolver(); if (tmidResolver != null) { if (queryInfo == null) { queryInfo = new HashMap(); queryInfo.put(TargetModuleIDResolver.KEY_CONTEXT_ROOT, contextRoot); } List maybeRedistributeWhenSharedDetected = new ArrayList(); List maybeRemoveFromRedeployWhenSharedDetected = new ArrayList(); TargetModuleID[] haveSameReferences = TargetModule.EMPTY_TMID_ARRAY; if (targs.length > 1) haveSameReferences = tmidResolver.lookupTargetModuleID(queryInfo, targs); for (int i=0; i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.