mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
*) minor changes
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7563 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
0da3b6489e
commit
b649ce2dd7
|
@ -5,9 +5,11 @@
|
||||||
//first published on http://www.anomic.de
|
//first published on http://www.anomic.de
|
||||||
//Frankfurt, Germany, 2004
|
//Frankfurt, Germany, 2004
|
||||||
//
|
//
|
||||||
//This file ist contributed by Martin Thelian
|
//This file is contributed by Martin Thelian
|
||||||
//last major change: $LastChangedDate: 2008-08-02 14:12:04 +0200 (Sa, 02 Aug 2008) $ by $LastChangedBy: low012 $
|
//
|
||||||
//Revision: $LastChangedRevision: 6542 $
|
// $LastChangedDate$
|
||||||
|
// $LastChangedRevision$
|
||||||
|
// $LastChangedBy$
|
||||||
//
|
//
|
||||||
//This program is free software; you can redistribute it and/or modify
|
//This program is free software; you can redistribute it and/or modify
|
||||||
//it under the terms of the GNU General Public License as published by
|
//it under the terms of the GNU General Public License as published by
|
||||||
|
@ -53,7 +55,7 @@ public final class ConsoleOutErrHandler extends Handler {
|
||||||
/**
|
/**
|
||||||
* Get any configuration properties set
|
* Get any configuration properties set
|
||||||
*/
|
*/
|
||||||
private final void configure() {
|
private void configure() {
|
||||||
final LogManager manager = LogManager.getLogManager();
|
final LogManager manager = LogManager.getLogManager();
|
||||||
final String className = getClass().getName();
|
final String className = getClass().getName();
|
||||||
|
|
||||||
|
@ -80,11 +82,11 @@ public final class ConsoleOutErrHandler extends Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ignoreCtrlChrStr = manager.getProperty(className + ".ignoreCtrlChr");
|
final String ignoreCtrlChrStr = manager.getProperty(className + ".ignoreCtrlChr");
|
||||||
this.ignoreCtrlChr = (ignoreCtrlChrStr==null)?false:ignoreCtrlChrStr.equalsIgnoreCase("true");
|
this.ignoreCtrlChr = (ignoreCtrlChrStr==null) ? false : "true".equalsIgnoreCase(ignoreCtrlChrStr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Level parseLevel(final String levelName) {
|
private Level parseLevel(final String levelName) {
|
||||||
try {
|
try {
|
||||||
return (levelName == null) ? Level.INFO : Level.parse(levelName);
|
return (levelName == null) ? Level.INFO : Level.parse(levelName);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
@ -92,7 +94,7 @@ public final class ConsoleOutErrHandler extends Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Filter makeFilter(final String name) {
|
private Filter makeFilter(final String name) {
|
||||||
if (name == null) return null;
|
if (name == null) return null;
|
||||||
|
|
||||||
Filter f = null;
|
Filter f = null;
|
||||||
|
@ -107,7 +109,7 @@ public final class ConsoleOutErrHandler extends Handler {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Formatter makeFormatter(final String name) {
|
private Formatter makeFormatter(final String name) {
|
||||||
if (name == null) return null;
|
if (name == null) return null;
|
||||||
|
|
||||||
Formatter f = null;
|
Formatter f = null;
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
//first published on http://www.anomic.de
|
//first published on http://www.anomic.de
|
||||||
//Frankfurt, Germany, 2004
|
//Frankfurt, Germany, 2004
|
||||||
//
|
//
|
||||||
//This file ist contributed by Martin Thelian
|
//This file is contributed by Martin Thelian
|
||||||
//last major change: $LastChangedDate: 2008-08-02 14:12:04 +0200 (Sa, 02 Aug 2008) $ by $LastChangedBy: low012 $
|
//
|
||||||
//Revision: $LastChangedRevision: 6542 $
|
// $LastChangedDate$
|
||||||
|
// $LastChangedRevision$
|
||||||
|
// $LastChangedBy$
|
||||||
//
|
//
|
||||||
//This program is free software; you can redistribute it and/or modify
|
//This program is free software; you can redistribute it and/or modify
|
||||||
//it under the terms of the GNU General Public License as published by
|
//it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
//first published on http://www.anomic.de
|
//first published on http://www.anomic.de
|
||||||
//Frankfurt, Germany, 2004
|
//Frankfurt, Germany, 2004
|
||||||
//
|
//
|
||||||
//This file ist contributed by Martin Thelian
|
//This file is contributed by Martin Thelian
|
||||||
//last major change: $LastChangedDate: 2009-10-12 23:59:39 +0200 (Mo, 12. Okt 2009) $ by $LastChangedBy$
|
//
|
||||||
//Revision: $LastChangedRevision$
|
// $LastChangedDate$
|
||||||
|
// $LastChangedRevision$
|
||||||
|
// $LastChangedBy$
|
||||||
//
|
//
|
||||||
//This program is free software; you can redistribute it and/or modify
|
//This program is free software; you can redistribute it and/or modify
|
||||||
//it under the terms of the GNU General Public License as published by
|
//it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,6 +28,7 @@
|
||||||
package net.yacy.kelondro.logging;
|
package net.yacy.kelondro.logging;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.ErrorManager;
|
import java.util.logging.ErrorManager;
|
||||||
import java.util.logging.Filter;
|
import java.util.logging.Filter;
|
||||||
import java.util.logging.Formatter;
|
import java.util.logging.Formatter;
|
||||||
|
@ -52,7 +55,7 @@ public class GuiHandler extends Handler {
|
||||||
/**
|
/**
|
||||||
* Get any configuration properties set
|
* Get any configuration properties set
|
||||||
*/
|
*/
|
||||||
private final void configure() {
|
private void configure() {
|
||||||
final LogManager manager = LogManager.getLogManager();
|
final LogManager manager = LogManager.getLogManager();
|
||||||
final String className = getClass().getName();
|
final String className = getClass().getName();
|
||||||
|
|
||||||
|
@ -69,7 +72,7 @@ public class GuiHandler extends Handler {
|
||||||
this.size = parseSize(sizeString);
|
this.size = parseSize(sizeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int parseSize(final String sizeString) {
|
private int parseSize(final String sizeString) {
|
||||||
int newSize = DEFAULT_SIZE;
|
int newSize = DEFAULT_SIZE;
|
||||||
try {
|
try {
|
||||||
newSize = Integer.parseInt(sizeString);
|
newSize = Integer.parseInt(sizeString);
|
||||||
|
@ -79,7 +82,7 @@ public class GuiHandler extends Handler {
|
||||||
return newSize;
|
return newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Filter makeFilter(final String name) {
|
private Filter makeFilter(final String name) {
|
||||||
if (name == null) return null;
|
if (name == null) return null;
|
||||||
|
|
||||||
Filter f = null;
|
Filter f = null;
|
||||||
|
@ -92,7 +95,7 @@ public class GuiHandler extends Handler {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Formatter makeFormatter(final String name) {
|
private Formatter makeFormatter(final String name) {
|
||||||
if (name == null) return null;
|
if (name == null) return null;
|
||||||
|
|
||||||
Formatter f = null;
|
Formatter f = null;
|
||||||
|
@ -106,7 +109,7 @@ public class GuiHandler extends Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize. Size is a count of LogRecords.
|
// Initialize. Size is a count of LogRecords.
|
||||||
private final void init() {
|
private void init() {
|
||||||
this.buffer = new LogRecord[this.size];
|
this.buffer = new LogRecord[this.size];
|
||||||
this.start = 0;
|
this.start = 0;
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
|
@ -136,7 +139,7 @@ public class GuiHandler extends Handler {
|
||||||
|
|
||||||
|
|
||||||
public final synchronized LogRecord[] getLogArray(final Long sequenceNumberStart) {
|
public final synchronized LogRecord[] getLogArray(final Long sequenceNumberStart) {
|
||||||
final ArrayList<LogRecord> tempBuffer = new ArrayList<LogRecord>(this.count);
|
final List<LogRecord> tempBuffer = new ArrayList<LogRecord>(this.count);
|
||||||
|
|
||||||
for (int i = 0; i < this.count; i++) {
|
for (int i = 0; i < this.count; i++) {
|
||||||
final int ix = (this.start+i)%this.buffer.length;
|
final int ix = (this.start+i)%this.buffer.length;
|
||||||
|
@ -157,15 +160,15 @@ public class GuiHandler extends Handler {
|
||||||
final Formatter logFormatter = getFormatter();
|
final Formatter logFormatter = getFormatter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final int start = (reversed)?this.start+this.count-1:this.start;
|
final int theStart = (reversed)?this.start+this.count-1:this.start;
|
||||||
LogRecord record=null;
|
LogRecord record=null;
|
||||||
for (int i = 0; i < lineCount; i++) {
|
for (int i = 0; i < lineCount; i++) {
|
||||||
final int ix = (reversed) ?
|
final int ix = (reversed) ?
|
||||||
Math.abs((start-i)%this.buffer.length) :
|
Math.abs((theStart-i)%this.buffer.length) :
|
||||||
(start+i)%this.buffer.length;
|
(theStart+i)%this.buffer.length;
|
||||||
record = this.buffer[ix];
|
record = this.buffer[ix];
|
||||||
logMessages.append(logFormatter.format(record));
|
logMessages.append(logFormatter.format(record));
|
||||||
}
|
}
|
||||||
return logMessages.toString();
|
return logMessages.toString();
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
// We don't want to throw an exception here, but we
|
// We don't want to throw an exception here, but we
|
||||||
|
@ -179,19 +182,19 @@ public class GuiHandler extends Handler {
|
||||||
|
|
||||||
if ((lineCount > this.count)||(lineCount < 0)) lineCount = this.count;
|
if ((lineCount > this.count)||(lineCount < 0)) lineCount = this.count;
|
||||||
|
|
||||||
final ArrayList<String> logMessages = new ArrayList<String>(this.count);
|
final List<String> logMessages = new ArrayList<String>(this.count);
|
||||||
final Formatter logFormatter = getFormatter();
|
final Formatter logFormatter = getFormatter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final int theStart = (reversed)?this.start+this.count-1:this.start+this.count-lineCount;
|
final int theStart = (reversed) ? this.start+this.count-1 : this.start+this.count-lineCount;
|
||||||
LogRecord record=null;
|
LogRecord record=null;
|
||||||
for (int i = 0; i < lineCount; i++) {
|
for (int i = 0; i < lineCount; i++) {
|
||||||
final int ix = (reversed) ?
|
final int ix = (reversed) ?
|
||||||
Math.abs((theStart-i)%this.buffer.length) :
|
Math.abs((theStart-i)%this.buffer.length) :
|
||||||
(theStart + i) % this.buffer.length;
|
(theStart + i) % this.buffer.length;
|
||||||
record = this.buffer[ix];
|
record = this.buffer[ix];
|
||||||
logMessages.add(logFormatter.format(record));
|
logMessages.add(logFormatter.format(record));
|
||||||
}
|
}
|
||||||
return logMessages.toArray(new String[logMessages.size()]);
|
return logMessages.toArray(new String[logMessages.size()]);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
// We don't want to throw an exception here, but we
|
// We don't want to throw an exception here, but we
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
// (C) by Michael Peter Christen; mc@yacy.net
|
// (C) by Michael Peter Christen; mc@yacy.net
|
||||||
// first published on http://www.anomic.de
|
// first published on http://www.anomic.de
|
||||||
// Frankfurt, Germany, 2004
|
// Frankfurt, Germany, 2004
|
||||||
// last major change: $LastChangedDate: 2009-01-30 14:48:11 +0000 (Fr, 30 Jan 2009) $ by $LastChangedBy$
|
//
|
||||||
// Revision: $LastChangedRevision$
|
// $LastChangedDate$
|
||||||
|
// $LastChangedRevision$
|
||||||
|
// $LastChangedBy$
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -318,7 +320,7 @@ public final class Log {
|
||||||
|
|
||||||
protected final static class logRunner extends Thread {
|
protected final static class logRunner extends Thread {
|
||||||
public logRunner() {
|
public logRunner() {
|
||||||
super("Log Runner");
|
super("Log Runner");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -369,12 +371,12 @@ public final class Log {
|
||||||
if (!log.canRead()) log.mkdir();
|
if (!log.canRead()) log.mkdir();
|
||||||
|
|
||||||
// generating the root logger
|
// generating the root logger
|
||||||
Logger logger = Logger.getLogger("");
|
final Logger logger = Logger.getLogger("");
|
||||||
logger.setUseParentHandlers(false);
|
logger.setUseParentHandlers(false);
|
||||||
|
|
||||||
//for (Handler h: logger.getHandlers()) logger.removeHandler(h);
|
//for (Handler h: logger.getHandlers()) logger.removeHandler(h);
|
||||||
if (!dataPath.getAbsolutePath().equals(appPath.getAbsolutePath())) {
|
if (!dataPath.getAbsolutePath().equals(appPath.getAbsolutePath())) {
|
||||||
FileHandler handler = new FileHandler(logPattern, 1024*1024, 20, true);
|
final FileHandler handler = new FileHandler(logPattern, 1024*1024, 20, true);
|
||||||
logger.addHandler(handler);
|
logger.addHandler(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,9 +384,9 @@ public final class Log {
|
||||||
final Log exceptionLog = new Log("UNCAUGHT-EXCEPTION");
|
final Log exceptionLog = new Log("UNCAUGHT-EXCEPTION");
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){
|
||||||
public void uncaughtException(final Thread t, final Throwable e) {
|
public void uncaughtException(final Thread t, final Throwable e) {
|
||||||
String msg = String.format("Thread %s: %s",t.getName(), e.getMessage());
|
final String msg = String.format("Thread %s: %s",t.getName(), e.getMessage());
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
PrintStream ps = new PrintStream(baos);
|
final PrintStream ps = new PrintStream(baos);
|
||||||
e.printStackTrace(ps);
|
e.printStackTrace(ps);
|
||||||
ps.close();
|
ps.close();
|
||||||
exceptionLog.logSevere(msg + "\n" + baos.toString(), e);
|
exceptionLog.logSevere(msg + "\n" + baos.toString(), e);
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
//LogParserPLASMA.java
|
//LogParser.java
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
//part of YACY
|
//part of YACY
|
||||||
//(C) by Michael Peter Christen; mc@yacy.net
|
//(C) by Michael Peter Christen; mc@yacy.net
|
||||||
//first published on http://www.anomic.de
|
//first published on http://www.anomic.de
|
||||||
//Frankfurt, Germany, 2004
|
//Frankfurt, Germany, 2004
|
||||||
//
|
//
|
||||||
//This file ist contributed by Matthias Soehnholz
|
//This file is contributed by Matthias Soehnholz
|
||||||
//last major change: $LastChangedDate: 2008-11-17 16:23:17 +0000 (Mo, 17 Nov 2008) $ by $LastChangedBy: orbiter $
|
//
|
||||||
//Revision: $LastChangedRevision: 7461 $
|
// $LastChangedDate$
|
||||||
|
// $LastChangedRevision$
|
||||||
|
// $LastChangedBy$
|
||||||
//
|
//
|
||||||
//This program is free software; you can redistribute it and/or modify
|
//This program is free software; you can redistribute it and/or modify
|
||||||
//it under the terms of the GNU General Public License as published by
|
//it under the terms of the GNU General Public License as published by
|
||||||
|
@ -25,8 +27,10 @@
|
||||||
|
|
||||||
package net.yacy.kelondro.logging;
|
package net.yacy.kelondro.logging;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -209,10 +213,10 @@ public final class LogParser {
|
||||||
private long DHTSendTraffic=0;
|
private long DHTSendTraffic=0;
|
||||||
private int DHTSendURLs=0;
|
private int DHTSendURLs=0;
|
||||||
private int RWIRejectCount=0;
|
private int RWIRejectCount=0;
|
||||||
private final HashSet<String> RWIRejectPeerNames = new HashSet<String>();
|
private final Set<String> RWIRejectPeerNames = new HashSet<String>();
|
||||||
private final HashSet<String> RWIRejectPeerHashs = new HashSet<String>();
|
private final Set<String> RWIRejectPeerHashs = new HashSet<String>();
|
||||||
private final HashSet<String> DHTPeerNames = new HashSet<String>();
|
private final Set<String> DHTPeerNames = new HashSet<String>();
|
||||||
private final HashSet<String> DHTPeerHashs = new HashSet<String>();
|
private final Set<String> DHTPeerHashs = new HashSet<String>();
|
||||||
private int DHTSelectionTargetCount = 1;
|
private int DHTSelectionTargetCount = 1;
|
||||||
private int DHTSelectionWordsCount = 0;
|
private int DHTSelectionWordsCount = 0;
|
||||||
private int DHTSelectionWordsTimeCount = 0;
|
private int DHTSelectionWordsTimeCount = 0;
|
||||||
|
@ -243,11 +247,10 @@ public final class LogParser {
|
||||||
|
|
||||||
public final int parse(final String logLevel, final String logLine) {
|
public final int parse(final String logLevel, final String logLine) {
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
if (logLevel.equals("INFO")){
|
if ("INFO".equals(logLevel)){
|
||||||
m = i1.matcher (logLine);
|
m = i1.matcher (logLine);
|
||||||
|
|
||||||
if (m.find () && m.groupCount() >= 3) {
|
if (m.find () && m.groupCount() >= 3) {
|
||||||
//System.out.println(m.group(1) + " " + m.group(2) + " " + m.group(3));
|
|
||||||
urlSum += Integer.parseInt(m.group(1));
|
urlSum += Integer.parseInt(m.group(1));
|
||||||
urlTimeSum += Integer.parseInt(m.group(2));
|
urlTimeSum += Integer.parseInt(m.group(2));
|
||||||
blockedURLSum += Integer.parseInt(m.group(3));
|
blockedURLSum += Integer.parseInt(m.group(3));
|
||||||
|
@ -392,7 +395,7 @@ public final class LogParser {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (logLevel.equals("WARNING")){
|
} else if ("WARNING".equals(logLevel)){
|
||||||
m = w1.matcher (logLine);
|
m = w1.matcher (logLine);
|
||||||
|
|
||||||
if (m.find ()) {
|
if (m.find ()) {
|
||||||
|
@ -409,12 +412,12 @@ public final class LogParser {
|
||||||
totalParserRuns++;
|
totalParserRuns++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (logLevel.equals("SEVERE")){
|
} else if ("SEVERE".equals(logLevel)){
|
||||||
m = e1.matcher (logLine);
|
m = e1.matcher (logLine);
|
||||||
|
|
||||||
if (m.find () && m.groupCount() >= 1) {
|
if (m.find () && m.groupCount() >= 1) {
|
||||||
if (m.group(1).equals("leftchild")) leftChildTwiceCount++;
|
if ("leftchild".equals(m.group(1))) leftChildTwiceCount++;
|
||||||
else if (m.group(1).equals("rightchild")) rightChildTwiceCount++;
|
else if ("rightchild".equals(m.group(1))) rightChildTwiceCount++;
|
||||||
totalParserTime += (System.currentTimeMillis() - start);
|
totalParserTime += (System.currentTimeMillis() - start);
|
||||||
totalParserRuns++;
|
totalParserRuns++;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -433,8 +436,8 @@ public final class LogParser {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Hashtable<String, Object> getResults() {
|
public final Map<String, Object> getResults() {
|
||||||
final Hashtable<String, Object> results = new Hashtable<String, Object>();
|
final Map<String, Object> results = new HashMap<String, Object>();
|
||||||
results.put(PARSER_VERSION , Float.valueOf(parserVersion));
|
results.put(PARSER_VERSION , Float.valueOf(parserVersion));
|
||||||
results.put(URLS_RECEIVED , Integer.valueOf(urlSum));
|
results.put(URLS_RECEIVED , Integer.valueOf(urlSum));
|
||||||
results.put(URLS_REQUESTED , Integer.valueOf(urlReqSum));
|
results.put(URLS_REQUESTED , Integer.valueOf(urlReqSum));
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
//first published on http://www.anomic.de
|
//first published on http://www.anomic.de
|
||||||
//Frankfurt, Germany, 2004
|
//Frankfurt, Germany, 2004
|
||||||
//
|
//
|
||||||
//This file ist contributed by Matthias Soehnholz
|
//This file is contributed by Matthias Soehnholz
|
||||||
//last major change: $LastChangedDate: 2009-10-12 23:59:39 +0200 (Mo, 12. Okt 2009) $ by $LastChangedBy: low012 $
|
//
|
||||||
//Revision: $LastChangedRevision: 6542 $
|
// $LastChangedDate$
|
||||||
|
// $LastChangedRevision$
|
||||||
|
// $LastChangedBy$
|
||||||
//
|
//
|
||||||
//This program is free software; you can redistribute it and/or modify
|
//This program is free software; you can redistribute it and/or modify
|
||||||
//it under the terms of the GNU General Public License as published by
|
//it under the terms of the GNU General Public License as published by
|
||||||
|
@ -25,7 +27,7 @@
|
||||||
|
|
||||||
package net.yacy.kelondro.logging;
|
package net.yacy.kelondro.logging;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.LogManager;
|
import java.util.logging.LogManager;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
|
@ -33,17 +35,17 @@ import java.util.logging.LogRecord;
|
||||||
|
|
||||||
public final class LogalizerHandler extends Handler {
|
public final class LogalizerHandler extends Handler {
|
||||||
|
|
||||||
public static boolean enabled = false;
|
public static boolean enabled;
|
||||||
public static boolean debug = false;
|
public static boolean debug;
|
||||||
|
|
||||||
public LogalizerHandler() {
|
public LogalizerHandler() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
final LogManager manager = LogManager.getLogManager();
|
final LogManager manager = LogManager.getLogManager();
|
||||||
String className = getClass().getName();
|
final String className = getClass().getName();
|
||||||
|
|
||||||
if(manager.getProperty(className + ".enabled").equalsIgnoreCase("true")) enabled = true;
|
enabled = "true".equalsIgnoreCase(manager.getProperty(className + ".enabled"));
|
||||||
if(manager.getProperty(className + ".debug").equalsIgnoreCase("true")) debug = true;
|
debug = "true".equalsIgnoreCase(manager.getProperty(className + ".debug"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void publish(final LogRecord record) {
|
public final void publish(final LogRecord record) {
|
||||||
|
@ -51,14 +53,13 @@ public final class LogalizerHandler extends Handler {
|
||||||
final LogParser temp = new LogParser();
|
final LogParser temp = new LogParser();
|
||||||
if (temp != null) try {
|
if (temp != null) try {
|
||||||
final int returnV = temp.parse(record.getLevel().toString(), record.getMessage());
|
final int returnV = temp.parse(record.getLevel().toString(), record.getMessage());
|
||||||
//if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel() + " --- " + record.getMessage());
|
|
||||||
if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel());
|
if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel());
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Hashtable<String, Object> getParserResults(final LogParser parsername) {
|
public final Map<String, Object> getParserResults(final LogParser parsername) {
|
||||||
return (parsername == null) ? null : parsername.getResults();
|
return (parsername == null) ? null : parsername.getResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
//severMiniLogFormatter.java
|
//MiniLogFormatter.java
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
//part of YACY
|
//part of YACY
|
||||||
//(C) by Michael Peter Christen; mc@yacy.net
|
//(C) by Michael Peter Christen; mc@yacy.net
|
||||||
//first published on http://www.anomic.de
|
//first published on http://www.anomic.de
|
||||||
//Frankfurt, Germany, 2004
|
//Frankfurt, Germany, 2004
|
||||||
//
|
//
|
||||||
//This file ist contributed by Martin Thelian
|
//This file is contributed by Martin Thelian
|
||||||
//last major change: $LastChangedDate: 2008-12-04 13:54:16 +0100 (Thu, 04 Dec 2008) $ by $LastChangedBy: low012 $
|
//
|
||||||
//Revision: $LastChangedRevision: 6542 $
|
// $LastChangedDate$
|
||||||
|
// $LastChangedRevision$
|
||||||
|
// $LastChangedBy$
|
||||||
//
|
//
|
||||||
//This program is free software; you can redistribute it and/or modify
|
//This program is free software; you can redistribute it and/or modify
|
||||||
//it under the terms of the GNU General Public License as published by
|
//it under the terms of the GNU General Public License as published by
|
||||||
|
@ -30,22 +32,22 @@ import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
public final class MiniLogFormatter extends SimpleFormatter {
|
public final class MiniLogFormatter extends SimpleFormatter {
|
||||||
|
|
||||||
private final StringBuilder buffer = new StringBuilder();
|
private final StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
public MiniLogFormatter() {
|
public MiniLogFormatter() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final synchronized String format(final LogRecord record) {
|
public final synchronized String format(final LogRecord record) {
|
||||||
|
|
||||||
final StringBuilder stringBuilder = this.buffer;
|
final StringBuilder stringBuilder = this.buffer;
|
||||||
stringBuilder.setLength(0);
|
stringBuilder.setLength(0);
|
||||||
stringBuilder.append(formatMessage(record));
|
stringBuilder.append(formatMessage(record));
|
||||||
|
|
||||||
// adding the stack trace if available
|
// adding the stack trace if available
|
||||||
stringBuilder.append(System.getProperty("line.separator"));
|
stringBuilder.append(System.getProperty("line.separator"));
|
||||||
|
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//severSimpleLogFormatter.java
|
//SimpleLogFormatter.java
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
//part of YACY
|
//part of YACY
|
||||||
//(C) by Michael Peter Christen; mc@yacy.net
|
//(C) by Michael Peter Christen; mc@yacy.net
|
||||||
|
@ -6,8 +6,10 @@
|
||||||
//Frankfurt, Germany, 2004
|
//Frankfurt, Germany, 2004
|
||||||
//
|
//
|
||||||
//This file is contributed by Martin Thelian
|
//This file is contributed by Martin Thelian
|
||||||
//last major change: $LastChangedDate: 2008-08-02 14:12:04 +0200 (Sat, 02 Aug 2008) $ by $LastChangedBy: orbiter $
|
//
|
||||||
//Revision: $LastChangedRevision: 6572 $
|
// $LastChangedDate$
|
||||||
|
// $LastChangedRevision$
|
||||||
|
// $LastChangedBy$
|
||||||
//
|
//
|
||||||
//This program is free software; you can redistribute it and/or modify
|
//This program is free software; you can redistribute it and/or modify
|
||||||
//it under the terms of the GNU General Public License as published by
|
//it under the terms of the GNU General Public License as published by
|
||||||
|
@ -37,73 +39,72 @@ import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
public final class SimpleLogFormatter extends SimpleFormatter {
|
public final class SimpleLogFormatter extends SimpleFormatter {
|
||||||
|
|
||||||
|
private final Date date = new Date();
|
||||||
|
private final FieldPosition position = new FieldPosition(0);
|
||||||
|
|
||||||
private final Date date = new Date();
|
// e.g. 2005/05/25 11:22:53
|
||||||
private final FieldPosition position = new FieldPosition(0);
|
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
|
||||||
|
|
||||||
// e.g. 2005/05/25 11:22:53
|
private final StringBuffer buffer = new StringBuffer();
|
||||||
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
|
|
||||||
|
public SimpleLogFormatter() {
|
||||||
private final StringBuffer buffer = new StringBuffer();
|
super();
|
||||||
|
}
|
||||||
public SimpleLogFormatter() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final synchronized String format(final LogRecord record) {
|
public final synchronized String format(final LogRecord record) {
|
||||||
|
|
||||||
final StringBuffer stringBuffer = this.buffer;
|
final StringBuffer stringBuffer = this.buffer;
|
||||||
stringBuffer.setLength(0);
|
stringBuffer.setLength(0);
|
||||||
|
|
||||||
// adding the loglevel
|
// adding the loglevel
|
||||||
final int logLevel = record.getLevel().intValue();
|
final int logLevel = record.getLevel().intValue();
|
||||||
if (logLevel == Log.LOGLEVEL_SEVERE)
|
if (logLevel == Log.LOGLEVEL_SEVERE)
|
||||||
this.buffer.append(Log.LOGTOKEN_SEVERE);
|
this.buffer.append(Log.LOGTOKEN_SEVERE);
|
||||||
else if (logLevel == Log.LOGLEVEL_WARNING)
|
else if (logLevel == Log.LOGLEVEL_WARNING)
|
||||||
this.buffer.append(Log.LOGTOKEN_WARNING);
|
this.buffer.append(Log.LOGTOKEN_WARNING);
|
||||||
else if (logLevel == Log.LOGLEVEL_CONFIG)
|
else if (logLevel == Log.LOGLEVEL_CONFIG)
|
||||||
this.buffer.append(Log.LOGTOKEN_CONFIG);
|
this.buffer.append(Log.LOGTOKEN_CONFIG);
|
||||||
else if (logLevel == Log.LOGLEVEL_INFO)
|
else if (logLevel == Log.LOGLEVEL_INFO)
|
||||||
this.buffer.append(Log.LOGTOKEN_INFO);
|
this.buffer.append(Log.LOGTOKEN_INFO);
|
||||||
else if (logLevel == Log.LOGLEVEL_FINE)
|
else if (logLevel == Log.LOGLEVEL_FINE)
|
||||||
this.buffer.append(Log.LOGTOKEN_FINE);
|
this.buffer.append(Log.LOGTOKEN_FINE);
|
||||||
else if (logLevel == Log.LOGLEVEL_FINER)
|
else if (logLevel == Log.LOGLEVEL_FINER)
|
||||||
this.buffer.append(Log.LOGTOKEN_FINER);
|
this.buffer.append(Log.LOGTOKEN_FINER);
|
||||||
else if (logLevel == Log.LOGLEVEL_FINEST)
|
else if (logLevel == Log.LOGLEVEL_FINEST)
|
||||||
this.buffer.append(Log.LOGTOKEN_FINEST);
|
this.buffer.append(Log.LOGTOKEN_FINEST);
|
||||||
else
|
else
|
||||||
this.buffer.append(Log.LOGTOKEN_FINE);
|
this.buffer.append(Log.LOGTOKEN_FINE);
|
||||||
this.buffer.append(' ');
|
this.buffer.append(' ');
|
||||||
|
|
||||||
// adding the logging date
|
// adding the logging date
|
||||||
this.date.setTime(record.getMillis());
|
this.date.setTime(record.getMillis());
|
||||||
this.position.setBeginIndex(0);
|
this.position.setBeginIndex(0);
|
||||||
this.formatter.format(this.date, this.buffer, this.position);
|
this.formatter.format(this.date, this.buffer, this.position);
|
||||||
|
|
||||||
// adding the logger name
|
// adding the logger name
|
||||||
stringBuffer.append(' ');
|
stringBuffer.append(' ');
|
||||||
stringBuffer.append(record.getLoggerName());
|
stringBuffer.append(record.getLoggerName());
|
||||||
|
|
||||||
// adding the logging message
|
// adding the logging message
|
||||||
stringBuffer.append(' ');
|
stringBuffer.append(' ');
|
||||||
stringBuffer.append(formatMessage(record));
|
stringBuffer.append(formatMessage(record));
|
||||||
|
|
||||||
// adding the stack trace if available
|
// adding the stack trace if available
|
||||||
stringBuffer.append(System.getProperty("line.separator"));
|
stringBuffer.append(System.getProperty("line.separator"));
|
||||||
if (record.getThrown() != null) {
|
if (record.getThrown() != null) {
|
||||||
StringWriter writer = null;
|
StringWriter writer = null;
|
||||||
try {
|
try {
|
||||||
writer = new StringWriter();
|
writer = new StringWriter();
|
||||||
final PrintWriter printer = new PrintWriter(writer);
|
final PrintWriter printer = new PrintWriter(writer);
|
||||||
record.getThrown().printStackTrace(printer);
|
record.getThrown().printStackTrace(printer);
|
||||||
stringBuffer.append(writer.toString());
|
stringBuffer.append(writer.toString());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
stringBuffer.append("Failed to get stack trace: ").append(e.getMessage());
|
stringBuffer.append("Failed to get stack trace: ").append(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (writer != null) try {writer.close();} catch (final Exception ex) {}
|
if (writer != null) try {writer.close();} catch (final Exception ex) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stringBuffer.toString();
|
return stringBuffer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// ThreadDumpGenerator
|
// ThreadDump.java
|
||||||
// (C) by Michael Peter Christen; mc@yacy.net
|
// (C) by Michael Peter Christen; mc@yacy.net
|
||||||
// first published on http://www.anomic.de
|
// first published on http://www.anomic.de
|
||||||
// Frankfurt, Germany, 2004-2010
|
// Frankfurt, Germany, 2004-2010
|
||||||
|
@ -48,20 +48,21 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
|
|
||||||
public class Thread {
|
public class Thread {
|
||||||
public String name;
|
public String name;
|
||||||
public Thread(String name) {
|
public Thread(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public boolean equals(Object a) {
|
public boolean equals(Object a) {
|
||||||
if (a == null) return false;
|
return (a != null && a instanceof Thread && this.name.equals(((Thread) a).name));
|
||||||
return this.name.equals(((Thread) a).name);
|
|
||||||
}
|
}
|
||||||
public boolean equals(Thread a) {
|
public boolean equals(Thread a) {
|
||||||
if (a == null) return false;
|
return (a != null && this.name.equals(a.name));
|
||||||
return this.name.equals(a.name);
|
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.name.hashCode();
|
return this.name.hashCode();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
@ -69,20 +70,21 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
|
|
||||||
public class Lock {
|
public class Lock {
|
||||||
public String id;
|
public String id;
|
||||||
public Lock(String name) {
|
public Lock(final String name) {
|
||||||
this.id = name;
|
this.id = name;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public boolean equals(Object a) {
|
public boolean equals(Object a) {
|
||||||
if (a == null) return false;
|
return (a != null && a instanceof Lock && this.id.equals(((Lock) a).id));
|
||||||
return this.id.equals(((Lock) a).id);
|
|
||||||
}
|
}
|
||||||
public boolean equals(Lock a) {
|
public boolean equals(Lock a) {
|
||||||
if (a == null) return false;
|
return (a != null && this.id.equals(a.id));
|
||||||
return this.id.equals(a.id);
|
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.id.hashCode();
|
return this.id.hashCode();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
@ -92,13 +94,13 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
return java.lang.Thread.getAllStackTraces();
|
return java.lang.Thread.getAllStackTraces();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThreadDump(File f) throws IOException {
|
public ThreadDump(final File f) throws IOException {
|
||||||
this(new FileInputStream(f));
|
this(new FileInputStream(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThreadDump(InputStream is) throws IOException {
|
public ThreadDump(final InputStream is) throws IOException {
|
||||||
super();
|
super();
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
final BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||||
String line;
|
String line;
|
||||||
String thread = null;
|
String thread = null;
|
||||||
int p;
|
int p;
|
||||||
|
@ -123,33 +125,43 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void appendStackTraces(final File rootPath, final StringBuilder buffer, final Map<java.lang.Thread, StackTraceElement[]> stackTraces, final boolean plain, final java.lang.Thread.State stateIn) {
|
public static void appendStackTraces(final File rootPath,
|
||||||
|
final StringBuilder buffer,
|
||||||
|
final Map<java.lang.Thread, StackTraceElement[]> stackTraces,
|
||||||
|
final boolean plain,
|
||||||
|
final java.lang.Thread.State stateIn)
|
||||||
|
{
|
||||||
bufferappend(buffer, plain, "THREADS WITH STATES: " + stateIn.toString());
|
bufferappend(buffer, plain, "THREADS WITH STATES: " + stateIn.toString());
|
||||||
bufferappend(buffer, plain, "");
|
bufferappend(buffer, plain, "");
|
||||||
// collect single dumps
|
// collect single dumps
|
||||||
HashMap<String, SortedSet<String>> dumps = dumpCollection(rootPath, stackTraces, plain, stateIn);
|
final Map<String, SortedSet<String>> dumps = dumpCollection(rootPath, stackTraces, plain, stateIn);
|
||||||
|
|
||||||
// write dumps
|
// write dumps
|
||||||
for (final Entry<String, SortedSet<String>> entry: dumps.entrySet()) {
|
for (final Entry<String, SortedSet<String>> entry: dumps.entrySet()) {
|
||||||
SortedSet<String> threads = entry.getValue();
|
SortedSet<String> threads = entry.getValue();
|
||||||
for (String t: threads) bufferappend(buffer, plain, t);
|
for (final String t: threads) bufferappend(buffer, plain, t);
|
||||||
bufferappend(buffer, plain, entry.getKey());
|
bufferappend(buffer, plain, entry.getKey());
|
||||||
bufferappend(buffer, plain, "");
|
bufferappend(buffer, plain, "");
|
||||||
}
|
}
|
||||||
bufferappend(buffer, plain, "");
|
bufferappend(buffer, plain, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void appendStackTraceStats(final File rootPath, final StringBuilder buffer, final ArrayList<Map<java.lang.Thread, StackTraceElement[]>> traces, final boolean plain, final java.lang.Thread.State stateIn) {
|
public static void appendStackTraceStats(final File rootPath,
|
||||||
|
final StringBuilder buffer,
|
||||||
|
final List<Map<java.lang.Thread, StackTraceElement[]>> traces,
|
||||||
|
final boolean plain,
|
||||||
|
final java.lang.Thread.State stateIn)
|
||||||
|
{
|
||||||
if (stateIn != null) {
|
if (stateIn != null) {
|
||||||
bufferappend(buffer, plain, "THREADS WITH STATES: " + stateIn.toString());
|
bufferappend(buffer, plain, "THREADS WITH STATES: " + stateIn.toString());
|
||||||
bufferappend(buffer, plain, "");
|
bufferappend(buffer, plain, "");
|
||||||
}
|
}
|
||||||
// collect single dumps
|
// collect single dumps
|
||||||
HashMap<String, Integer> dumps = dumpStatistic(rootPath, traces, plain, stateIn);
|
Map<String, Integer> dumps = dumpStatistic(rootPath, traces, plain, stateIn);
|
||||||
|
|
||||||
// write dumps
|
// write dumps
|
||||||
while (!dumps.isEmpty()) {
|
while (!dumps.isEmpty()) {
|
||||||
Entry<String, Integer> e = removeMax(dumps);
|
final Entry<String, Integer> e = removeMax(dumps);
|
||||||
bufferappend(buffer, plain, "Occurrences: " + e.getValue());
|
bufferappend(buffer, plain, "Occurrences: " + e.getValue());
|
||||||
bufferappend(buffer, plain, e.getKey());
|
bufferappend(buffer, plain, e.getKey());
|
||||||
//bufferappend(buffer, plain, "");
|
//bufferappend(buffer, plain, "");
|
||||||
|
@ -157,7 +169,7 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
bufferappend(buffer, plain, "");
|
bufferappend(buffer, plain, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entry<String, Integer> removeMax(HashMap<String, Integer> result) {
|
private static Entry<String, Integer> removeMax(final Map<String, Integer> result) {
|
||||||
Entry<String, Integer> max = null;
|
Entry<String, Integer> max = null;
|
||||||
for (final Entry<String, Integer> e: result.entrySet()) {
|
for (final Entry<String, Integer> e: result.entrySet()) {
|
||||||
if (max == null || e.getValue().intValue() > max.getValue().intValue()) {
|
if (max == null || e.getValue().intValue() > max.getValue().intValue()) {
|
||||||
|
@ -168,11 +180,15 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<String, Integer> dumpStatistic(final File rootPath, final ArrayList<Map<java.lang.Thread, StackTraceElement[]>> stackTraces, final boolean plain, final java.lang.Thread.State stateIn) {
|
private static Map<String, Integer> dumpStatistic(final File rootPath,
|
||||||
HashMap<String, Integer> result = new HashMap<String, Integer>();
|
final List<Map<java.lang.Thread,StackTraceElement[]>> stackTraces,
|
||||||
HashMap<String, SortedSet<String>> x;
|
final boolean plain,
|
||||||
|
final java.lang.Thread.State stateIn)
|
||||||
|
{
|
||||||
|
final Map<String, Integer> result = new HashMap<String, Integer>();
|
||||||
|
Map<String, SortedSet<String>> x;
|
||||||
int count;
|
int count;
|
||||||
for (Map<java.lang.Thread,StackTraceElement[]> trace: stackTraces) {
|
for (final Map<java.lang.Thread,StackTraceElement[]> trace: stackTraces) {
|
||||||
x = dumpCollection(rootPath, trace, plain, stateIn);
|
x = dumpCollection(rootPath, trace, plain, stateIn);
|
||||||
for (final Entry<String, SortedSet<String>> e: x.entrySet()) {
|
for (final Entry<String, SortedSet<String>> e: x.entrySet()) {
|
||||||
Integer c = result.get(e.getKey());
|
Integer c = result.get(e.getKey());
|
||||||
|
@ -187,12 +203,16 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<String, SortedSet<String>> dumpCollection(final File appPath, final Map<java.lang.Thread,StackTraceElement[]> stackTraces, final boolean plain, final java.lang.Thread.State stateIn) {
|
private static Map<String, SortedSet<String>> dumpCollection(final File appPath,
|
||||||
|
final Map<java.lang.Thread,StackTraceElement[]> stackTraces,
|
||||||
|
final boolean plain,
|
||||||
|
final java.lang.Thread.State stateIn)
|
||||||
|
{
|
||||||
final File classPath = new File(appPath, "source");
|
final File classPath = new File(appPath, "source");
|
||||||
|
|
||||||
java.lang.Thread thread;
|
java.lang.Thread thread;
|
||||||
// collect single dumps
|
// collect single dumps
|
||||||
HashMap<String, SortedSet<String>> dumps = new HashMap<String, SortedSet<String>>();
|
final Map<String, SortedSet<String>> dumps = new HashMap<String, SortedSet<String>>();
|
||||||
for (final Entry<java.lang.Thread, StackTraceElement[]> entry: stackTraces.entrySet()) {
|
for (final Entry<java.lang.Thread, StackTraceElement[]> entry: stackTraces.entrySet()) {
|
||||||
thread = entry.getKey();
|
thread = entry.getKey();
|
||||||
final StackTraceElement[] stackTraceElements = entry.getValue();
|
final StackTraceElement[] stackTraceElements = entry.getValue();
|
||||||
|
@ -233,7 +253,7 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String threaddump = sb.toString();
|
final String threaddump = sb.toString();
|
||||||
SortedSet<String> threads = dumps.get(threaddump);
|
SortedSet<String> threads = dumps.get(threaddump);
|
||||||
if (threads == null) threads = new TreeSet<String>();
|
if (threads == null) threads = new TreeSet<String>();
|
||||||
threads.add(threadtitle);
|
threads.add(threadtitle);
|
||||||
|
@ -263,11 +283,7 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
|
|
||||||
public static void bufferappend(final StringBuilder buffer, final boolean plain, final String a) {
|
public static void bufferappend(final StringBuilder buffer, final boolean plain, final String a) {
|
||||||
buffer.append(a);
|
buffer.append(a);
|
||||||
if (plain) {
|
buffer.append(plain ? "\n" : "<br />");
|
||||||
buffer.append("\n");
|
|
||||||
} else {
|
|
||||||
buffer.append("<br />");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,9 +292,9 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
*/
|
*/
|
||||||
public Map<Lock, Thread> locks() {
|
public Map<Lock, Thread> locks() {
|
||||||
int p;
|
int p;
|
||||||
Map<Lock, Thread> locks = new HashMap<Lock, Thread>();
|
final Map<Lock, Thread> locks = new HashMap<Lock, Thread>();
|
||||||
for (Map.Entry<Thread, List<String>> entry: this.entrySet()) {
|
for (final Map.Entry<Thread, List<String>> entry: this.entrySet()) {
|
||||||
for (String s: entry.getValue()) {
|
for (final String s: entry.getValue()) {
|
||||||
if ((p = s.indexOf("locked <")) > 0) {
|
if ((p = s.indexOf("locked <")) > 0) {
|
||||||
locks.put(new Lock(s.substring(p + 8, s.indexOf('>'))), entry.getKey());
|
locks.put(new Lock(s.substring(p + 8, s.indexOf('>'))), entry.getKey());
|
||||||
|
|
||||||
|
@ -293,11 +309,11 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
* @param threadName
|
* @param threadName
|
||||||
* @return the thread id if there is a lock or null if there is none
|
* @return the thread id if there is a lock or null if there is none
|
||||||
*/
|
*/
|
||||||
public Lock lockedBy(Thread threadName) {
|
public Lock lockedBy(final Thread threadName) {
|
||||||
int p;
|
int p;
|
||||||
List<String> list = this.get(threadName);
|
final List<String> list = this.get(threadName);
|
||||||
if (list == null) return null;
|
if (list == null) return null;
|
||||||
for (String s: list) {
|
for (final String s: list) {
|
||||||
if ((p = s.indexOf("<")) > 0 && s.indexOf("locked <") < 0) {
|
if ((p = s.indexOf("<")) > 0 && s.indexOf("locked <") < 0) {
|
||||||
return new Lock(s.substring(p + 1, s.indexOf('>')));
|
return new Lock(s.substring(p + 1, s.indexOf('>')));
|
||||||
}
|
}
|
||||||
|
@ -306,23 +322,23 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Thread, Integer> countLocks() {
|
public Map<Thread, Integer> countLocks() {
|
||||||
Map<Lock, Thread> locks = locks();
|
final Map<Lock, Thread> locks = locks();
|
||||||
Map<Thread, Integer> count = new HashMap<Thread, Integer>();
|
final Map<Thread, Integer> count = new HashMap<Thread, Integer>();
|
||||||
for (Map.Entry<Lock, Thread> entry: locks.entrySet()) {
|
for (final Map.Entry<Lock, Thread> entry: locks.entrySet()) {
|
||||||
// look where the lock has an effect
|
// look where the lock has an effect
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for (Thread thread: this.keySet()) if (entry.getKey().equals(lockedBy(thread))) c++;
|
for (final Thread thread: this.keySet()) if (entry.getKey().equals(lockedBy(thread))) c++;
|
||||||
if (c > 0) count.put(entry.getValue(), c);
|
if (c > 0) count.put(entry.getValue(), c);
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print() {
|
public void print() {
|
||||||
for (Thread thread: this.keySet()) print(thread);
|
for (final Thread thread: this.keySet()) print(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print(Thread thread) {
|
public void print(Thread thread) {
|
||||||
List<String> list = this.get(thread);
|
final List<String> list = this.get(thread);
|
||||||
if (list == null) return;
|
if (list == null) return;
|
||||||
System.out.println("Thread: " + thread);
|
System.out.println("Thread: " + thread);
|
||||||
for (String s: list) System.out.println(" " + s);
|
for (String s: list) System.out.println(" " + s);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user