Skip to content

Commit

Permalink
added Apache Solr, changed logging (halfway through)
Browse files Browse the repository at this point in the history
  • Loading branch information
kolais committed Mar 30, 2009
1 parent adb7c5b commit 87d4327
Show file tree
Hide file tree
Showing 42 changed files with 581 additions and 207 deletions.
72 changes: 56 additions & 16 deletions pom.xml
Expand Up @@ -325,23 +325,25 @@
</plugins>
</build>
<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>3.0.4</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand All @@ -351,9 +353,26 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
Expand All @@ -374,6 +393,12 @@
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
Expand All @@ -390,17 +415,32 @@
<artifactId>saxon9-xpath</artifactId>
<version>9.1.0.6</version>
</dependency>
<!--
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>1.3.0</version>
</dependency>
-->
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon9-dom</artifactId>
<version>9.1.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.0</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xerces</groupId>
Expand Down
6 changes: 6 additions & 0 deletions resources/ae-solr-index.xml
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<solr persistent="true" sharedLib="lib">
<cores adminPath="/admin/cores">
<core name="experiments" instanceDir="experiments" default="true"/>
</cores>
</solr>
5 changes: 5 additions & 0 deletions resources/arrayexpress.properties
Expand Up @@ -38,3 +38,8 @@ ae.files.cache.filename = ${interface.application.pref.files.pre

# rescan files (in ms)
ae.files.rescan.interval = ${interface.application.pref.files.rescan.interval}

# solr index configuration
ae.solr.index.config.filename = ae-solr-index.xml
# directory (relative to java.io.tmpdir)
ae.solr.index.directory = ae-solr-index
8 changes: 8 additions & 0 deletions resources/logging.properties
@@ -0,0 +1,8 @@
# just turn off all jul logging
handlers = java.util.logging.ConsoleHandler

# Set the default logging level for the root logger
.level = ALL

# Set the default logging level for new ConsoleHandler instances
java.util.logging.ConsoleHandler.level = OFF
52 changes: 51 additions & 1 deletion src/main/java/uk/ac/ebi/arrayexpress/AEInterfaceApplication.java
@@ -1,17 +1,67 @@
package uk.ac.ebi.arrayexpress;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import uk.ac.ebi.arrayexpress.app.Application;
import uk.ac.ebi.arrayexpress.components.*;

public class AEInterfaceApplication extends Application
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.net.MalformedURLException;
import java.net.URL;

public class AEInterfaceApplication extends Application implements ServletContextListener
{
// logging machinery
private final Logger logger = LoggerFactory.getLogger(getClass());

private ServletContext servletContext;

public AEInterfaceApplication()
{
super("arrayexpress");

addComponent(new SaxonEngine());
addComponent(new SearchEngine());
addComponent(new Experiments());
addComponent(new Users());
addComponent(new DownloadableFilesRegistry());
addComponent(new JobsController());
}

public URL getResource(String path) throws MalformedURLException
{
return null != servletContext ? servletContext.getResource(path) : null;
}


public synchronized void contextInitialized( ServletContextEvent sce )
{
servletContext = sce.getServletContext();

logger.info("****************************************************************************************************************************");
logger.info("*");
logger.info("* {}", servletContext.getServletContextName());
logger.info("*");
logger.info("****************************************************************************************************************************");

// re-route all subsequent java.util.logging calls via slf4j
SLF4JBridgeHandler.install();

initialize();
}

public synchronized void contextDestroyed( ServletContextEvent sce )
{
terminate();

// restor java.util.logging calls to the original state
SLF4JBridgeHandler.uninstall();

servletContext = null;

logger.info("****************************************************************************************************************************\n\n");
}
}
60 changes: 18 additions & 42 deletions src/main/java/uk/ac/ebi/arrayexpress/app/Application.java
@@ -1,23 +1,19 @@
package uk.ac.ebi.arrayexpress.app;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;

public class Application implements ServletContextListener
public abstract class Application
{
// logging machinery
private static final Log log = LogFactory.getLog(Application.class);
private static final Logger logger = LoggerFactory.getLogger(Application.class);

private String name;
private ServletContext servletContext;
private Map<String, ApplicationComponent> components;

public Application( String appName )
Expand All @@ -35,15 +31,12 @@ public String getName()
return name;
}

public URL getResource(String path) throws MalformedURLException
{
return null != servletContext ? servletContext.getResource(path) : null;
}
public abstract URL getResource(String path) throws MalformedURLException;

public void addComponent( ApplicationComponent component )
{
if (components.containsKey(component.getName())) {
log.error("The component [" + component.getName() + "] has already been added to the application");
logger.error("The component [{}] has already been added to the application", component.getName());
} else {
components.put(component.getName(), component);
}
Expand All @@ -62,62 +55,45 @@ public ApplicationPreferences getPreferences()
return (ApplicationPreferences) getComponent("Preferences");
}

public synchronized void contextInitialized( ServletContextEvent sce )
{
servletContext = sce.getServletContext();
log.info("****************************************************************************************************************************");
log.info("*");
log.info("* " + servletContext.getServletContextName());
log.info("*");
log.info("****************************************************************************************************************************");

initialize();
}

public synchronized void contextDestroyed( ServletContextEvent sce )
public void initialize()
{
terminate();
appInstance = null;
servletContext = null;
log.info("****************************************************************************************************************************\n\n");
}

private void initialize()
{
log.debug("Initializing the application...");
logger.debug("Initializing the application...");
for ( ApplicationComponent c : components.values() ) {
log.info("Initializing component [" + c.getName() + "]");
logger.info("Initializing component [{}]", c.getName());
try {
c.initialize();
} catch ( Throwable x ) {
log.error("Caught an exception while initializing[" + c.getName() + "]:", x);
logger.error("Caught an exception while initializing [" + c.getName() + "]:", x);
}
}
}

private void terminate()
public void terminate()
{
log.debug("Terminating the application...");
logger.debug("Terminating the application...");
ApplicationComponent[] compArray = components.values().toArray(new ApplicationComponent[components.size()]);

for ( int i = compArray.length - 1; i >= 0; --i ) {
ApplicationComponent c = compArray[i];
log.info("Terminating component [" + c.getName() + "]");
logger.info("Terminating component [{}]", c.getName());
try {
c.terminate();
} catch ( Throwable x ) {
log.error("Caught an exception while terminating [" + c.getName() + "]:", x);
logger.error("Caught an exception while terminating [" + c.getName() + "]:", x);
}
}
// release references to application components
components.clear();
components = null;

// remove reference to self
appInstance = null;
}

public static Application getInstance()
{
if (null == appInstance) {
log.error("Attempted to obtain application instance before initialization or after destruction");
logger.error("Attempted to obtain application instance before initialization or after destruction");
}
return appInstance;
}
Expand Down
@@ -1,13 +1,7 @@
package uk.ac.ebi.arrayexpress.app;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

abstract public class ApplicationComponent
{
// logging machinery
private final Log log = LogFactory.getLog(getClass());

private String componentName;

public ApplicationComponent( String name )
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/uk/ac/ebi/arrayexpress/app/ApplicationJob.java
@@ -1,13 +1,13 @@
package uk.ac.ebi.arrayexpress.app;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

abstract public class ApplicationJob implements InterruptableJob, StatefulJob
{
// logging facitlity
private final Log log = LogFactory.getLog(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
// worker thread object
private Thread myThread;

Expand All @@ -17,7 +17,7 @@ public void execute( JobExecutionContext jec ) throws JobExecutionException
try {
execute();
} catch ( InterruptedException x ) {
log.debug("Job [" + jec.getJobDetail().getFullName() + "] was interrupted");
logger.debug("Job [{}] was interrupted", jec.getJobDetail().getFullName());
}
myThread = null;
}
Expand All @@ -26,7 +26,7 @@ public void execute( JobExecutionContext jec ) throws JobExecutionException

public void interrupt() throws UnableToInterruptJobException
{
log.debug("Attempting to interrupt job");
logger.debug("Attempting to interrupt job");
if (null != myThread)
myThread.interrupt();
}
Expand Down

0 comments on commit 87d4327

Please sign in to comment.