Package org.glassfish.deployment.common
Class DeploymentContextImpl
- java.lang.Object
-
- org.glassfish.deployment.common.DeploymentContextImpl
-
- All Implemented Interfaces:
ApplicationContext,DeploymentContext,ExecutionContext,org.glassfish.hk2.api.PreDestroy,ExtendedDeploymentContext
public class DeploymentContextImpl extends Object implements ExtendedDeploymentContext, org.glassfish.hk2.api.PreDestroy
- Author:
- dochez
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.glassfish.internal.deployment.ExtendedDeploymentContext
ExtendedDeploymentContext.Phase
-
-
Field Summary
Fields Modifier and Type Field Description static LoggerdeplLogger-
Fields inherited from interface org.glassfish.internal.deployment.ExtendedDeploymentContext
IS_TEMP_CLASSLOADER, TRACKER
-
-
Constructor Summary
Constructors Constructor Description DeploymentContextImpl(ActionReport actionReport, Logger logger, ReadableArchive source, OpsParams params, ServerEnvironment env)DeploymentContextImpl(ActionReport actionReport, ReadableArchive source, OpsParams params, ServerEnvironment env)DeploymentContextImpl(Deployment.DeploymentContextBuilder builder, ServerEnvironment env)Creates a new instance of DeploymentContext
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddModuleMetaData(Object metaData)Stores a descriptor for the module in the context so other deployer's can have access to it.voidaddTransformer(ClassFileTransformer transformer)Add a new ClassFileTransformer to the contextvoidaddTransientAppMetaData(String metaDataKey, Object metaData)Stores application level metadata in the context so other deployer's can have access to it.voidclean()voidcreateApplicationClassLoader(ClassLoaderHierarchy clh, ArchiveHandler handler)Create the final class loader.It will be used to load and start application.voidcreateDeploymentClassLoader(ClassLoaderHierarchy clh, ArchiveHandler handler)Create the deployment class loader.It will be used for sniffer retrieval, metadata parsing and deployer prepare.ActionReportgetActionReport()Gets the action report for this contextFilegetAppAltDDDir()Returns the alternate deployment descriptor directory for the application (used for holding the external alternate deployment descriptors).FilegetAppInternalDir()Returns the internal directory for the application (used for holding the uploaded archive, for example).List<URI>getAppLibs()gets the app-libs specified for this archive
This list includes --libraries as well EXTENSION_LIST specified in the manifest entriesPropertiesgetAppProps()Returns the application level properties that will be persisted as a key value pair at then end of deployment.ArchiveHandlergetArchiveHandler()Returns the archive handler that's associated with this contextClassLoadergetClassLoader()Returns the class loader associated to this deployment request.ClassLoadergetClassLoader(boolean sharable)<U extends OpsParams>
UgetCommandParameters(Class<U> commandParametersType)Returns the DeployCommand parametersClassLoadergetFinalClassLoader()Returns the class loader associated to this deployment request.LoggergetLogger()Returns the logger services implementation should use to log useful information about their execution.Map<String,ArchiveHandler>getModuleArchiveHandlers()Gets the archive handlers for modulesMap<String,ExtendedDeploymentContext>getModuleDeploymentContexts()Gets the deployment context for modulesCollection<Object>getModuleMetadata()Returns all the metadata associated with this deployment<T> TgetModuleMetaData(Class<T> metadataType)Returns the meta data associated with a module type.PropertiesgetModuleProps()Returns the module level properties that will be persisted as a key value pair at then end of deployment.Map<String,Properties>getModulePropsMap()Gets the module properties for modulesStringgetModuleUri()Gets the module uri for this module contextReadableArchivegetOriginalSource()Gets the original source archive In case of archive deployment, this will return the archive before expanding.ExtendedDeploymentContextgetParentContext()Gets the parent context of the moduleExtendedDeploymentContext.PhasegetPhase()FilegetScratchDir(String subDirName)Returns a scratch directory that can be used to store things in.ReadableArchivegetSource()Application bits, at the raw level.FilegetSourceDir()Returns the directory where the original applications bits should be stored.StringgetTenant()Returns the tenant, if one is valid for this DeploymentContext.FilegetTenantDir()Returns the directory containing the expanded tenant customization archive, if this DC is for a tenant and if a customization archive was specified when the tenant was provisioned.List<ClassFileTransformer>getTransformers()Returns the list of transformers registered to this context.Map<String,Object>getTransientAppMetadata()Returns all the transient app metadata associated with this deployment<T> TgetTransientAppMetaData(String key, Class<T> metadataType)Returns the meta data for the given keyvoidpostDeployClean(boolean isFinalClean)Performs any clean-up of the deployment context after deployment has finished.voidpreDestroy()voidprepareScratchDirs()Prepare the scratch directories, creating the directories if they do not existvoidremoveTransientAppMetaData(String metaDataKey)Removes application level metadata of input key from the context.voidresetModuleMetaData()Reset the meta data associated with a module type.voidsetArchiveHandler(ArchiveHandler archiveHandler)Sets the archive handler that's associated with this contextvoidsetClassLoader(ClassLoader cloader)Sets the application classloadervoidsetModulePropsMap(Map<String,Properties> modulePropsMap)Sets the module properties for modulesvoidsetModuleUri(String moduleUri)Sets the module uri for this module contextvoidsetParentContext(ExtendedDeploymentContext parentContext)Sets the parent context for the modulevoidsetPhase(ExtendedDeploymentContext.Phase newPhase)Sets the phase of the deployment activity.voidsetSource(ReadableArchive source)Sets the source archivevoidsetTenant(String tenant, String appName)Sets the tenant to which this deployment context applies.
-
-
-
Field Detail
-
deplLogger
public static final Logger deplLogger
-
-
Constructor Detail
-
DeploymentContextImpl
public DeploymentContextImpl(Deployment.DeploymentContextBuilder builder, ServerEnvironment env)
Creates a new instance of DeploymentContext- Parameters:
builder-env-
-
DeploymentContextImpl
public DeploymentContextImpl(ActionReport actionReport, Logger logger, ReadableArchive source, OpsParams params, ServerEnvironment env)
-
DeploymentContextImpl
public DeploymentContextImpl(ActionReport actionReport, ReadableArchive source, OpsParams params, ServerEnvironment env)
-
-
Method Detail
-
getPhase
public ExtendedDeploymentContext.Phase getPhase()
- Specified by:
getPhasein interfaceExtendedDeploymentContext
-
setPhase
public void setPhase(ExtendedDeploymentContext.Phase newPhase)
Description copied from interface:ExtendedDeploymentContextSets the phase of the deployment activity.- Specified by:
setPhasein interfaceExtendedDeploymentContext
-
getSource
public ReadableArchive getSource()
Description copied from interface:DeploymentContextApplication bits, at the raw level. Deployer's should avoid using such low level access as it binds the deployer to a particular directory layout. Instead Deployers should use the class loader obtained via the getClassLoader() API- Specified by:
getSourcein interfaceDeploymentContext- Returns:
- Abstraction to the application's source archive.
-
setSource
public void setSource(ReadableArchive source)
Description copied from interface:ExtendedDeploymentContextSets the source archive- Specified by:
setSourcein interfaceExtendedDeploymentContext
-
getCommandParameters
public <U extends OpsParams> U getCommandParameters(Class<U> commandParametersType)
Description copied from interface:DeploymentContextReturns the DeployCommand parameters- Specified by:
getCommandParametersin interfaceDeploymentContext- Parameters:
commandParametersType- expected deployment operation parameters type.- Returns:
- the command parameters
-
getLogger
public Logger getLogger()
Description copied from interface:ExecutionContextReturns the logger services implementation should use to log useful information about their execution.- Specified by:
getLoggerin interfaceExecutionContext- Returns:
- the services logger
-
preDestroy
public void preDestroy()
- Specified by:
preDestroyin interfaceorg.glassfish.hk2.api.PreDestroy
-
getFinalClassLoader
public ClassLoader getFinalClassLoader()
Returns the class loader associated to this deployment request. ClassLoader instances are usually obtained by the getClassLoader API on the associated ArchiveHandler for the archive type being deployed. This can return null and the container should allocate a ClassLoader while loading the application.- Specified by:
getFinalClassLoaderin interfaceDeploymentContext- Returns:
- a class loader capable of loading classes and resources from the source
-
getClassLoader
public ClassLoader getClassLoader()
Returns the class loader associated to this deployment request. ClassLoader instances are usually obtained by the getClassLoader API on the associated ArchiveHandler for the archive type being deployed. This can return null and the container should allocate a ClassLoader while loading the application.- Specified by:
getClassLoaderin interfaceApplicationContext- Returns:
- a class loader capable of loading classes and resources from the source
-
setClassLoader
public void setClassLoader(ClassLoader cloader)
Description copied from interface:ExtendedDeploymentContextSets the application classloader- Specified by:
setClassLoaderin interfaceExtendedDeploymentContext
-
createDeploymentClassLoader
public void createDeploymentClassLoader(ClassLoaderHierarchy clh, ArchiveHandler handler) throws URISyntaxException, MalformedURLException
Description copied from interface:ExtendedDeploymentContextCreate the deployment class loader.It will be used for sniffer retrieval, metadata parsing and deployer prepare.- Specified by:
createDeploymentClassLoaderin interfaceExtendedDeploymentContext- Parameters:
clh- the hierarchy of class loader for the parenthandler- the archive handler for the source archive- Throws:
URISyntaxExceptionMalformedURLException
-
createApplicationClassLoader
public void createApplicationClassLoader(ClassLoaderHierarchy clh, ArchiveHandler handler) throws URISyntaxException, MalformedURLException
Description copied from interface:ExtendedDeploymentContextCreate the final class loader.It will be used to load and start application.- Specified by:
createApplicationClassLoaderin interfaceExtendedDeploymentContext- Parameters:
clh- the hierarchy of class loader for the parenthandler- the archive handler for the source archive- Throws:
URISyntaxExceptionMalformedURLException
-
getClassLoader
public ClassLoader getClassLoader(boolean sharable)
-
getScratchDir
public File getScratchDir(String subDirName)
Returns a scratch directory that can be used to store things in. The scratch directory will be persisted across server restart but not across redeployment of the same application- Specified by:
getScratchDirin interfaceDeploymentContext- Parameters:
subDirName- the sub directory name of the scratch dir- Returns:
- the scratch directory for this application based on passed in subDirName. Returns the root scratch dir if the passed in value is null.
-
getSourceDir
public File getSourceDir()
Returns the directory where the original applications bits should be stored. This is useful when users deploy an archive file that need to be unzipped somewhere for the container to work with.- Specified by:
getSourceDirin interfaceDeploymentContext- Returns:
- the source directory for this application
-
addModuleMetaData
public void addModuleMetaData(Object metaData)
Description copied from interface:DeploymentContextStores a descriptor for the module in the context so other deployer's can have access to it. Module meta-data is usual not persistent which mean that any modification to it will not be available at the next server restart and will need to be reset.- Specified by:
addModuleMetaDatain interfaceDeploymentContext- Parameters:
metaData- the meta data itself
-
resetModuleMetaData
public void resetModuleMetaData()
Description copied from interface:DeploymentContextReset the meta data associated with a module type.- Specified by:
resetModuleMetaDatain interfaceDeploymentContext
-
getModuleMetaData
public <T> T getModuleMetaData(Class<T> metadataType)
Description copied from interface:DeploymentContextReturns the meta data associated with a module type.- Specified by:
getModuleMetaDatain interfaceDeploymentContext- Parameters:
metadataType- type of the meta date.- Returns:
- instance of T or null
-
getModuleMetadata
public Collection<Object> getModuleMetadata()
Description copied from interface:DeploymentContextReturns all the metadata associated with this deployment- Specified by:
getModuleMetadatain interfaceDeploymentContext- Returns:
- collection of metadata added to the context
-
getTransientAppMetadata
public Map<String,Object> getTransientAppMetadata()
Description copied from interface:DeploymentContextReturns all the transient app metadata associated with this deployment- Specified by:
getTransientAppMetadatain interfaceDeploymentContext- Returns:
- collection of metadata added to the context
-
addTransientAppMetaData
public void addTransientAppMetaData(String metaDataKey, Object metaData)
Description copied from interface:DeploymentContextStores application level metadata in the context so other deployer's can have access to it. The transient meta-data is not persistent which mean that any modification to it will not be available at the next server restart and will need to be reset.- Specified by:
addTransientAppMetaDatain interfaceDeploymentContext- Parameters:
metaDataKey- key of the meta date.metaData- the meta data itself
-
removeTransientAppMetaData
public void removeTransientAppMetaData(String metaDataKey)
Description copied from interface:DeploymentContextRemoves application level metadata of input key from the context.- Specified by:
removeTransientAppMetaDatain interfaceDeploymentContext- Parameters:
metaDataKey- key of the meta date.
-
getTransientAppMetaData
public <T> T getTransientAppMetaData(String key, Class<T> metadataType)
Description copied from interface:DeploymentContextReturns the meta data for the given key- Specified by:
getTransientAppMetaDatain interfaceDeploymentContext- Parameters:
key- key of the meta date.metadataType- type of the meta date.- Returns:
- instance of T or null
-
getAppProps
public Properties getAppProps()
Returns the application level properties that will be persisted as a key value pair at then end of deployment. That allows individual Deployers implementation to store some information at the application level that should be available upon server restart. Application level properties are shared by all the modules.- Specified by:
getAppPropsin interfaceApplicationContext- Returns:
- the application's properties.
-
getModuleProps
public Properties getModuleProps()
Returns the module level properties that will be persisted as a key value pair at then end of deployment. That allows individual Deployers implementation to store some information at the module level that should be available upon server restart. Module level properties are only visible to the current module.- Specified by:
getModulePropsin interfaceApplicationContext- Returns:
- the module's properties.
-
addTransformer
public void addTransformer(ClassFileTransformer transformer)
Add a new ClassFileTransformer to the context- Specified by:
addTransformerin interfaceDeploymentContext- Parameters:
transformer- the new class file transformer to register to the new application class loader- Throws:
UnsupportedOperationException- if the class loader we use does not support the registration of a ClassFileTransformer. In such case, the deployer should either fail deployment or revert to a mode without the bytecode enhancement feature.
-
getTransformers
public List<ClassFileTransformer> getTransformers()
Returns the list of transformers registered to this context.- Specified by:
getTransformersin interfaceExtendedDeploymentContext- Returns:
- the transformers list
-
getAppLibs
public List<URI> getAppLibs() throws URISyntaxException
Description copied from interface:DeploymentContextgets the app-libs specified for this archive
This list includes --libraries as well EXTENSION_LIST specified in the manifest entries- Specified by:
getAppLibsin interfaceDeploymentContext- Returns:
- list of library URIs
- Throws:
URISyntaxException- when unable to get the library URIs
-
clean
public void clean()
- Specified by:
cleanin interfaceExtendedDeploymentContext
-
getArchiveHandler
public ArchiveHandler getArchiveHandler()
Description copied from interface:DeploymentContextReturns the archive handler that's associated with this context- Specified by:
getArchiveHandlerin interfaceDeploymentContext- Returns:
- archive handler
-
setArchiveHandler
public void setArchiveHandler(ArchiveHandler archiveHandler)
Description copied from interface:ExtendedDeploymentContextSets the archive handler that's associated with this context- Specified by:
setArchiveHandlerin interfaceExtendedDeploymentContext
-
getOriginalSource
public ReadableArchive getOriginalSource()
Description copied from interface:DeploymentContextGets the original source archive In case of archive deployment, this will return the archive before expanding. In case of directory deployment, this will return the same thing as getSource()- Specified by:
getOriginalSourcein interfaceDeploymentContext- Returns:
- the original source archive
-
getModulePropsMap
public Map<String,Properties> getModulePropsMap()
Gets the module properties for modules- Specified by:
getModulePropsMapin interfaceDeploymentContext- Returns:
- a map containing module properties
-
setModulePropsMap
public void setModulePropsMap(Map<String,Properties> modulePropsMap)
Sets the module properties for modules- Specified by:
setModulePropsMapin interfaceExtendedDeploymentContext- Parameters:
modulePropsMap-
-
setParentContext
public void setParentContext(ExtendedDeploymentContext parentContext)
Sets the parent context for the module- Specified by:
setParentContextin interfaceExtendedDeploymentContext- Parameters:
parentContext-
-
getParentContext
public ExtendedDeploymentContext getParentContext()
Gets the parent context of the module- Specified by:
getParentContextin interfaceExtendedDeploymentContext- Returns:
- the parent context
-
getModuleUri
public String getModuleUri()
Gets the module uri for this module context- Specified by:
getModuleUriin interfaceExtendedDeploymentContext- Returns:
- the module uri
-
setModuleUri
public void setModuleUri(String moduleUri)
Sets the module uri for this module context- Specified by:
setModuleUriin interfaceExtendedDeploymentContext- Parameters:
moduleUri-
-
getModuleArchiveHandlers
public Map<String,ArchiveHandler> getModuleArchiveHandlers()
Gets the archive handlers for modules- Specified by:
getModuleArchiveHandlersin interfaceDeploymentContext- Returns:
- a map containing module archive handlers
-
getModuleDeploymentContexts
public Map<String,ExtendedDeploymentContext> getModuleDeploymentContexts()
Gets the deployment context for modules- Specified by:
getModuleDeploymentContextsin interfaceExtendedDeploymentContext- Returns:
- a map containing module deployment contexts
-
getActionReport
public ActionReport getActionReport()
Gets the action report for this context- Specified by:
getActionReportin interfaceDeploymentContext- Returns:
- an action report
-
getAppInternalDir
public File getAppInternalDir()
Description copied from interface:ExtendedDeploymentContextReturns the internal directory for the application (used for holding the uploaded archive, for example).- Specified by:
getAppInternalDirin interfaceExtendedDeploymentContext- Returns:
- location of the internal directory for the application
-
getAppAltDDDir
public File getAppAltDDDir()
Description copied from interface:ExtendedDeploymentContextReturns the alternate deployment descriptor directory for the application (used for holding the external alternate deployment descriptors).- Specified by:
getAppAltDDDirin interfaceExtendedDeploymentContext- Returns:
- location of the alternate deployment descriptor directory for the application
-
setTenant
public void setTenant(String tenant, String appName)
Description copied from interface:ExtendedDeploymentContextSets the tenant to which this deployment context applies. Also initializes the tenant directory.- Specified by:
setTenantin interfaceExtendedDeploymentContext- Parameters:
tenant- the name of the tenantappName- the name of the application
-
getTenant
public String getTenant()
Description copied from interface:ExtendedDeploymentContextReturns the tenant, if one is valid for this DeploymentContext.- Specified by:
getTenantin interfaceExtendedDeploymentContext- Returns:
- tenant name if applicable, null if no tenant is set for this DC
-
getTenantDir
public File getTenantDir()
Description copied from interface:ExtendedDeploymentContextReturns the directory containing the expanded tenant customization archive, if this DC is for a tenant and if a customization archive was specified when the tenant was provisioned.- Specified by:
getTenantDirin interfaceExtendedDeploymentContext- Returns:
- directory containing the expanded customization archive; null if none
-
postDeployClean
public void postDeployClean(boolean isFinalClean)
Description copied from interface:ExtendedDeploymentContextPerforms any clean-up of the deployment context after deployment has finished.This method can be invoked either with "true", meaning that this is the final clean-up for the DC, or with "false," meaning that the DC implementation should be selective. (Some data is used, for instance, in the DeployCommand logic after ApplicationLifeCycle.deploy has completed.)
- Specified by:
postDeployCleanin interfaceExtendedDeploymentContext- Parameters:
isFinalClean- whether this clean is the final clean or a selective one.
-
prepareScratchDirs
public void prepareScratchDirs() throws IOExceptionPrepare the scratch directories, creating the directories if they do not exist- Specified by:
prepareScratchDirsin interfaceExtendedDeploymentContext- Throws:
IOException
-
-