public abstract class AbstractAggregatorImpl extends javax.servlet.http.HttpServlet implements IAggregator
Modifier and Type | Class and Description |
---|---|
class |
AbstractAggregatorImpl.ExtensionRegistrar
Implements the
IExtensionInitializer.IExtensionRegistrar interface |
IAggregator.SubstitutionTransformer
Modifier and Type | Field and Description |
---|---|
protected ICacheManager |
cacheMgr |
protected IConfig |
config |
protected static String |
DEFAULT_HTTPTRANSPORT
Default value for httptransport init-param
|
protected static String |
DEFAULT_MODULEBUILDERS
Default value for modulebuilders init-param
|
protected static String |
DEFAULT_RESOURCEFACTORIES
Default value for resourcefactories init-param
|
protected IDependencies |
deps |
protected FileNameMap |
fileNameMap |
protected MimetypesFileTypeMap |
fileTypeMap |
protected InitParams |
initParams |
protected String |
name |
protected Pattern |
pattern |
protected IPlatformServices |
platformServices |
protected List<IServiceRegistration> |
registrations |
protected Map<String,URI> |
resourcePaths |
protected List<IServiceReference> |
serviceReferences |
protected URI |
webContentUri |
AGGREGATOR_REQATTRNAME, CONCURRENTMAP_REQATTRNAME
Constructor and Description |
---|
AbstractAggregatorImpl() |
Modifier and Type | Method and Description |
---|---|
protected void |
addAlias(String alias,
URI res,
String initParamName,
Map<String,URI> map) |
javax.servlet.http.HttpServlet |
asServlet()
Returns this instance of the aggregator as a HttpServlet.
|
Future<?> |
buildAsync(Callable<?> builder,
javax.servlet.http.HttpServletRequest req)
Runs the specified builder on an asynchronous thread and returns a
Future to the
result. |
protected void |
callExtensionInitializers(Iterable<IAggregatorExtension> extensions,
AbstractAggregatorImpl.ExtensionRegistrar reg)
For each extension specified, call the extension's
IExtensionInitializer.initialize(com.ibm.jaggr.core.IAggregator, com.ibm.jaggr.core.IAggregatorExtension, com.ibm.jaggr.core.IExtensionInitializer.IExtensionRegistrar) method. |
void |
destroy() |
protected void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
protected void |
exceptionResponse(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
Throwable t,
int status)
Sets response status and headers for an error response based on the information in the
specified exception.
|
protected String |
getAggregatorName(Map<String,String> configMap)
Returns the name for this aggregator
|
ICacheManager |
getCacheManager()
Returns the cache manager object for this aggregator.
|
IConfig |
getConfig()
Returns the config object for this aggregator.
|
protected String |
getContentType(String filename)
Returns the content type string for the specified filename based on the filename's extension.
|
javax.servlet.http.HttpServletRequest |
getCurrentRequest()
Returns the request object currently being processed.
|
IDependencies |
getDependencies()
Returns the dependencies object for this aggregator.
|
abstract IExecutors |
getExecutors() |
Iterable<IAggregatorExtension> |
getExtensions(String extensionPointId)
Returns an
Iterable for the collection of aggregator extensions identified by
extensionPointId . |
InitParams |
getInitParams()
Returns the servlet init-params for this aggregator.
|
protected ILayer |
getLayer(javax.servlet.http.HttpServletRequest request)
Returns the
Layer object for the specified request. |
IModuleBuilder |
getModuleBuilder(String mid,
IResource res)
Returns an
IModuleBuilder for the specified arguments. |
String |
getName()
Returns the name of the servlet implementing this interface.
|
abstract IOptions |
getOptions()
Returns the options object for this aggregator.
|
protected Map<String,URI> |
getPathsAndAliases(InitParams initParams)
Returns a mapping of resource aliases to IResources defined in the init-params.
|
IPlatformServices |
getPlatformServices()
Get the
IPlatformServices implementation for this aggregator. |
String |
getPropValue(String propName)
Returns the value for the property name used by the aggregator.
|
IResourceFactory |
getResourceFactory(org.apache.commons.lang3.mutable.Mutable<URI> uriRef)
Returns a new
IResourceFactory for the specified URI. |
IHttpTransport |
getTransport()
Returns the HTTP transport in use by this object
|
void |
init(javax.servlet.ServletConfig servletConfig) |
void |
initialize(IConfig config)
This method does some initialization for the aggregator servlet.
|
protected File |
initWorkingDirectory(File defaultLocation,
Map<String,String> configMap,
String versionString) |
protected File |
initWorkingDirectory(File defaultLocation,
Map<String,String> configMap,
String versionString,
Collection<String> retainedVersions)
Returns the working directory for this aggregator.
|
protected boolean |
loadConfig(long seq)
Loads the
IConfig for this aggregator |
protected ICacheManager |
newCacheManager(long stamp)
Instantiates a new cache manager
|
protected IConfig |
newConfig()
Instantiates a new config object
|
protected IDependencies |
newDependencies(long stamp)
Instantiates a new dependencies object
|
protected ForcedErrorResponse |
newForcedErrorResponse(String info)
Instantiates a new ForcedErrorResponse object
|
IGzipCache |
newGzipCache()
Factory method for IGZipCache
|
ILayerCache |
newLayerCache()
Factory method for ILayerCache
|
IModule |
newModule(String mid,
URI uri)
Factory method for IModule instances.
|
IModuleCache |
newModuleCache()
Factory method for IModuleCache
|
IResource |
newResource(URI uri)
Returns a new
IResource for the specified URI. |
protected void |
notifyConfigListeners(long seq)
Call the registered config change listeners
|
protected void |
notifyRequestListeners(com.ibm.jaggr.core.impl.AbstractAggregatorImpl.RequestNotifierAction action,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Calls the registered request notifier listeners.
|
protected void |
processAggregatorRequest(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
protected void |
processResourceRequest(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
URI uri,
String path) |
protected void |
registerExtension(IAggregatorExtension ext,
IAggregatorExtension before)
Adds the specified extension to the list of registered extensions.
|
protected void |
registerLayerListener()
Registers the layer listener
|
boolean |
reloadConfig()
Reloads the config data using the latest values in the config file
specified in the
config init-param of the servlet. |
IResource |
runConverters(IResource resource)
Run the registered resource converters against the specified resource.
|
String |
setForceError(String forceError)
Command provider function for setting forced errors in development mode.
|
protected void |
setResourceResponseCacheHeaders(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
IResource resolved,
boolean isNoCache) |
protected void |
shutdown()
Called when the aggregator is shutting down.
|
String |
substituteProps(String str)
Performs substitution of variable names of the form ${name} with the values
defined in java system properties, or with the value returned by a registered
variable resolver that implements the interface
IVariableResolver . |
String |
substituteProps(String str,
IAggregator.SubstitutionTransformer transformer)
Like
IAggregator.substituteProps(String) , but allows the caller to specify
a transformer class to process the substitution values. |
protected boolean |
writeResponse(InputStream in,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Writes the response to the response object.
|
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getWorkingDirectory
protected static final String DEFAULT_RESOURCEFACTORIES
protected static final String DEFAULT_MODULEBUILDERS
protected static final String DEFAULT_HTTPTRANSPORT
protected ICacheManager cacheMgr
protected IConfig config
protected String name
protected IDependencies deps
protected List<IServiceRegistration> registrations
protected List<IServiceReference> serviceReferences
protected InitParams initParams
protected MimetypesFileTypeMap fileTypeMap
protected FileNameMap fileNameMap
protected IPlatformServices platformServices
protected URI webContentUri
protected final Pattern pattern
public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
protected void shutdown()
GenericServlet.destroy()
is called relative to when (or even if) the bundle is stopped. So this method
may be called from the destroy method or the bundle listener or both.protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
protected void setResourceResponseCacheHeaders(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, IResource resolved, boolean isNoCache)
protected void processResourceRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, URI uri, String path)
protected void processAggregatorRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
public boolean reloadConfig() throws IOException
IAggregator
config
init-param of the servlet.
Any services registered using the IConfigListener
interface are
notified.
reloadConfig
in interface IAggregator
IOException
public IDependencies getDependencies()
IAggregator
getDependencies
in interface IAggregator
public String getName()
IAggregator
getName
in interface IAggregator
public IConfig getConfig()
IAggregator
config
servlet init-param. The URI
specified by this init-param points to a server side AMD config file that
specifies the aggregator config propertes using JSON format in the same
way that the client side loader config JSON specifies the AMD
configuration for the loader on the client. \getConfig
in interface IAggregator
public ICacheManager getCacheManager()
IAggregator
getCacheManager
in interface IAggregator
public InitParams getInitParams()
IAggregator
getInitParams
in interface IAggregator
public javax.servlet.http.HttpServlet asServlet()
IAggregator
asServlet
in interface IAggregator
public IHttpTransport getTransport()
IAggregator
getTransport
in interface IAggregator
public IResourceFactory getResourceFactory(org.apache.commons.lang3.mutable.Mutable<URI> uriRef)
IAggregator
IResourceFactory
for the specified URI. The aggregator
will create the new resource using one of the registered resource
factories.
The aggregator will select the factory from among the registered IResourceFactory
extensions by testing the provided uri
against the scheme attribute of each of the
registered resource factories as follows:
Iterate through the registered resource factory extensions looking for extensions that
specify a scheme
attribute matching the scheme of uri
or a
scheme
attribute of *
. For each matching extension, call the
IResourceFactory.handles(URI)
method and if the method returns true, then call the
IResourceFactory.newResource(URI)
method to create the new resource.
The iteration order of the resource factories is determined by the order that
resourcefactories
init-params are declared within the servlet
element defining the aggregator servlet, the order that the factory
elements are
declared in the resource factory extensions within the plugin.xml{s}, and on the insertion
positions of extensions registered programatically using
IExtensionInitializer.IExtensionRegistrar.registerExtension(java.lang.Object, java.util.Properties, com.ibm.jaggr.core.InitParams, java.lang.String, java.lang.String, com.ibm.jaggr.core.IAggregatorExtension)
.
The registered resource factory extensions may be obtained by calling
IAggregator.getExtensions(String)
;
If a satisfactory resource factory cannot be found, then null is returned.
getResourceFactory
in interface IAggregator
uriRef
- (Input/Output)
A mutable reference to the input uri which may be modified to reference a
different uri for the same resource if the uri needs to be transformed in order to
match to a resource factory (e.g. a relative uri transformed into an absolute
uri).public IResource newResource(URI uri)
IAggregator
IResource
for the specified URI. The aggregator
will create the new resource using the resource factory obtained by
calling IAggregator.getResourceFactory(Mutable)
.
This method may return an instance of NotFoundResource
if a resource factory
for the URI cannot be found.
This method calls IAggregator.runConverters(IResource)
against the resource
obtained from the resource factory before returning the result.
newResource
in interface IAggregator
uri
- The URI for the resourcepublic IResource runConverters(IResource resource)
IAggregator
Note that this method is called automatically by IAggregator.newResource(URI)
, so it is
generally not necessary to call this method directly.
runConverters
in interface IAggregator
resource
- the resource to run converters againstres
if no conversion is applied.public IModuleBuilder getModuleBuilder(String mid, IResource res)
IAggregator
IModuleBuilder
for the specified arguments. The aggregator will select the
builder from among the registered module builder extensions by testing the provided
mid
and res
arguments against the attributes for each of the
registered extensions as follows:
Iterate through the registered module builder extensions looking for extensions that specify
an extension
attribute that matches the file extension of the resource specified
by res
or an extension
attribute of *
. For each
matching module builder extension, if the extension does not specify a plugin
attribute or the value of the plugin
attribute matches the plugin specified by
mid
(if any), then call the module builder's
IModuleBuilder.handles(String, IResource)
method. If the method returns true, then
the module builder is returned to the caller.
The iteration order of the module builders is determined by the order that
modulebuilders
init-params are declared within the servlet
element
defining the aggregator servlet, the order that the builder
elements are
declared in the module builder extensions within the plugin.xml{s}, and on the insertion
positions of extensions registered programatically using
IExtensionInitializer.IExtensionRegistrar.registerExtension(java.lang.Object, java.util.Properties, com.ibm.jaggr.core.InitParams, java.lang.String, java.lang.String, com.ibm.jaggr.core.IAggregatorExtension)
.
The registered module builder extensions may be obtained by calling
IAggregator.getExtensions(String)
.
getModuleBuilder
in interface IAggregator
mid
- The module id for the module to be builtres
- The resource for the modulepublic Iterable<IAggregatorExtension> getExtensions(String extensionPointId)
IAggregator
Iterable
for the collection of aggregator extensions identified by
extensionPointId
. This includes extensions obtained from the eclipse extension
registry, as well as extensions registered though the IExtensionInitializer.IExtensionRegistrar
interface.getExtensions
in interface IAggregator
extensionPointId
- The extension point id for the extensions to be returned, or null for all
extensions.public IModule newModule(String mid, URI uri)
IAggregator
newModule
in interface IAggregator
mid
- the module iduri
- the URI to the module sourcepublic ILayerCache newLayerCache()
IAggregator
newLayerCache
in interface IAggregator
public IModuleCache newModuleCache()
IAggregator
newModuleCache
in interface IAggregator
public IGzipCache newGzipCache()
IAggregator
newGzipCache
in interface IAggregator
protected boolean writeResponse(InputStream in, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
in
- the input stream.request
- the http request objectresponse
- the http response objectIOException
protected void exceptionResponse(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, Throwable t, int status)
req
- the request objectresp
- The response objectt
- The exception objectstatus
- The response statusprotected ILayer getLayer(javax.servlet.http.HttpServletRequest request) throws Exception
Layer
object for the specified request.request
- The request objectException
public String substituteProps(String str)
IAggregator
IVariableResolver
.
Variable resolvers are registered in the OSGi service registry. If more than
one resolver is registered, the first one that returns a value for the variable
will be used. If no value is found for a variable, then the variable
identifier is unmodified in the returned string.substituteProps
in interface IAggregator
str
- The string for which variables should be substitutedpublic String substituteProps(String str, IAggregator.SubstitutionTransformer transformer)
IAggregator
IAggregator.substituteProps(String)
, but allows the caller to specify
a transformer class to process the substitution values.substituteProps
in interface IAggregator
str
- The input stringtransformer
- An instance of IAggregator.SubstitutionTransformer
public String getPropValue(String propName)
propName
- protected boolean loadConfig(long seq) throws IOException
IConfig
for this aggregatorseq
- The config change sequence numberIOException
protected String getContentType(String filename)
filename
- the file name for which the content type is desiredprotected void notifyRequestListeners(com.ibm.jaggr.core.impl.AbstractAggregatorImpl.RequestNotifierAction action, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOException
action
- The request action (start or end)req
- The request object.resp
- The response object.IOException
protected void notifyConfigListeners(long seq) throws IOException
seq
- The change listener sequence numberIOException
protected void registerExtension(IAggregatorExtension ext, IAggregatorExtension before)
ext
- The extension to addbefore
- Reference to an existing extension that the
new extension should be placed before in the list. If null,
then the new extension is added to the end of the listprotected void callExtensionInitializers(Iterable<IAggregatorExtension> extensions, AbstractAggregatorImpl.ExtensionRegistrar reg)
IExtensionInitializer.initialize(com.ibm.jaggr.core.IAggregator, com.ibm.jaggr.core.IAggregatorExtension, com.ibm.jaggr.core.IExtensionInitializer.IExtensionRegistrar)
method. Note that this
can cause additional extensions to be registered though the
AbstractAggregatorImpl.ExtensionRegistrar
.extensions
- The list of extensions to initializereg
- The extension registrar.protected File initWorkingDirectory(File defaultLocation, Map<String,String> configMap, String versionString) throws FileNotFoundException
FileNotFoundException
protected File initWorkingDirectory(File defaultLocation, Map<String,String> configMap, String versionString, Collection<String> retainedVersions) throws FileNotFoundException
This method is called during aggregator intialization. Subclasses may override this method to
initialize the aggregator using a different working directory. Use the public
IAggregator.getWorkingDirectory()
method to get the working directory from an initialized
aggregator.
The working directory returned by this method will be located at
<defaultLocation>/<versionString>/<aggregator name>
If the directory <defaultLocation>/<versionString>
does not already
exist when this method is called, then any files in defaultLocation
and any
subdirectories in defaultLocation
that are not listed in
retaindedVersions
WILL BE DELETED.
defaultLocation
- The default, unversioned, directory location. The aggregator assumes that it owns
this directory and all the files in it.configMap
- the map of config name/value pairsversionString
- the version string to qualify the directory locationretainedVersions
- collection of versions to retain when deleting stale version subdirectories.File
object for the working directoryFileNotFoundException
protected String getAggregatorName(Map<String,String> configMap)
This method is called during aggregator intialization. Subclasses may
override this method to initialize the aggregator using a different
name. Use the public IAggregator.getName()
method
to get the name of an initialized aggregator.
configMap
- A Map having key-value pairs denoting configuration settings for the aggregator servletprotected IDependencies newDependencies(long stamp)
stamp
- the time stampprotected IConfig newConfig() throws IOException
IOException
protected ForcedErrorResponse newForcedErrorResponse(String info) throws URISyntaxException
info
- The configuration stringURISyntaxException
protected ICacheManager newCacheManager(long stamp) throws IOException
stamp
- the time stampIOException
public abstract IOptions getOptions()
IAggregator
getOptions
in interface IAggregator
public abstract IExecutors getExecutors()
getExecutors
in interface IAggregator
public IPlatformServices getPlatformServices()
IAggregator
IPlatformServices
implementation for this aggregator.getPlatformServices
in interface IAggregator
IPlatformServices
public void initialize(IConfig config) throws Exception
config
- The aggregator configException
protected Map<String,URI> getPathsAndAliases(InitParams initParams)
initParams
- The aggregator init-paramsprotected void registerLayerListener()
public String setForceError(String forceError)
IAggregator
setForceError
in interface IAggregator
forceError
- the error parameters. See ForcedErrorResponse.ForcedErrorResponse(String)
for description.public Future<?> buildAsync(Callable<?> builder, javax.servlet.http.HttpServletRequest req)
IAggregator
Future
to the
result. Saves request
to a thread local that can be queried by the async thread
using IAggregator.getCurrentRequest()
.buildAsync
in interface IAggregator
builder
- the builder to runreq
- the request objectpublic javax.servlet.http.HttpServletRequest getCurrentRequest()
IAggregator
IAggregator.buildAsync(Callable, HttpServletRequest)
.
For all other threads, the return value will be null.getCurrentRequest
in interface IAggregator
Copyright © 2011-2015 IBM. All Rights Reserved.