Author: nextgens
Date: 2009-02-02 19:48:30 +0000 (Mon, 02 Feb 2009)
New Revision: 25475
Modified:
trunk/freenet/src/freenet/client/Metadata.java
trunk/freenet/src/freenet/support/io/BaseFileBucket.java
Log:
more Logger.shouldLog() optimizations
Modified: trunk/freenet/src/freenet/client/Metadata.java
===================================================================
--- trunk/freenet/src/freenet/client/Metadata.java 2009-02-02 19:35:23 UTC
(rev 25474)
+++ trunk/freenet/src/freenet/client/Metadata.java 2009-02-02 19:48:30 UTC
(rev 25475)
@@ -22,6 +22,7 @@
import freenet.client.ArchiveManager.ARCHIVE_TYPE;
import freenet.support.Fields;
import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
import freenet.support.api.Bucket;
import freenet.support.api.BucketFactory;
import freenet.support.compress.Compressor.COMPRESSOR_TYPE;
@@ -30,7 +31,18 @@
/** Metadata parser/writer class. */
public class Metadata implements Cloneable {
+ private static volatile boolean logMINOR;
+ static {
+ Logger.registerLogThresholdCallback(new LogThresholdCallback() {
+
+ @Override
+ public void shouldUpdate() {
+ logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ }
+ });
+ }
+
static final long FREENET_METADATA_MAGIC = 0xf053b2842d91482bL;
static final int MAX_SPLITFILE_PARAMS_LENGTH = 32768;
/** Soft limit, to avoid memory DoS */
@@ -179,7 +191,6 @@
documentType = dis.readByte();
if((documentType < 0) || (documentType > 5))
throw new MetadataParseException("Unsupported document
type: "+documentType);
- boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(logMINOR) Logger.minor(this, "Document type: "+documentType);
boolean compressed = false;
@@ -321,7 +332,7 @@
// Parse the sub-Manifest.
- Logger.minor(this, "Simple manifest,
"+manifestEntryCount+" entries");
+ if(logMINOR)Logger.minor(this, "Simple manifest,
"+manifestEntryCount+" entries");
for(int i=0;i<manifestEntryCount;i++) {
short nameLength = dis.readShort();
Modified: trunk/freenet/src/freenet/support/io/BaseFileBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/BaseFileBucket.java 2009-02-02
19:35:23 UTC (rev 25474)
+++ trunk/freenet/src/freenet/support/io/BaseFileBucket.java 2009-02-02
19:48:30 UTC (rev 25475)
@@ -14,11 +14,25 @@
import freenet.support.Fields;
import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
import freenet.support.SimpleFieldSet;
import freenet.support.api.Bucket;
public abstract class BaseFileBucket implements Bucket,
SerializableToFieldSetBucket {
+ private static volatile boolean logMINOR;
+ private static volatile boolean logDEBUG;
+ static {
+ Logger.registerLogThresholdCallback(new LogThresholdCallback() {
+
+ @Override
+ public void shouldUpdate() {
+ logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
+ }
+ });
+ }
+
// JVM caches File.size() and there is no way to flush the cache, so we
// need to track it ourselves
protected long length;
@@ -68,7 +82,7 @@
FileBucketOutputStream os =
new FileBucketOutputStream(tempfile,
streamNumber);
- if(Logger.shouldLog(Logger.DEBUG, this))
+ if(logDEBUG)
Logger.debug(this, "Creating "+os, new
Exception("debug"));
addStream(os);
@@ -131,7 +145,7 @@
File tempfile, long restartCount)
throws FileNotFoundException {
super(tempfile, false);
- if(Logger.shouldLog(Logger.MINOR, this))
+ if(logMINOR)
Logger.minor(this, "Writing to "+tempfile+" for
"+getFile());
this.tempfile = tempfile;
resetLength();
@@ -187,7 +201,6 @@
file = getFile();
}
removeStream(this);
- boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(logMINOR)
Logger.minor(this, "Closing
"+BaseFileBucket.this);
try {
@@ -257,7 +270,7 @@
FileBucketInputStream is =
new FileBucketInputStream(file);
addStream(is);
- if(Logger.shouldLog(Logger.DEBUG, this))
+ if(logDEBUG)
Logger.debug(this, "Creating "+is, new
Exception("debug"));
return is;
}
@@ -279,7 +292,7 @@
* called twice. But length must still be valid when calling it.
*/
protected synchronized void deleteFile() {
- if(Logger.shouldLog(Logger.MINOR, this))
+ if(logMINOR)
Logger.minor(this, "Deleting "+getFile()+" for "+this,
new Exception("debug"));
getFile().delete();
}
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs