use of digilib.util.DigilibJobCenter in project digilib by robcast.
the class DigilibServletConfiguration method configure.
/*
* (non-Javadoc)
*
* @see digilib.conf.DigilibConfiguration#configure()
*/
@SuppressWarnings("unchecked")
public void configure(ServletContext context) {
DigilibServletConfiguration config = this;
super.configure();
/*
* configure factories
*/
try {
// initialise MetaFactory
Class<FileMeta> fileMetaClass = (Class<FileMeta>) Class.forName(config.getAsString("filemeta-class"));
config.setValue("servlet.filemeta.class", fileMetaClass);
MetaFactory.setFileMetaClass(fileMetaClass);
Class<DirMeta> dirMetaClass = (Class<DirMeta>) Class.forName(config.getAsString("dirmeta-class"));
config.setValue("servlet.dirmeta.class", dirMetaClass);
MetaFactory.setDirMetaClass(dirMetaClass);
} catch (ClassNotFoundException e) {
logger.error("Error setting Metadata classes!");
}
if (config.getAsBoolean("use-authorization")) {
try {
// initialise AuthnOpsFactory
Class<AuthnOps> authnOpsClass = (Class<AuthnOps>) Class.forName(config.getAsString("authnops-class"));
config.setValue("servlet.authnops.class", authnOpsClass);
AuthnOpsFactory.setAuthnOpsClass(authnOpsClass);
} catch (ClassNotFoundException e) {
logger.error("Error setting AuthnOps class!");
}
try {
// initialise AuthzOpsFactory
Class<AuthzOps> authzOpsClass = (Class<AuthzOps>) Class.forName(config.getAsString("authzops-class"));
config.setValue("servlet.authzops.class", authzOpsClass);
AuthzOpsFactory.setAuthzOpsClass(authzOpsClass);
} catch (ClassNotFoundException e) {
logger.error("Error setting AuthzOps class!");
}
}
try {
// initialise DocuDirectoryFactory
Class<DocuDirectory> docuDirectoryClass = (Class<DocuDirectory>) Class.forName(config.getAsString("docudirectory-class"));
config.setValue("servlet.docudirectory.class", docuDirectoryClass);
DocuDirectoryFactory.setDocuDirectoryClass(docuDirectoryClass);
DocuDirectoryFactory.setDigilibConfig(this);
} catch (ClassNotFoundException e) {
logger.error("Error setting DocuDirectory class!");
}
/*
* configure singletons
*/
// set up the logger
File logConf = ServletOps.getConfigFile((File) config.getValue("log-config-file"), context);
if (logConf != null && logConf.canRead()) {
DOMConfigurator.configure(logConf.getAbsolutePath());
config.setValue("log-config-file", logConf);
}
// say hello in the log file
logger.info("***** Digital Image Library Configuration (version " + getVersion() + ") *****");
try {
// directory cache
DocuDirCache dirCache;
if (config.getAsBoolean("use-mapping")) {
// with mapping file
File mapConf = ServletOps.getConfigFile((File) config.getValue("mapping-file"), context);
dirCache = new AliasingDocuDirCache(FileClass.IMAGE, mapConf, config);
config.setValue("mapping-file", mapConf);
} else {
// without mapping
dirCache = new DocuDirCache(FileClass.IMAGE, this);
}
config.setValue(DIR_CACHE_KEY, dirCache);
// useAuthorization
if (config.getAsBoolean("use-authorization")) {
// set auth config file
File authConf = ServletOps.getConfigFile((File) config.getValue("auth-file"), context);
config.setValue("auth-file", authConf);
// initialise AuthnOps
AuthnOps authnOps = AuthnOpsFactory.getAuthnOpsInstance();
authnOps.init(this);
config.setValue(AUTHN_OP_KEY, authnOps);
// initialise AuthzOps (requires AuthnOps)
AuthzOps authzOps = AuthzOpsFactory.getAuthzOpsInstance();
authzOps.init(this);
config.setValue(AUTHZ_OP_KEY, authzOps);
}
// digilib worker threads
int nt = config.getAsInt("worker-threads");
int mt = config.getAsInt("max-waiting-threads");
DigilibJobCenter<DocuImage> imageExecutor = new DigilibJobCenter<DocuImage>(nt, mt, false, IMAGEEXECUTOR_KEY);
config.setValue(IMAGEEXECUTOR_KEY, imageExecutor);
/*
* set as the servlets main config
*/
setContextConfig(context);
} catch (Exception e) {
logger.error("Error configuring digilib servlet:", e);
}
}
use of digilib.util.DigilibJobCenter in project digilib by robcast.
the class DigilibServletConfiguration method contextDestroyed.
/**
* Clean up local resources
*/
public void contextDestroyed(ServletContextEvent cte) {
logger.info("DigilibServletConfiguration shutting down.");
// get current config from servlet context
ServletContext context = cte.getServletContext();
DigilibServletConfiguration config = getContextConfig(context);
@SuppressWarnings("unchecked") DigilibJobCenter<DocuImage> imageExecutor = (DigilibJobCenter<DocuImage>) config.getValue(IMAGEEXECUTOR_KEY);
if (imageExecutor != null) {
// shut down image thread pool
List<Runnable> rj = imageExecutor.shutdownNow();
int nrj = rj.size();
if (nrj > 0) {
logger.error("Still running threads when shutting down image job queue: " + nrj);
}
}
}
use of digilib.util.DigilibJobCenter in project digilib by robcast.
the class PDFServletConfiguration method contextDestroyed.
/* (non-Javadoc)
* @see digilib.conf.DigilibServletConfiguration#contextDestroyed(javax.servlet.ServletContextEvent)
*/
@Override
public void contextDestroyed(ServletContextEvent sce) {
super.contextDestroyed(sce);
ServletContext context = sce.getServletContext();
DigilibServletConfiguration config = PDFServletConfiguration.getCurrentConfig(context);
@SuppressWarnings("unchecked") DigilibJobCenter<DocuImage> pdfExecutor = (DigilibJobCenter<DocuImage>) config.getValue(PDF_EXECUTOR_KEY);
if (pdfExecutor != null) {
// shut down pdf thread pool
List<Runnable> rj = pdfExecutor.shutdownNow();
int nrj = rj.size();
if (nrj > 0) {
logger.error("Still running threads when shutting down PDF job queue: " + nrj);
}
}
@SuppressWarnings("unchecked") DigilibJobCenter<DocuImage> pdfImageExecutor = (DigilibJobCenter<DocuImage>) config.getValue(PDF_IMAGEEXECUTOR_KEY);
if (pdfImageExecutor != null) {
// shut down pdf image thread pool
List<Runnable> rj = pdfImageExecutor.shutdownNow();
int nrj = rj.size();
if (nrj > 0) {
logger.error("Still running threads when shutting down PDF-image job queue: " + nrj);
}
}
}
use of digilib.util.DigilibJobCenter in project digilib by robcast.
the class PDFServletConfiguration method configurePdfServlet.
/**
* @param config
* @param context
*/
protected void configurePdfServlet(ServletContext context) {
PDFServletConfiguration config = this;
// PDF worker threads
int pnt = config.getAsInt("pdf-worker-threads");
int pmt = config.getAsInt("pdf-max-waiting-threads");
DigilibJobCenter<OutputStream> pdfExecutor = new DigilibJobCenter<OutputStream>(pnt, pmt, false, "servlet.worker.pdfexecutor");
config.setValue(PDF_EXECUTOR_KEY, pdfExecutor);
// PDF image worker threads
int pint = config.getAsInt("pdf-image-worker-threads");
int pimt = config.getAsInt("pdf-image-max-waiting-threads");
DigilibJobCenter<DocuImage> pdfImageExecutor = new DigilibJobCenter<DocuImage>(pint, pimt, false, "servlet.worker.pdfimageexecutor");
config.setValue(PDF_IMAGEEXECUTOR_KEY, pdfImageExecutor);
/*
* set up temporary directories
*/
String temp_fn = config.getAsString("pdf-temp-dir");
File temp_directory = new File(temp_fn);
if (!temp_directory.exists()) {
// try to create
temp_directory.mkdirs();
} else {
// rid the temporary directory of possible incomplete document files
FileOps.emptyDirectory(temp_directory);
}
config.setValue(PDF_WORKDIR_KEY, temp_directory);
String cache_fn = config.getAsString("pdf-cache-dir");
File cache_directory = new File(cache_fn);
if (!cache_directory.exists()) {
// try to create
cache_directory.mkdirs();
}
config.setValue(PDF_CACHEDIR_KEY, cache_directory);
/*
* set as the PDF servlets main config
*/
context.setAttribute(PDF_SERVLET_CONFIG_KEY, this);
}
Aggregations