Skip to content

Commit

Permalink
MONDRIAN: [MONDRIAN-994] Allows log4j's MDC context to be passed to t…
Browse files Browse the repository at this point in the history
…he Execution thread.

[git-p4: depot-paths = "//open/mondrian/": change = 14955]
  • Loading branch information
lucboudreau committed Feb 16, 2012
1 parent 5fd6110 commit 09a3e3e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/mondrian/rolap/RolapConnection.java
Expand Up @@ -619,6 +619,7 @@ public Result execute(Query query) {
* the property file
*/
public Result execute(final Execution execution) {
execution.copyMDC();
return
server.getResultShepherd()
.shepherdExecution(
Expand All @@ -631,6 +632,7 @@ public Result call() throws Exception {
}

private Result executeInternal(final Execution execution) {
execution.setContextMap();
final Statement statement = execution.getMondrianStatement();
// Cleanup any previous executions still running
synchronized (statement) {
Expand Down
27 changes: 27 additions & 0 deletions src/main/mondrian/server/Execution.java
Expand Up @@ -19,6 +19,8 @@
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.log4j.MDC;

/**
* Execution context.
*
Expand Down Expand Up @@ -81,6 +83,8 @@ public class Execution {

public static final Execution NONE = new Execution(null, 0);

private Map<String, Object> mdc;

public Execution(Statement statement, long timeoutIntervalMillis) {
this.id = SEQ.getAndIncrement();
this.statement = (StatementImpl) statement;
Expand Down Expand Up @@ -320,6 +324,29 @@ private void fireExecutionStartEvent() {
id,
getMdx()));
}


/**
* Copy the current MDC so it can be used later
*/
public void copyMDC() {
this.mdc = new HashMap<String, Object>(MDC.getContext());
}

/**
* Set the copied mdc into the current MDC. This should be called
* any time there will be logging in a thread handled by the
* RolapResultShepherd where original MDC needs to be retrieved
*/
public void setContextMap() {
if(mdc == null) {
return;
}
Map<String, Object> old = MDC.getContext();
old.clear();
old.putAll(mdc);
}

/**
* Enumeration of the states of an Execution instance.
*/
Expand Down

0 comments on commit 09a3e3e

Please sign in to comment.