Skip to content

Commit

Permalink
MONDRIAN: Complete moving MessageRecorder to its own package.
Browse files Browse the repository at this point in the history
Update home page.

[git-p4: depot-paths = "//open/mondrian/": change = 3578]
  • Loading branch information
julianhyde committed May 14, 2005
1 parent 20efd3e commit 70b8874
Show file tree
Hide file tree
Showing 18 changed files with 1,351 additions and 1,304 deletions.
2 changes: 1 addition & 1 deletion doc/index.html
Expand Up @@ -17,7 +17,7 @@
<meta name="description" content="Mondrian is an OLAP server written in Java. It enables you to interactively
analyze very large datasets stored in SQL databases without writing SQL.">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Mondrian components</title>
<title>Mondrian OLAP Server</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css" />
</head>

Expand Down
1 change: 1 addition & 0 deletions doc/noframes.html
Expand Up @@ -51,6 +51,7 @@
&nbsp;&nbsp;&nbsp;<a href="mdx.html">MDX</a><br>
&nbsp;&nbsp;&nbsp;<a href="architecture.html">Architecture</a><br>
&nbsp;&nbsp;&nbsp;<a href="schema.html">Writing a schema</a><br>
&nbsp;&nbsp;&nbsp;<a href="cmdrunner.html">Command runner</a><br>
&nbsp;&nbsp;&nbsp;<a href="faq.html">FAQ</a><br>
&nbsp;&nbsp;&nbsp;<a href="roadmap.html">Roadmap</a><br>
Design<br>
Expand Down
293 changes: 58 additions & 235 deletions src/main/mondrian/recorder/AbstractRecorder.java
Expand Up @@ -3,240 +3,58 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2001-2005 Kana Software, Inc. and others.
// Copyright (C) 2005-2005 Julian Hyde and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, 12 August, 2001
*/

package mondrian.rolap;
package mondrian.recorder;

import mondrian.olap.Util;
import java.io.PrintStream;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;

/**
* This class provides both an abstract implemention of the MessageRecorder
* interface as well as three concrete implementions.
*
import java.util.*;

/**
* Abstract implemention of the {@link MessageRecorder} interface.
*
* @author <a>Richard M. Emberson</a>
* @version
* @version $Id$
*/
public abstract class Recorder implements MessageRecorder {
/**
* Simply writes messages to PrintStreams.
*/
public static class Std extends Recorder {
private final PrintStream err;
private final PrintStream out;
public Std() {
this(System.out, System.err);
}
public Std(final PrintStream out, final PrintStream err) {
this.out = out;
this.err = err;
}
protected void recordMessage(final String msg,
final Object info,
final int msgType) {
PrintStream ps = null;
String prefix = null;
switch (msgType) {
case INFO_MSG_TYPE :
prefix = "INFO: ";
ps = out;
break;
case WARN_MSG_TYPE :
prefix = "WARN: ";
ps = out;
break;
case ERROR_MSG_TYPE :
prefix = "ERROR: ";
ps = err;
break;
default :
prefix = "UNKNOWN: ";
}
String context = getContext();
public abstract class AbstractRecorder implements MessageRecorder {

ps.print(prefix);
ps.print(context);
ps.print(": ");
ps.println(msg);
}
}

/**
/**
* Helper method to format a message and write to logger.
*/
public static void logMessage(final String context,
final String msg,
final int msgType,
final org.apache.log4j.Logger logger) {
StringBuffer buf = new StringBuffer(64);
buf.append(context);
buf.append(": ");
buf.append(msg);

switch (msgType) {
case INFO_MSG_TYPE :
logger.info(buf.toString());
break;
case WARN_MSG_TYPE :
logger.warn(buf.toString());
break;
case ERROR_MSG_TYPE :
logger.error(buf.toString());
break;
default :
logger.warn(
public static void logMessage(
final String context,
final String msg,
final int msgType,
final org.apache.log4j.Logger logger) {
StringBuffer buf = new StringBuffer(64);
buf.append(context);
buf.append(": ");
buf.append(msg);

switch (msgType) {
case INFO_MSG_TYPE :
logger.info(buf.toString());
break;
case WARN_MSG_TYPE :
logger.warn(buf.toString());
break;
case ERROR_MSG_TYPE :
logger.error(buf.toString());
break;
default :
logger.warn(
"Unknown message type enum \"" +
msgType +
"\" for message: " +
buf.toString()
);
}
}

/**
* MessageRecorder that writes to a logger.
*/
public static class Logger extends Recorder {
private final org.apache.log4j.Logger logger;

public Logger(final org.apache.log4j.Logger logger) {
this.logger = logger;
}
protected void recordMessage(final String msg,
final Object info,
final int msgType) {
String context = getContext();

logMessage(context, msg, msgType, logger);
);
}
}

public static void logMessage(final Lists.Entry e,
final org.apache.log4j.Logger logger) {
logMessage(e.getContext(), e.getMessage(), e.getMsgType(), logger);
}

/**
* MessageRecorder that records all of the messages in lists allowing the
* calling code to access the list and take actions as needed.
*/
public static class Lists extends Recorder {

/**
* Entry is a Info, Warning or Error message. This is the object stored
* in the Lists MessageRecorder's info, warning and error message lists.
*/
public static class Entry {
private final String context;
private final String msg;
private final int msgType;
private final Object info;

private Entry(final String context,
final String msg,
final int msgType,
final Object info) {
this.context = context;
this.msg = msg;
this.msgType = msgType;
this.info = info;
}
public String getContext() {
return context;
}
public String getMessage() {
return msg;
}
public int getMsgType() {
return msgType;
}
public Object getInfo() {
return info;
}
}

private final List errorList;
private final List warnList;
private final List infoList;

public Lists() {
errorList = new ArrayList();
warnList = new ArrayList();
infoList = new ArrayList();
}
public void clear() {
super.clear();
errorList.clear();
warnList.clear();
infoList.clear();
}
public Iterator getErrorEntries() {
return errorList.iterator();
}
public Iterator getWarnEntries() {
return warnList.iterator();
}
public Iterator getInfoEntries() {
return infoList.iterator();
}
protected void recordMessage(final String msg,
final Object info,
final int msgType) {
String context = getContext();

Entry e = new Entry(context, msg, msgType, info);
switch (msgType) {
case INFO_MSG_TYPE :
infoList.add(e);
break;
case WARN_MSG_TYPE :
warnList.add(e);
break;
case ERROR_MSG_TYPE :
errorList.add(e);
break;
default :
e = new Entry(
context,
"Unknown message type enum \"" +
msgType +
"\" for message: " + msg,
WARN_MSG_TYPE,
info);
warnList.add(e);
}
}
public void logInfoMessage(final org.apache.log4j.Logger logger) {
if (hasInformation()) {
logMessage(getInfoEntries(), logger);
}
}
public void logWarningMessage(final org.apache.log4j.Logger logger) {
if (hasWarnings()) {
logMessage(getWarnEntries(), logger);
}
}
public void logErrorMessage(final org.apache.log4j.Logger logger) {
if (hasErrors()) {
logMessage(getErrorEntries(), logger);
}
}
protected void logMessage(final Iterator it,
final org.apache.log4j.Logger logger) {
while (it.hasNext()) {
Recorder.Lists.Entry e = (Recorder.Lists.Entry) it.next();
Recorder.logMessage(e, logger);
}
}
}
public static final int INFO_MSG_TYPE = 1;
public static final int WARN_MSG_TYPE = 2;
public static final int ERROR_MSG_TYPE = 3;
Expand All @@ -251,17 +69,17 @@ protected void logMessage(final Iterator it,
private String contextMsgCache;
private long startTime;

protected Recorder() {
protected AbstractRecorder() {
this(DEFAULT_MSG_LIMIT);
}
protected Recorder(final int errorMsgLimit) {
protected AbstractRecorder(final int errorMsgLimit) {
this.errorMsgLimit = errorMsgLimit;
this.contexts = new ArrayList();
this.startTime = System.currentTimeMillis();
}

/**
* Reset this MessageRecorder.
/**
* Resets this MessageRecorder.
*/
public void clear() {
errorMsgCount = 0;
Expand All @@ -271,6 +89,7 @@ public void clear() {
contexts.clear();
this.startTime = System.currentTimeMillis();
}

public long getStartTimeMillis() {
return this.startTime;
}
Expand Down Expand Up @@ -324,32 +143,32 @@ public void popContextName() {
contextMsgCache = null;
}

public void throwRTException() throws RTException {
public void throwRTException() throws RecorderException {
if (hasErrors()) {
final String errorMsg =
Util.getRes().getForceMessageRecorderError(
getContext(),
new Integer(errorMsgCount));
throw new MessageRecorder.RTException(errorMsg);
throw new RecorderException(errorMsg);
}
}

public void reportError(final Exception ex)
throws MessageRecorder.RTException {
public void reportError(final Exception ex)
throws RecorderException {
reportError(ex, null);
}

public void reportError(final Exception ex, final Object info)
throws MessageRecorder.RTException {
public void reportError(final Exception ex, final Object info)
throws RecorderException {
reportError(ex.toString(), info);
}

public void reportError(final String msg)
throws MessageRecorder.RTException {
throws RecorderException {
reportError(msg, null);
}
public void reportError(final String msg, final Object info)
throws MessageRecorder.RTException {
throws RecorderException {
errorMsgCount++;
recordMessage(msg, info, ERROR_MSG_TYPE);

Expand All @@ -358,7 +177,7 @@ public void reportError(final String msg, final Object info)
Util.getRes().getTooManyMessageRecorderErrors(
getContext(),
new Integer(errorMsgCount));
throw new MessageRecorder.RTException(errorMsg);
throw new RecorderException(errorMsg);
}
}

Expand All @@ -377,16 +196,20 @@ public void reportInfo(final String msg, final Object info) {
infoMsgCount++;
recordMessage(msg, info, INFO_MSG_TYPE);
}

/**

/**
* Handles a message.
* Classes implementing this abstract class must provide an implemention
* of this method which receives all warning/error messages.
*
* of this method; it receives all warning/error messages.
*
* @param msg the error or warning message.
* @param info the information Object which might be null.
* @param msgType one of the message type enum values
*/
protected abstract void recordMessage(final String msg,
final Object info,
final int msgType);
protected abstract void recordMessage(
String msg,
Object info,
int msgType);
}

// End AbstractRecorder.java

0 comments on commit 70b8874

Please sign in to comment.