Author: rhauch
Date: 2008-08-20 12:09:15 -0400 (Wed, 20 Aug 2008)
New Revision: 455
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/BasicExecutionContext.java
Log:
DNA-201 - Provide a facility for clients to obtain context-level traces/logs of activity
http://jira.jboss.com/jira/browse/DNA-201
Added to ExecutionContext two "getLogger(...)" methods that mirror the
signatures of the static methods on Logger.
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-08-20
15:44:54 UTC (rev 454)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-08-20
16:09:15 UTC (rev 455)
@@ -211,7 +211,6 @@
private Selector sequencerSelector = DEFAULT_SEQUENCER_SELECTOR;
private NodeFilter nodeFilter = DEFAULT_NODE_FILTER;
private ExecutorService executorService;
- private Logger logger = Logger.getLogger(this.getClass());
private final Statistics statistics = new Statistics();
private final Administrator administrator = new Administrator();
@@ -317,24 +316,6 @@
}
/**
- * Get the logger for this system
- *
- * @return the logger
- */
- public Logger getLogger() {
- return this.logger;
- }
-
- /**
- * Set the logger for this system.
- *
- * @param logger the logger, or null if the standard logging should be used
- */
- public void setLogger( Logger logger ) {
- this.logger = logger != null ? logger : Logger.getLogger(this.getClass());
- }
-
- /**
* @return executionContext
*/
public JcrExecutionContext getExecutionContext() {
@@ -498,6 +479,9 @@
* @param changedNode the node to be processed.
*/
protected void processChangedNode( NodeChange changedNode ) {
+ final JcrExecutionContext context = this.getExecutionContext();
+ final Logger logger = context.getLogger(getClass());
+ assert logger != null;
try {
final String repositoryWorkspaceName =
changedNode.getRepositoryWorkspaceName();
Session session = null;
@@ -536,7 +520,7 @@
Node node = null;
if (!sequencers.isEmpty()) {
// Create a session that we'll use for all sequencing ...
- session =
this.getExecutionContext().getSessionFactory().createSession(repositoryWorkspaceName);
+ session =
context.getSessionFactory().createSession(repositoryWorkspaceName);
// Find the changed node ...
String relPath =
changedNode.getAbsolutePath().replaceAll("^/+", "");
@@ -547,14 +531,14 @@
}
if (sequencers.isEmpty()) {
this.statistics.recordNodeSkipped();
- if (this.logger.isDebugEnabled()) {
- this.logger.trace("Skipping '{0}': no sequencers
matched this condition", changedNode);
+ if (logger.isDebugEnabled()) {
+ logger.trace("Skipping '{0}': no sequencers matched
this condition", changedNode);
}
} else {
// Run each of those sequencers ...
ProgressMonitor progressMonitor = new
SimpleProgressMonitor(RepositoryI18n.sequencerTask.text(changedNode));
- if (this.logger.isTraceEnabled()) {
- progressMonitor = new LoggingProgressMonitor(progressMonitor,
this.logger, Logger.Level.TRACE);
+ if (logger.isTraceEnabled()) {
+ progressMonitor = new LoggingProgressMonitor(progressMonitor,
logger, Logger.Level.TRACE);
}
try {
progressMonitor.beginTask(sequencerCalls.size(),
RepositoryI18n.sequencerTask, changedNode);
@@ -569,7 +553,7 @@
assert outputPaths != null && outputPaths.size() !=
0;
// Create a new execution context for each sequencer
- final Context executionContext = new Context();
+ final Context executionContext = new Context(context);
final ProgressMonitor sequenceMonitor =
progressMonitor.createSubtask(1);
try {
sequenceMonitor.beginTask(100,
RepositoryI18n.sequencerSubtask, sequencerName);
@@ -580,12 +564,9 @@
executionContext,
sequenceMonitor.createSubtask(80)); //
80%
} catch (RepositoryException e) {
- this.logger.error(e,
-
RepositoryI18n.errorInRepositoryWhileSequencingNode,
- sequencerName,
- changedNode);
+ logger.error(e,
RepositoryI18n.errorInRepositoryWhileSequencingNode, sequencerName, changedNode);
} catch (SequencerException e) {
- this.logger.error(e,
RepositoryI18n.errorWhileSequencingNode, sequencerName, changedNode);
+ logger.error(e, RepositoryI18n.errorWhileSequencingNode,
sequencerName, changedNode);
} finally {
try {
// Save the changes made by each sequencer ...
@@ -611,9 +592,9 @@
if (session != null) session.logout();
}
} catch (RepositoryException e) {
- this.logger.error(e,
RepositoryI18n.errorInRepositoryWhileFindingSequencersToRunAgainstNode, changedNode);
+ logger.error(e,
RepositoryI18n.errorInRepositoryWhileFindingSequencersToRunAgainstNode, changedNode);
} catch (Throwable e) {
- this.logger.error(e, RepositoryI18n.errorFindingSequencersToRunAgainstNode,
changedNode);
+ logger.error(e, RepositoryI18n.errorFindingSequencersToRunAgainstNode,
changedNode);
}
}
@@ -624,8 +605,8 @@
private final Set<Session> sessions = new HashSet<Session>();
protected final AtomicBoolean closed = new AtomicBoolean(false);
- protected Context() {
- this.delegate = SequencingService.this.getExecutionContext();
+ protected Context( JcrExecutionContext context ) {
+ this.delegate = context;
final SessionFactory delegateSessionFactory =
this.delegate.getSessionFactory();
this.factory = new SessionFactory() {
@@ -708,6 +689,24 @@
return this.delegate.getValueFactories();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.Class)
+ */
+ public Logger getLogger( Class<?> clazz ) {
+ return this.delegate.getLogger(clazz);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.String)
+ */
+ public Logger getLogger( String name ) {
+ return this.delegate.getLogger(name);
+ }
+
protected synchronized void recordSession( Session session ) {
if (session != null) sessions.add(session);
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java 2008-08-20
15:44:54 UTC (rev 454)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java 2008-08-20
16:09:15 UTC (rev 455)
@@ -24,6 +24,7 @@
import java.security.AccessControlContext;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.PropertyFactory;
@@ -72,4 +73,26 @@
* @return the subject; never null
*/
Subject getSubject();
+
+ /**
+ * Return a logger associated with this context. This logger records only those
activities within the context and provide a
+ * way to capture the context-specific activities. All log messages are also sent to
the system logger, so classes that log
+ * via this mechanism should <i>not</i> also {@link
Logger#getLogger(Class) obtain a system logger}.
+ *
+ * @param clazz the class that is doing the logging
+ * @return the logger, named after <code>clazz</code>; never null
+ * @see #getLogger(String)
+ */
+ Logger getLogger( Class<?> clazz );
+
+ /**
+ * Return a logger associated with this context. This logger records only those
activities within the context and provide a
+ * way to capture the context-specific activities. All log messages are also sent to
the system logger, so classes that log
+ * via this mechanism should <i>not</i> also {@link
Logger#getLogger(Class) obtain a system logger}.
+ *
+ * @param name the name for the logger
+ * @return the logger, named after <code>clazz</code>; never null
+ * @see #getLogger(Class)
+ */
+ Logger getLogger( String name );
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java 2008-08-20
15:44:54 UTC (rev 454)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java 2008-08-20
16:09:15 UTC (rev 455)
@@ -25,6 +25,7 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.PathFactory;
@@ -204,6 +205,24 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.Class)
+ */
+ public Logger getLogger( Class<?> clazz ) {
+ return delegate.getLogger(clazz);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.String)
+ */
+ public Logger getLogger( String name ) {
+ return delegate.getLogger(name);
+ }
+
+ /**
* @return delegate
*/
protected ExecutionContext getDelegate() {
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/BasicExecutionContext.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/BasicExecutionContext.java 2008-08-20
15:44:54 UTC (rev 454)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/BasicExecutionContext.java 2008-08-20
16:09:15 UTC (rev 455)
@@ -26,6 +26,7 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.PropertyFactory;
@@ -158,4 +159,22 @@
public ValueFactories getValueFactories() {
return valueFactories;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.Class)
+ */
+ public Logger getLogger( Class<?> clazz ) {
+ return Logger.getLogger(clazz);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.String)
+ */
+ public Logger getLogger( String name ) {
+ return Logger.getLogger(name);
+ }
}